mirror of
https://github.com/openswarm-ai/openswarm.git
synced 2026-09-11 04:07:44 +02:00
[eric] browser: Settings "Clear browsing data" wipes the browser partition only
This commit is contained in:
@@ -2448,6 +2448,14 @@ ipcMain.handle('get-webview-preload-path', () => {
|
||||
return `file://${path.join(__dirname, 'webview-preload.js')}`;
|
||||
});
|
||||
|
||||
// Wipe ONLY the browser-card partition (cookies/cache/localStorage/IndexedDB), never the app's defaultSession. Surfaced as Settings -> Data & Privacy -> Clear browsing data.
|
||||
ipcMain.handle('browser:clear-data', async () => {
|
||||
const ses = session.fromPartition(BROWSER_PARTITION);
|
||||
await ses.clearStorageData();
|
||||
await ses.clearCache();
|
||||
return { ok: true };
|
||||
});
|
||||
|
||||
ipcMain.handle('get-update-status', () => cachedUpdateStatus);
|
||||
|
||||
// One-shot recovery info: if the crash-watchdog relaunched us, returns the
|
||||
|
||||
@@ -57,6 +57,8 @@ contextBridge.exposeInMainWorld('openswarm', {
|
||||
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'),
|
||||
// Clears cookies/cache/localStorage for the browser-card partition only (never the app's defaultSession). Logs you out of sites opened in browser cards.
|
||||
clearBrowserData: () => ipcRenderer.invoke('browser:clear-data'),
|
||||
connectSlack: () => ipcRenderer.invoke('connect-slack'),
|
||||
sendCdpCommand: (wcId, method, params, sessionId) => ipcRenderer.invoke('send-cdp-command', wcId, method, params, sessionId),
|
||||
cdpDetachClean: (wcId) => ipcRenderer.invoke('cdp-detach-clean', wcId),
|
||||
|
||||
@@ -20,11 +20,15 @@ const DataPrivacySection: React.FC<{ styles: SettingsStyles }> = ({ styles }) =>
|
||||
const [busy, setBusy] = useState(false);
|
||||
const [eraseText, setEraseText] = useState('');
|
||||
const [err, setErr] = useState<string | null>(null);
|
||||
const [clearOpen, setClearOpen] = useState(false);
|
||||
const [clearedOk, setClearedOk] = useState(false);
|
||||
|
||||
const closeAll = () => {
|
||||
if (busy) return;
|
||||
setResetOpen(false);
|
||||
setEraseOpen(false);
|
||||
setClearOpen(false);
|
||||
setClearedOk(false);
|
||||
setEraseText('');
|
||||
setErr(null);
|
||||
};
|
||||
@@ -59,6 +63,24 @@ const DataPrivacySection: React.FC<{ styles: SettingsStyles }> = ({ styles }) =>
|
||||
}
|
||||
};
|
||||
|
||||
const doClearBrowser = async () => {
|
||||
const api = window.openswarm;
|
||||
if (!api?.clearBrowserData) {
|
||||
setErr('This only works in the desktop app.');
|
||||
return;
|
||||
}
|
||||
setBusy(true);
|
||||
setErr(null);
|
||||
try {
|
||||
await api.clearBrowserData();
|
||||
setBusy(false);
|
||||
setClearedOk(true);
|
||||
} catch {
|
||||
setBusy(false);
|
||||
setErr("Couldn't clear browsing data just now. Try again in a moment.");
|
||||
}
|
||||
};
|
||||
|
||||
const dialogPaperSx = {
|
||||
bgcolor: c.bg.surface,
|
||||
border: `1px solid ${c.border.subtle}`,
|
||||
@@ -100,6 +122,14 @@ const DataPrivacySection: React.FC<{ styles: SettingsStyles }> = ({ styles }) =>
|
||||
<Button variant="outlined" size="small" onClick={() => { setErr(null); setResetOpen(true); }} sx={rowBtnSx}>Reset</Button>
|
||||
</Box>
|
||||
|
||||
<Box sx={{ ...rowSx, borderBottom: `1px solid ${c.border.subtle}` }}>
|
||||
<Box>
|
||||
<Typography sx={labelSx}>Clear browsing data</Typography>
|
||||
<Typography sx={descSx}>Signs you out of sites opened in browser cards and clears their cookies, cache, and local storage. Your chats, apps, and settings stay.</Typography>
|
||||
</Box>
|
||||
<Button variant="outlined" size="small" onClick={() => { setErr(null); setClearedOk(false); setClearOpen(true); }} sx={rowBtnSx}>Clear</Button>
|
||||
</Box>
|
||||
|
||||
<Box sx={rowSx}>
|
||||
<Box>
|
||||
<Typography sx={{ ...labelSx, color: c.status.error }}>Erase all content and settings</Typography>
|
||||
@@ -120,6 +150,24 @@ const DataPrivacySection: React.FC<{ styles: SettingsStyles }> = ({ styles }) =>
|
||||
</Box>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={clearOpen} onClose={closeAll} PaperProps={{ sx: dialogPaperSx }}>
|
||||
<Box sx={{ p: 2.5 }}>
|
||||
<Typography sx={titleSx}>{clearedOk ? 'Browsing data cleared' : 'Clear browsing data?'}</Typography>
|
||||
<Typography sx={bodySx}>{clearedOk ? 'Cookies, cache, and local storage for browser cards are gone. Reload a browser card to see it signed out.' : 'This signs you out of sites in browser cards and clears their cookies, cache, and local storage. Your chats, apps, and settings stay.'}</Typography>
|
||||
{err && <Typography sx={errSx}>{err}</Typography>}
|
||||
<Box sx={actionRowSx}>
|
||||
{clearedOk ? (
|
||||
<Button onClick={closeAll} sx={{ color: c.accent.primary, textTransform: 'none', fontWeight: 600 }}>Done</Button>
|
||||
) : (
|
||||
<>
|
||||
<Button onClick={closeAll} disabled={busy} sx={cancelSx}>Cancel</Button>
|
||||
<Button onClick={doClearBrowser} disabled={busy} sx={{ color: c.accent.primary, textTransform: 'none', fontWeight: 600 }}>{busy ? 'Clearing…' : 'Clear'}</Button>
|
||||
</>
|
||||
)}
|
||||
</Box>
|
||||
</Box>
|
||||
</Dialog>
|
||||
|
||||
<Dialog open={eraseOpen} onClose={closeAll} PaperProps={{ sx: dialogPaperSx }}>
|
||||
<Box sx={{ p: 2.5 }}>
|
||||
<Typography sx={titleSx}>Erase all content and settings?</Typography>
|
||||
|
||||
Vendored
+1
@@ -49,6 +49,7 @@ declare global {
|
||||
onWebviewNewWindow: (cb: (url: string, webContentsId: number) => void) => () => void;
|
||||
openExternal: (url: string) => Promise<void>;
|
||||
hardReset?: () => Promise<void>;
|
||||
clearBrowserData?: () => Promise<{ ok: boolean }>;
|
||||
onAuthUrl?: (cb: (url: string) => void) => () => void;
|
||||
onOauthClaim?: (cb: (url: string) => void) => () => void;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user