Vault on plain .md files with FTS5 index, link rewriting, canvas files, history/trash/backup, link previews, image fetch, tasks and unlinked mentions, Notion/Obsidian importer, quick-capture window and shortcut. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
40 lines
945 B
JavaScript
40 lines
945 B
JavaScript
'use strict';
|
|
// App settings (not notes): last vault, theme, window size, folded pages.
|
|
const fs = require('node:fs');
|
|
const path = require('node:path');
|
|
|
|
let file = null;
|
|
let cache = null;
|
|
|
|
function location() {
|
|
if (!file) file = path.join(require('electron').app.getPath('userData'), 'settings.json');
|
|
return file;
|
|
}
|
|
|
|
function get() {
|
|
if (cache) return cache;
|
|
try { cache = JSON.parse(fs.readFileSync(location(), 'utf8')); } catch { cache = {}; }
|
|
return cache;
|
|
}
|
|
|
|
let timer = null;
|
|
function set(patch) {
|
|
cache = { ...get(), ...patch };
|
|
clearTimeout(timer);
|
|
timer = setTimeout(flush, 200);
|
|
return cache;
|
|
}
|
|
|
|
function flush() {
|
|
clearTimeout(timer);
|
|
if (!cache) return;
|
|
try {
|
|
fs.mkdirSync(path.dirname(location()), { recursive: true });
|
|
fs.writeFileSync(location(), JSON.stringify(cache, null, 2));
|
|
} catch (err) {
|
|
console.error('Could not write settings', err);
|
|
}
|
|
}
|
|
|
|
module.exports = { get, set, flush };
|