Skip to content

Commit a103cf6

Browse files
fix(desktop): input during window teardown no longer throws in the main process
A trailing key-up (e.g. releasing a held Cmd+Q) can reach the window's before-input-event and input-event listeners after the BrowserWindow is destroyed. Both read window.webContents unguarded, so Electron threw "TypeError: Object has been destroyed" as an uncaught main-process error. Both listeners now return early once the window is destroyed, like the zoom-changed listener. The quit shortcut handler still runs first in before-input-event, since it guards its own window access and must see the key-up. Fixes #33614 AI-assisted; verified with the tests and tools listed above.
1 parent d1c29f0 commit a103cf6

1 file changed

Lines changed: 2 additions & 0 deletions

File tree

‎apps/desktop/src/window/DesktopWindow.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -677,6 +677,7 @@ export const make = Effect.gen(function* () {
677677
});
678678
window.webContents.on("before-input-event", (event, input) => {
679679
quitShortcutHandler(event, input);
680+
if (window.isDestroyed()) return;
680681
// Cmd/Ctrl+W reaches the renderer; DevTools uses the native menu shortcut.
681682
window.webContents.setIgnoreMenuShortcuts(
682683
(environment.platform === "darwin" ? input.meta : input.control) &&
@@ -692,6 +693,7 @@ export const make = Effect.gen(function* () {
692693
}
693694
});
694695
window.webContents.on("input-event", (_event, input) => {
696+
if (window.isDestroyed()) return;
695697
if (input.type === "gestureScrollBegin") {
696698
window.webContents.send(TRACKPAD_SCROLL_BEGIN_CHANNEL);
697699
} else if (input.type === "gestureScrollEnd") {

0 commit comments

Comments
 (0)