Spaces:
Runtime error
Runtime error
File size: 711 Bytes
077865a | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 | import fs from 'node:fs';
import path from 'node:path';
import { app } from 'electron';
export interface DesktopConfig {
port?: number;
theme?: 'dark' | 'light';
}
function configPath(): string {
return path.join(app.getPath('userData'), 'config.json');
}
export function loadConfig(): DesktopConfig {
try {
return JSON.parse(fs.readFileSync(configPath(), 'utf8')) as DesktopConfig;
} catch {
return {};
}
}
export function saveConfig(cfg: DesktopConfig): void {
try {
fs.mkdirSync(app.getPath('userData'), { recursive: true });
fs.writeFileSync(configPath(), JSON.stringify(cfg, null, 2));
} catch (err) {
console.warn('[desktop] could not persist config:', err);
}
}
|