fix(electron): Win10 HUD click-through recovery

This commit is contained in:
webadderall
2026-04-02 16:29:51 +11:00
parent 13f99f07c8
commit b08f4efb37
2 changed files with 57 additions and 0 deletions
+39
View File
@@ -166,6 +166,15 @@ function focusOrCreateMainWindow() {
win.destroy();
return;
}
// On Win32, calling show/moveTop/focus on the transparent HUD overlay
// permanently corrupts setIgnoreMouseEvents forwarding, making it
// click-through. Only focus the editor window; the HUD is alwaysOnTop
// so it doesn't need explicit focus.
if (process.platform === "win32" && !isEditorWindow(mainWindow)) {
return;
}
mainWindow.show();
if (mainWindow.isMinimized()) mainWindow.restore();
mainWindow.moveTop();
@@ -173,6 +182,32 @@ function focusOrCreateMainWindow() {
}
}
/**
* On Windows 10, focus changes and native notifications can break
* {@link BrowserWindow.setIgnoreMouseEvents} forwarding on the transparent HUD
* overlay, causing it to become permanently click-through. Call this after any
* operation that may alter focus or z-order so that hover detection keeps working.
*/
function reassertHudOverlayMouseState() {
if (process.platform !== "win32") {
return;
}
const hud = getHudOverlayWindow();
if (!hud) {
return;
}
// Toggle off then back on so the native WS_EX_TRANSPARENT flag is fully
// re-initialised rather than merely re-asserted in a potentially broken state.
hud.setIgnoreMouseEvents(false);
setTimeout(() => {
if (!hud.isDestroyed()) {
hud.setIgnoreMouseEvents(true, { forward: true });
}
}, 50);
}
function isEditorWindow(window: BrowserWindow) {
return window.webContents.getURL().includes("windowType=editor");
}
@@ -411,6 +446,10 @@ function sendUpdateToastToWindows(channel: "update-toast-state", payload: unknow
});
notification.show();
// On Win10, showing a native notification can break setIgnoreMouseEvents
// forwarding on the transparent HUD overlay. Re-assert it after a short
// delay so the renderer's hover detection keeps working.
reassertHudOverlayMouseState();
activeUpdateNotification = notification;
activeUpdateNotificationKey = notificationKey;
return true;
+18
View File
@@ -322,6 +322,24 @@ export function createHudOverlayWindow(): BrowserWindow {
win.setIgnoreMouseEvents(true, { forward: true });
// On Windows 10, focus changes (e.g. showing a native notification) can break
// setIgnoreMouseEvents forwarding on a transparent always-on-top window, making
// it permanently click-through without hover detection. Re-initialise the
// pass-through-with-forwarding state whenever the window gains focus by toggling
// the flag off then back on so the native WS_EX_TRANSPARENT flag is fully reset.
if (process.platform === "win32") {
win.on("focus", () => {
if (!win.isDestroyed()) {
win.setIgnoreMouseEvents(false);
setTimeout(() => {
if (!win.isDestroyed()) {
win.setIgnoreMouseEvents(true, { forward: true });
}
}, 50);
}
});
}
win.webContents.on("did-finish-load", () => {
win?.webContents.send("main-process-message", new Date().toLocaleString());
setTimeout(() => {