From 9736bb916c2fe205972037d993e3d77234a69cb4 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Wed, 12 Aug 2026 22:31:54 -0400 Subject: [PATCH 1/4] [PM-41905] Add null check for window before executing the autotype mvp keyboard shortcut closure --- .../main-desktop-autotype-mvp.service.spec.ts | 16 ++++++++++++++++ .../main/main-desktop-autotype-mvp.service.ts | 16 +++++++++++----- 2 files changed, 27 insertions(+), 5 deletions(-) diff --git a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts index f296720d3fc0..798575696752 100644 --- a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts +++ b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts @@ -414,5 +414,21 @@ describe("MainDesktopAutotypeMvpService", () => { { windowTitle: "Notepad" }, ); }); + + it("should not throw on shortcut activation if the window does not exist", () => { + const toggleHandler = ipcHandlers.get(AUTOTYPE_MVP_IPC_CHANNELS.TOGGLE); + toggleHandler({}, true); + + mockWindowMain.win = null; + + // Get the registered callback + const registeredCallback = (globalShortcut.register as jest.Mock).mock.calls[0][1]; + + expect(() => registeredCallback()).not.toThrow(); + expect(autotype_mvp.getForegroundWindowTitle).not.toHaveBeenCalled(); + expect(mockLogService.debug).toHaveBeenCalledWith( + "Autotype keyboard shortcut activated, but the main window does not exist.", + ); + }); }); }); diff --git a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts index 1c2c1db88605..7004cbdeb013 100644 --- a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts +++ b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts @@ -102,11 +102,17 @@ export class MainDesktopAutotypeMvpService { const result = globalShortcut.register( this.autotypeKeyboardShortcut.getElectronFormat(), () => { - const windowTitle = autotype_mvp.getForegroundWindowTitle(); - - this.windowMain.win.webContents.send(AUTOTYPE_MVP_IPC_CHANNELS.LISTEN, { - windowTitle, - }); + if (this.windowMain.win != null) { + const windowTitle = autotype_mvp.getForegroundWindowTitle(); + + this.windowMain.win.webContents.send(AUTOTYPE_MVP_IPC_CHANNELS.LISTEN, { + windowTitle, + }); + } else { + this.logService.debug( + "Autotype keyboard shortcut activated, but the main window does not exist.", + ); + } }, ); From cb586a239b52ad40031eddbdfd8db623f93db046 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 17 Aug 2026 09:15:37 -0400 Subject: [PATCH 2/4] [PM-41905] Address PR feedback --- .../src/autofill/main/main-desktop-autotype-mvp.service.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts index 7004cbdeb013..c2ed1e7c7fc3 100644 --- a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts +++ b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.ts @@ -102,7 +102,7 @@ export class MainDesktopAutotypeMvpService { const result = globalShortcut.register( this.autotypeKeyboardShortcut.getElectronFormat(), () => { - if (this.windowMain.win != null) { + if (this.windowMain.win != null && !this.windowMain.win.isDestroyed()) { const windowTitle = autotype_mvp.getForegroundWindowTitle(); this.windowMain.win.webContents.send(AUTOTYPE_MVP_IPC_CHANNELS.LISTEN, { From 4d779bb955b4444c50de08301638402d50b3d760 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 17 Aug 2026 09:36:12 -0400 Subject: [PATCH 3/4] [PM-41905] Address PR feedback part 2 --- .../src/autofill/main/main-desktop-autotype-mvp.service.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts index 798575696752..8baffc9a385e 100644 --- a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts +++ b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts @@ -74,6 +74,7 @@ describe("MainDesktopAutotypeMvpService", () => { // Mock WindowMain with webContents mockWindowMain = { win: { + isDestroyed: jest.fn().mockReturnValue(false), webContents: { send: jest.fn(), }, From 7dcec4fda0a7243ac8a20df8c2c3afd1487e06e8 Mon Sep 17 00:00:00 2001 From: Colton Hurst Date: Mon, 17 Aug 2026 09:44:01 -0400 Subject: [PATCH 4/4] [PM-41905] Address PR feedback, adding a destroyed test --- .../main-desktop-autotype-mvp.service.spec.ts | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts index 8baffc9a385e..2150dbe09a18 100644 --- a/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts +++ b/apps/desktop/src/autofill/main/main-desktop-autotype-mvp.service.spec.ts @@ -431,5 +431,22 @@ describe("MainDesktopAutotypeMvpService", () => { "Autotype keyboard shortcut activated, but the main window does not exist.", ); }); + + it("should not send window title to renderer if the window is destroyed", () => { + const toggleHandler = ipcHandlers.get(AUTOTYPE_MVP_IPC_CHANNELS.TOGGLE); + toggleHandler({}, true); + + (mockWindowMain.win.isDestroyed as jest.Mock).mockReturnValue(true); + + // Get the registered callback + const registeredCallback = (globalShortcut.register as jest.Mock).mock.calls[0][1]; + registeredCallback(); + + expect(autotype_mvp.getForegroundWindowTitle).not.toHaveBeenCalled(); + expect(mockWindowMain.win.webContents.send).not.toHaveBeenCalled(); + expect(mockLogService.debug).toHaveBeenCalledWith( + "Autotype keyboard shortcut activated, but the main window does not exist.", + ); + }); }); });