fix: prevent Windows tray blur→hide race on window show (#3064) - #3082
fix: prevent Windows tray blur→hide race on window show (#3064)#3082marceli1404 wants to merge 1 commit into
Conversation
…3064) On Windows, clicking the tray icon may not transfer focus to the window, triggering electron-menubar's internal blur handler which hides the window after a 100ms timeout. If this timeout fires before the first paint, the user sees no visible result. Workaround: listen for 'after-show' and temporarily set alwaysOnTop=true so the blur handler emits 'focus-lost' instead of hiding. Restore the user's preference after 400ms.
|
I was not quite able to reproduce on the windows machines I had access to, but hopefully this got addressed in the |
|
Thanks for checking, @afonsojramos. The fix hooks into the �fter-show event and temporarily sets �lwaysOnTop: true for 400ms so the blur handler emits ocus-lost instead of calling hideWindow(). This works regardless of whether �lectron-menubar upstream has been updated, since it patches the behavior at the BrowserWindow level. If you have a Windows machine available to test, the key scenario is: left-click or right-click the tray icon — the window should appear and remain visible instead of silently disappearing. Without the fix, the window flashes briefly and vanishes. |
|
We are the maintainers of the dependency, so the fix is easy to apply :) |
|
Thanks everyone! 🙇 A good workaround. I'm hopeful that electron fixes this themselves in a future release. I recall reading something about windows blur behavior changing, but wasn't expecting this type of regression. |
Problem
Issue #3064: On Windows v7.0.0/v7.0.1, clicking the tray icon produces no visible result. The app runs in background (notifications, colored icon) but the window never appears. Silent failure — no errors in logs.
Root Cause
\�lectron-menubar's internal blur handler hides the window 100ms after it loses focus. On Windows, clicking the tray icon may not transfer focus to the window, causing the blur→hide timeout to fire immediately after \showWindow(). When this timeout fires before the first paint cycle, the user sees no visible result.
Relevant Menubar.ts code:
\\ ypescript
this._browserWindow.on('blur', () => {
if (!this._browserWindow) return;
this._browserWindow.isAlwaysOnTop()
? this.emit('focus-lost')
: (this._blurTimeout = setTimeout(() => {
this.hideWindow();
}, 100));
});
\\
If \�lwaysOnTop\ is true, the blur handler emits \ocus-lost\ instead of hiding — this is the escape hatch.
Fix
Listen for the \�fter-show\ event and temporarily set \�lwaysOnTop=true\ for 400ms after showing the window. This causes the blur handler to short-circuit via the \ocus-lost\ path instead of hiding. The user's \keepWindowOnBlur\ preference is restored after the blur race window passes.
Fixes #3064