21 lines
833 B
JavaScript
21 lines
833 B
JavaScript
// Small Pithos preferences kept beside s3d.yml (pithos-prefs.json):
|
|
// whether s3d should be running, so a restart of the host (Theseus quitting,
|
|
// an extension update) brings it back instead of leaving it stopped.
|
|
|
|
import fs from 'node:fs';
|
|
import path from 'node:path';
|
|
|
|
const FILE = 'pithos-prefs.json';
|
|
|
|
export function readPrefs(configFile) {
|
|
try { return JSON.parse(fs.readFileSync(path.join(path.dirname(configFile), FILE), 'utf8')) || {}; } catch { return {}; }
|
|
}
|
|
|
|
export function writePrefs(configFile, patch) {
|
|
const next = { ...readPrefs(configFile), ...patch };
|
|
try {
|
|
fs.mkdirSync(path.dirname(configFile), { recursive: true });
|
|
fs.writeFileSync(path.join(path.dirname(configFile), FILE), JSON.stringify(next, null, 2));
|
|
} catch { /* a read-only config folder just means no memory */ }
|
|
return next;
|
|
}
|