[eric] electron: hard-reset IPC (kill backend, wipe data dir, relaunch) for factory reset

This commit is contained in:
ciregenz
2026-06-17 23:32:17 -07:00
parent 6d9e559892
commit 3f9fde17a8
2 changed files with 21 additions and 0 deletions
+19
View File
@@ -2561,6 +2561,25 @@ ipcMain.handle('get-install-state', () => {
}
});
// Factory reset ("Erase all content and settings"). Stop the backend FIRST so
// nothing rewrites the dir mid-wipe (on Windows a live process even locks the
// files), wipe everything under userData/data, then relaunch into a clean first
// run. install.json lives OUTSIDE /data so the install + affiliate identity
// survives, exactly like a real reinstall would. Best-effort throughout: a
// failed kill or wipe still relaunches rather than wedging the user.
ipcMain.handle('hard-reset', async () => {
try { killBackend(); } catch (e) { console.error('[hard-reset] killBackend failed', e); }
try {
const dataDir = path.join(app.getPath('userData'), 'data');
fs.rmSync(dataDir, { recursive: true, force: true });
console.log('[hard-reset] wiped data dir');
} catch (e) {
console.error('[hard-reset] wipe failed', e);
}
app.relaunch();
app.exit(0);
});
// ---------------------------------------------------------------------------
// CDP debugger bridge for the browser sub-agent
// ---------------------------------------------------------------------------
+2
View File
@@ -55,6 +55,8 @@ contextBridge.exposeInMainWorld('openswarm', {
// Renderer attaches the ref to Stripe checkout + sign-in flows so
// the cloud can credit the affiliate. Resolves to {} if no state yet.
getInstallState: () => ipcRenderer.invoke('get-install-state'),
// Factory reset: wipes the data dir and relaunches. Never resolves on success (the app exits first).
hardReset: () => ipcRenderer.invoke('hard-reset'),
connectSlack: () => ipcRenderer.invoke('connect-slack'),
sendCdpCommand: (wcId, method, params, sessionId) => ipcRenderer.invoke('send-cdp-command', wcId, method, params, sessionId),
cdpCacheSet: (wcId, indexMap) => ipcRenderer.invoke('cdp-cache-set', wcId, indexMap),