feat: added utility function, sorting, and new shortcut
This commit is contained in:
parent
46b314303c
commit
c510f5dcce
@ -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)
|
||||
}
|
||||
|
||||
@ -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) {
|
||||
|
||||
@ -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)
|
||||
|
||||
|
||||
@ -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
|
||||
}
|
||||
}
|
||||
|
||||
@ -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'],
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user