mirror of
https://github.com/webadderallorg/Recordly.git
synced 2026-09-29 09:15:45 +00:00
fix: persist presets and theme preferences
This commit is contained in:
@@ -0,0 +1,42 @@
|
||||
type ElectronSettingsApi = Pick<Window["electronAPI"], "getAppSetting" | "setAppSetting">;
|
||||
|
||||
function getElectronSettingsApi(): ElectronSettingsApi | null {
|
||||
const api = (globalThis as typeof globalThis & { electronAPI?: ElectronSettingsApi })
|
||||
.electronAPI;
|
||||
if (
|
||||
!api ||
|
||||
typeof api.getAppSetting !== "function" ||
|
||||
typeof api.setAppSetting !== "function"
|
||||
) {
|
||||
return null;
|
||||
}
|
||||
|
||||
return api;
|
||||
}
|
||||
|
||||
export function loadAppSetting<T>(key: string): T | null {
|
||||
const api = getElectronSettingsApi();
|
||||
if (!api) {
|
||||
return null;
|
||||
}
|
||||
|
||||
try {
|
||||
const value = api.getAppSetting(key);
|
||||
return value === undefined ? null : (value as T | null);
|
||||
} catch {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
export function saveAppSetting(key: string, value: unknown): boolean {
|
||||
const api = getElectronSettingsApi();
|
||||
if (!api) {
|
||||
return false;
|
||||
}
|
||||
|
||||
try {
|
||||
return api.setAppSetting(key, value);
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user