Skip to content

Commit adffb13

Browse files
committed
Fix: Handle destroyed windows on app quit
- Add isDestroyed() check in attachCrashEvents before sending events - Properly destroy all windows in cleanupBeforeQuit - Clear windows Set and activePorts on quit
1 parent 612a869 commit adffb13

1 file changed

Lines changed: 17 additions & 2 deletions

File tree

src/main/index.ts

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -171,11 +171,15 @@ function createNewWindow(): BrowserWindow {
171171

172172
function attachCrashEvents(win: BrowserWindow): void {
173173
onProcessCrash(() => {
174-
win.webContents.send('opencode-web-crashed')
174+
if (!win.isDestroyed()) {
175+
win.webContents.send('opencode-web-crashed')
176+
}
175177
})
176178

177179
onTunnelCrash(() => {
178-
win.webContents.send('cloudflare-tunnel-crashed')
180+
if (!win.isDestroyed()) {
181+
win.webContents.send('cloudflare-tunnel-crashed')
182+
}
179183
void startBackgroundTunnelIfEnabled()
180184
})
181185
}
@@ -272,6 +276,17 @@ function setupMenu(): void {
272276
}
273277

274278
async function cleanupBeforeQuit(): Promise<void> {
279+
isQuitting = true
280+
281+
// Clean up all windows
282+
for (const win of windows) {
283+
if (!win.isDestroyed()) {
284+
win.destroy()
285+
}
286+
}
287+
windows.clear()
288+
289+
// Clean up RPC ports
275290
for (const port of activePorts.values()) {
276291
port.close()
277292
}

0 commit comments

Comments
 (0)