diff --git a/electron/main.js b/electron/main.js index e5d2ff6c..56d45f63 100644 --- a/electron/main.js +++ b/electron/main.js @@ -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 // --------------------------------------------------------------------------- diff --git a/electron/preload.js b/electron/preload.js index e7e70ab2..ac4a3e13 100644 --- a/electron/preload.js +++ b/electron/preload.js @@ -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),