8092f0e8ee
Symptom (Discord/X report, macOS): exit HUD mode and the small HUD window stays on screen while the main window never regains focus; the toggle now reads the wrong state, so there is no in-app way out. Three defects in the HUD lifecycle, all in the main process: - closeHudWindow() detached the window's 'closed' listener before calling win.close(). close() is a REQUEST that waits on the renderer's unload handlers, so a HUD renderer that never answered left an always-on-top window with no teardown owner and no close broadcast. The 'closed' handler now stays attached and is the single teardown path; a bounded requestHudClose() (electron/hud-close.ts) destroys the window after a 1.5 s grace if the renderer never lets go. - ⌘W inside the HUD was routed to the MAIN renderer's close-active-tab (installPreviewShortcut is wired on every chat window), so it closed a tab in the hidden app window and left the HUD up. ⌘W in the HUD now runs closeHudWindow(), the same path as the exit button. - restoreMainWindowFromHud() was a bare show() and only armed when the main window was isVisible() at HUD-open time. On macOS isVisible() is false for an occluded window (Electron folds occlusionState in), so the app never came back when the HUD was opened over another app, and show() alone does not make the window key. The restore now arms on a live main window and routes through focusWindow() (restore → show → focus). Closes #88513 (credit: PR #90489's diagnosis). Renderer: the handoff now also requests composer focus on the close broadcast, so the app window gets the keyboard, not just the session. Docs: ⌘/Ctrl+W added to the HUD exit list.