feat(electron): main process, vault, search index, links, import, capture
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>
This commit is contained in:
1 parent
0b5f8bfa8b
commit
313c41f867
16 files changed
+2706
-15
No files matched your search
@@ -0,0 +1,39 @@
|
||||
'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 };
|
||||
Reference in new issue
Block a user