Files
ChatLab/apps/desktop/preload/apis/preferences.ts
T
digua 08260499f8 feat: migrate localStorage to backend storage with declarative persist plugin
- Add backendPersist Pinia plugin for declarative preferences.json persistence
- Move Preferences types to @openchatlab/shared-types (single source of truth)
- Migrate sessionGapThreshold from localStorage to config.toml [ui]
- Migrate chatlab_filter_history from localStorage to preferences.json
- Fix stale localStorage locale read in i18n/index.ts
- Simplify usePreferencesSync (172 → 75 lines) by delegating to plugin

Adding a new backend-synced preference now only requires 3 changes:
1. shared-types interface  2. node-runtime DEFAULTS  3. store backendPersist.pick
2026-05-19 22:42:00 +08:00

31 lines
916 B
TypeScript

/**
* Preferences Preload API
*/
import { ipcRenderer } from 'electron'
export const preferencesApi = {
get: (): Promise<Record<string, unknown>> => {
return ipcRenderer.invoke('preferences:get')
},
save: (partial: Record<string, unknown>): Promise<{ success: boolean; error?: string }> => {
return ipcRenderer.invoke('preferences:save', partial)
},
getUiConfig: (): Promise<Record<string, unknown>> => {
return ipcRenderer.invoke('preferences:getUiConfig')
},
saveUiConfig: (partial: Record<string, unknown>): Promise<{ success: boolean; error?: string }> => {
return ipcRenderer.invoke('preferences:saveUiConfig', partial)
},
getLocale: (): Promise<string> => {
return ipcRenderer.invoke('preferences:getLocale')
},
saveLocale: (lang: string): Promise<{ success: boolean; error?: string }> => {
return ipcRenderer.invoke('preferences:saveLocale', lang)
},
}