diff --git a/src/main/utils/index.ts b/src/main/utils/index.ts index 3fc44e2d..972364f5 100644 --- a/src/main/utils/index.ts +++ b/src/main/utils/index.ts @@ -34,3 +34,11 @@ export function debounce(func: (...args: any[]) => void, wait: number, immediate } } } + +export function dumpPersistState() { + const persistState = JSON.parse(localStorage.getItem('persist:cherry-studio') || '{}') + for (const key in persistState) { + persistState[key] = JSON.parse(persistState[key]) + } + return JSON.stringify(persistState) +} diff --git a/src/renderer/src/hooks/useShortcuts.ts b/src/renderer/src/hooks/useShortcuts.ts index d4c1b206..691bd42f 100644 --- a/src/renderer/src/hooks/useShortcuts.ts +++ b/src/renderer/src/hooks/useShortcuts.ts @@ -1,5 +1,6 @@ import { isMac, isWindows } from '@renderer/config/constant' import { useAppSelector } from '@renderer/store' +import { orderBy } from 'lodash' import { useCallback } from 'react' import { useHotkeys } from 'react-hotkeys-hook' @@ -58,7 +59,7 @@ export const useShortcut = ( export function useShortcuts() { const shortcuts = useAppSelector((state) => state.shortcuts.shortcuts) - return { shortcuts } + return { shortcuts: orderBy(shortcuts, 'system', 'desc') } } export function useShortcutDisplay(key: string) { diff --git a/src/renderer/src/pages/settings/ShortcutSettings.tsx b/src/renderer/src/pages/settings/ShortcutSettings.tsx index 077e0133..c00d6fd3 100644 --- a/src/renderer/src/pages/settings/ShortcutSettings.tsx +++ b/src/renderer/src/pages/settings/ShortcutSettings.tsx @@ -2,7 +2,8 @@ import { ClearOutlined, UndoOutlined } from '@ant-design/icons' import { HStack } from '@renderer/components/Layout' import { isMac, isWindows } from '@renderer/config/constant' import { useTheme } from '@renderer/context/ThemeProvider' -import { useAppDispatch, useAppSelector } from '@renderer/store' +import { useShortcuts } from '@renderer/hooks/useShortcuts' +import { useAppDispatch } from '@renderer/store' import { initialState, resetShortcuts, toggleShortcut, updateShortcut } from '@renderer/store/shortcuts' import { Shortcut } from '@renderer/types' import { Button, Input, InputRef, Switch, Table as AntTable, Tooltip } from 'antd' @@ -17,7 +18,7 @@ const ShortcutSettings: FC = () => { const { t } = useTranslation() const { theme } = useTheme() const dispatch = useAppDispatch() - const shortcuts = useAppSelector((state) => state.shortcuts.shortcuts) + const { shortcuts } = useShortcuts() const inputRefs = useRef>({}) const [editingKey, setEditingKey] = useState(null) diff --git a/src/renderer/src/store/migrate.ts b/src/renderer/src/store/migrate.ts index d7db10c2..88625f6b 100644 --- a/src/renderer/src/store/migrate.ts +++ b/src/renderer/src/store/migrate.ts @@ -12,6 +12,23 @@ import { createMigrate } from 'redux-persist' import { RootState } from '.' import { DEFAULT_SIDEBAR_ICONS } from './settings' +function removeMiniAppIconsFromState(state: RootState) { + if (state.minapps) { + state.minapps.enabled = state.minapps.enabled.map((app) => { + const _app = DEFAULT_MIN_APPS.find((m) => m.id === app.id) + return _app || app + }) + state.minapps.disabled = state.minapps.disabled.map((app) => { + const _app = DEFAULT_MIN_APPS.find((m) => m.id === app.id) + return _app || app + }) + state.minapps.pinned = state.minapps.pinned.map((app) => { + const _app = DEFAULT_MIN_APPS.find((m) => m.id === app.id) + return _app || app + }) + } +} + const migrateConfig = { '2': (state: RootState) => { return { @@ -825,20 +842,7 @@ const migrateConfig = { }) } - if (state.minapps) { - state.minapps.enabled = state.minapps.enabled.map((app) => { - const _app = DEFAULT_MIN_APPS.find((m) => m.id === app.id) - return _app || app - }) - state.minapps.disabled = state.minapps.disabled.map((app) => { - const _app = DEFAULT_MIN_APPS.find((m) => m.id === app.id) - return _app || app - }) - state.minapps.pinned = state.minapps.pinned.map((app) => { - const _app = DEFAULT_MIN_APPS.find((m) => m.id === app.id) - return _app || app - }) - } + removeMiniAppIconsFromState(state) state.llm.providers.forEach((provider) => { if (provider.id === 'qwenlm') { @@ -879,6 +883,7 @@ const migrateConfig = { state.minapps.enabled.push(flowith) } } + removeMiniAppIconsFromState(state) return state } } diff --git a/src/renderer/src/store/shortcuts.ts b/src/renderer/src/store/shortcuts.ts index 7eb2e4c5..ab03ef97 100644 --- a/src/renderer/src/store/shortcuts.ts +++ b/src/renderer/src/store/shortcuts.ts @@ -17,6 +17,13 @@ const initialState: ShortcutsState = { enabled: true, system: true }, + { + key: 'mini_window', + shortcut: [isMac ? 'Command' : 'Ctrl', 'E'], + editable: true, + enabled: false, + system: true + }, { key: 'new_topic', shortcut: [isMac ? 'Command' : 'Ctrl', 'N'], @@ -52,13 +59,6 @@ const initialState: ShortcutsState = { enabled: true, system: false }, - { - key: 'mini_window', - shortcut: [isMac ? 'Command' : 'Ctrl', 'E'], - editable: true, - enabled: false, - system: true - }, { key: 'clear_topic', shortcut: [isMac ? 'Command' : 'Ctrl', 'L'],