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
This commit is contained in:
digua committed 2026-05-19 22:42:00 +08:00
1 parent 05394c2155
commit 08260499f8
37 files changed
+857 -196

No files matched your search

+30
View File
@@ -0,0 +1,30 @@
/**
* 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)
},
}