forked from trent_larson/crowd-funder-for-time-pwa
- Implement XDG Base Directory Specification for data storage - Use $XDG_DATA_HOME (defaults to ~/.local/share) for data files - Add proper directory permissions (700) for security - Fallback to ~/.timesafari if XDG paths fail - Add graceful degradation for SQLite failures - Allow app to boot even if SQLite initialization fails - Track and expose initialization errors via IPC - Add availability checks to all SQLite operations - Improve error reporting and logging - Security improvements - Set secure permissions (700) on data directories - Verify directory permissions on existing paths - Add proper error handling for permission issues TODO: - Fix database creation - Add retry logic for initialization - Add reinitialization capability - Add more detailed error reporting - Consider fallback storage options
76 lines
1.8 KiB
JavaScript
76 lines
1.8 KiB
JavaScript
/* eslint-disable no-undef */
|
|
/* eslint-disable @typescript-eslint/no-var-requires */
|
|
const cp = require('child_process');
|
|
const chokidar = require('chokidar');
|
|
const electron = require('electron');
|
|
|
|
let child = null;
|
|
const npmCmd = process.platform === 'win32' ? 'npm.cmd' : 'npm';
|
|
const reloadWatcher = {
|
|
debouncer: null,
|
|
ready: false,
|
|
watcher: null,
|
|
restarting: false,
|
|
};
|
|
|
|
///*
|
|
function runBuild() {
|
|
return new Promise((resolve, _reject) => {
|
|
let tempChild = cp.spawn(npmCmd, ['run', 'build']);
|
|
tempChild.once('exit', () => {
|
|
resolve();
|
|
});
|
|
tempChild.stdout.pipe(process.stdout);
|
|
});
|
|
}
|
|
//*/
|
|
|
|
async function spawnElectron() {
|
|
if (child !== null) {
|
|
child.stdin.pause();
|
|
child.kill();
|
|
child = null;
|
|
await runBuild();
|
|
}
|
|
child = cp.spawn(electron, ['--inspect=5858', './']);
|
|
child.on('exit', () => {
|
|
if (!reloadWatcher.restarting) {
|
|
process.exit(0);
|
|
}
|
|
});
|
|
child.stdout.pipe(process.stdout);
|
|
}
|
|
|
|
function setupReloadWatcher() {
|
|
reloadWatcher.watcher = chokidar
|
|
.watch('./src/**/*', {
|
|
ignored: /[/\\]\./,
|
|
persistent: true,
|
|
})
|
|
.on('ready', () => {
|
|
reloadWatcher.ready = true;
|
|
})
|
|
.on('all', (_event, _path) => {
|
|
if (reloadWatcher.ready) {
|
|
clearTimeout(reloadWatcher.debouncer);
|
|
reloadWatcher.debouncer = setTimeout(async () => {
|
|
console.log('Restarting');
|
|
reloadWatcher.restarting = true;
|
|
await spawnElectron();
|
|
reloadWatcher.restarting = false;
|
|
reloadWatcher.ready = false;
|
|
clearTimeout(reloadWatcher.debouncer);
|
|
reloadWatcher.debouncer = null;
|
|
reloadWatcher.watcher = null;
|
|
setupReloadWatcher();
|
|
}, 500);
|
|
}
|
|
});
|
|
}
|
|
|
|
(async () => {
|
|
await runBuild();
|
|
await spawnElectron();
|
|
setupReloadWatcher();
|
|
})();
|