fix browser cleanup

This commit is contained in:
Arjun 2026-05-06 17:50:56 +05:30
parent 0bb58e55ac
commit 37c1627d79
2 changed files with 19 additions and 6 deletions

View file

@ -113,7 +113,9 @@ export class BrowserViewManager extends EventEmitter {
attach(window: BrowserWindow): void {
this.cleanupWindowListeners?.();
this.cleanupWindowListeners = null;
this.window = window;
const hostWebContents = window.webContents;
const resetForHostWindowNavigation = () => {
// Renderer refreshes do not run React unmount cleanup reliably, so the
@ -132,10 +134,16 @@ export class BrowserViewManager extends EventEmitter {
};
const handleClosed = () => {
this.cleanupWindowListeners?.();
if (this.window !== window) return;
const tabs = [...this.tabs.values()];
this.cleanupWindowListeners = null;
this.window = null;
this.browserSession = null;
this.bounds = { x: 0, y: 0, width: 0, height: 0 };
for (const tab of tabs) {
this.destroyTab(tab);
}
this.tabs.clear();
this.tabOrder = [];
this.activeTabId = null;
@ -144,14 +152,18 @@ export class BrowserViewManager extends EventEmitter {
this.snapshotCache.clear();
};
window.webContents.on('did-start-loading', handleDidStartLoading);
window.webContents.on('render-process-gone', handleRenderProcessGone);
hostWebContents.on('did-start-loading', handleDidStartLoading);
hostWebContents.on('render-process-gone', handleRenderProcessGone);
window.on('closed', handleClosed);
this.cleanupWindowListeners = () => {
window.webContents.removeListener('did-start-loading', handleDidStartLoading);
window.webContents.removeListener('render-process-gone', handleRenderProcessGone);
window.removeListener('closed', handleClosed);
if (!hostWebContents.isDestroyed()) {
hostWebContents.removeListener('did-start-loading', handleDidStartLoading);
hostWebContents.removeListener('render-process-gone', handleRenderProcessGone);
}
if (!window.isDestroyed()) {
window.removeListener('closed', handleClosed);
}
};
}

View file

@ -58,6 +58,7 @@ if (started) app.quit();
// Single-instance lock: route a second launch (e.g. clicking a rowboat:// link)
// back into the existing process via the 'second-instance' event.
if (!app.requestSingleInstanceLock()) {
console.error('[Main] Another Rowboat instance is already running; exiting this process.');
app.quit();
process.exit(0);
}