import { readFileSync, writeFileSync } from "node:fs"; import { APP_SETTINGS_FILE } from "./ipc/constants"; import { parseJsonWithByteOrderMark } from "./ipc/utils"; export function readAppSettingsStore(): Record { try { const content = readFileSync(APP_SETTINGS_FILE, "utf-8"); const parsed = parseJsonWithByteOrderMark(content); if (!parsed || typeof parsed !== "object" || Array.isArray(parsed)) { return {}; } return parsed as Record; } catch { return {}; } } export function writeAppSettingsStore(store: Record) { writeFileSync(APP_SETTINGS_FILE, JSON.stringify(store, null, 2), "utf-8"); } export function hasAppSetting(store: Record, key: string): boolean { return Reflect.getOwnPropertyDescriptor(store, key) !== undefined; } export function readAppSetting(key: string): unknown { const store = readAppSettingsStore(); return hasAppSetting(store, key) ? store[key] : null; } export function writeAppSetting(key: string, value: unknown) { const store = readAppSettingsStore(); store[key] = value; writeAppSettingsStore(store); }