feat: added utility function, sorting, and new shortcut

This commit is contained in:
kangfenmao 2025-01-20 10:29:44 +08:00
parent 46b314303c
commit c510f5dcce
5 changed files with 39 additions and 24 deletions

View File

@ -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)
}

View File

@ -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) {

View File

@ -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<Record<string, InputRef>>({})
const [editingKey, setEditingKey] = useState<string | null>(null)

View File

@ -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
}
}

View File

@ -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'],