[PM-41905] Add Autotype MVP Window Null Check - #22398
Conversation
…p keyboard shortcut closure
🤖 Bitwarden Claude Code ReviewOverall Assessment: APPROVE This PR adds a null check on Code Review Details
|
| this.windowMain.win.webContents.send(AUTOTYPE_MVP_IPC_CHANNELS.LISTEN, { | ||
| windowTitle, | ||
| }); | ||
| if (this.windowMain.win != null) { |
There was a problem hiding this comment.
🎨 SUGGESTED: Also guard on isDestroyed() to close the remaining shutdown race.
Details and fix
WindowMain only clears this.win inside the closed handler after an await:
// window.main.ts:474
this.win.on("closed", async () => {
this.isClosing = false;
await this.updateWindowState(mainWindowSizeKey, this.win); // <- yields
this.win = null;
});During that await the window is destroyed but win is still non-null, so a shortcut press in that gap reaches this.windowMain.win.webContents.send(...) and throws Object has been destroyed — the exact crash this PR is closing.
| if (this.windowMain.win != null) { | |
| if (this.windowMain.win != null && !this.windowMain.win.isDestroyed()) { |
This matches the existing pattern used elsewhere in the desktop main process (window.main.ts:335 and window.main.ts:592).
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## main #22398 +/- ##
==========================================
- Coverage 53.45% 53.45% -0.01%
==========================================
Files 4275 4275
Lines 135294 135296 +2
Branches 21326 21327 +1
==========================================
- Hits 72328 72326 -2
- Misses 57679 57683 +4
Partials 5287 5287 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
🎟️ Tracking
https://bitwarden.atlassian.net/browse/PM-41905
📔 Objective
If the main window in the desktop app is destroyed, and a user presses the autotype hotkey combination before the quit processes have completed, that the app would most likely crash due to no conditional checking that the window is still valid (not null) before we send the autotype request from the main process → render process.
Adding a null check prevents this crash, in case there are specific tasks prior to app shut down that need to happen.