/** * Application-level local preferences. * * Renderer localStorage is origin-scoped, so dev server port changes can make * user preferences appear to disappear. Keep business-local preferences here * as the stable source shared by all renderer origins. */ export interface AppLocalPreferences { quickTasks?: unknown[]; channelAccountRemarks?: Record; desktopUserName?: string; workspaceDisplayName?: string; } // eslint-disable-next-line @typescript-eslint/no-explicit-any let localPreferencesStoreInstance: any = null; async function getLocalPreferencesStore() { if (!localPreferencesStoreInstance) { const Store = (await import('electron-store')).default; localPreferencesStoreInstance = new Store({ name: 'local-preferences', }); } return localPreferencesStoreInstance; } export async function getAllLocalPreferences(): Promise { const store = await getLocalPreferencesStore(); return { ...(store.store ?? {}) }; } export async function patchLocalPreferences(patch: AppLocalPreferences): Promise { const store = await getLocalPreferencesStore(); for (const [key, value] of Object.entries(patch) as Array<[keyof AppLocalPreferences, unknown]>) { if (value === undefined) continue; store.set(key, value); } return { ...(store.store ?? {}) }; }