Skip to content

The agent that grows with you

fix(desktop): activate a tray-hidden window when anything but the tray restores it

ethernetcb326e32c720
diff --git a/apps/desktop/electron/minimize-to-tray.test.ts b/apps/desktop/electron/minimize-to-tray.test.ts
index d342102823e..23c99ec8c52 100644
--- a/apps/desktop/electron/minimize-to-tray.test.ts
+++ b/apps/desktop/electron/minimize-to-tray.test.ts
@@ -195,6 +195,52 @@ test('Windows restore re-activates the window instead of showInactive (#119252)'
}
})
+test('Windows restore of a tray-hidden window by any other path activates it (#127349)', async () => {
+ setPlatform('win32')
+
+ try {
+ const { controller, main } = setup()
+ await controller.start()
+ await controller.setEnabled(true)
+
+ main.minimize()
+ await flushDeferredHide()
+
+ const show = vi.spyOn(main, 'show')
+ const focus = vi.spyOn(main, 'focus')
+
+ // A relaunch, deep link or notification click restores without the tray.
+ // restore() alone leaves a painted window that is not the OS foreground
+ // window, so it drops all input. It needs show() then focus().
+ main.restore()
+ await flushDeferredHide()
+ expect(show).toHaveBeenCalledOnce()
+ expect(focus).toHaveBeenCalledOnce()
+ expect(main.skipped).toBe(false)
+ expect(show.mock.invocationCallOrder[0]).toBeLessThan(focus.mock.invocationCallOrder[0])
+ } finally {
+ restorePlatform()
+ }
+})
+
+test('a restore of a window the tray never hid is left alone', async () => {
+ setPlatform('win32')
+
+ try {
+ const { main } = setup()
+ const show = vi.spyOn(main, 'show')
+ const focus = vi.spyOn(main, 'focus')
+
+ main.minimize()
+ main.restore()
+ await flushDeferredHide()
+ expect(show).not.toHaveBeenCalled()
+ expect(focus).not.toHaveBeenCalled()
+ } finally {
+ restorePlatform()
+ }
+})
+
test('Windows tray hide releases keyboard focus before hiding (#126570)', async () => {
setPlatform('win32')
diff --git a/apps/desktop/electron/minimize-to-tray.ts b/apps/desktop/electron/minimize-to-tray.ts
index b7c2424cf36..6551e2545c4 100644
--- a/apps/desktop/electron/minimize-to-tray.ts
+++ b/apps/desktop/electron/minimize-to-tray.ts
@@ -61,9 +61,9 @@ export function createMinimizeToTray(options: Options) {
}
}
- const released = (win: BrowserWindow) => {
+ const released = (win: BrowserWindow): boolean => {
if (!hidden.delete(win)) {
- return
+ return false
}
if (process.platform === 'win32') {
@@ -71,6 +71,8 @@ export function createMinimizeToTray(options: Options) {
}
showDock()
+
+ return true
}
const restoreHidden = () => {
@@ -268,14 +270,27 @@ export function createMinimizeToTray(options: Options) {
win.on('query-session-end', () => {
quitting = true
})
- win.on('show', () => {
- released(win)
- syncDock()
- })
- win.on('restore', () => {
- released(win)
+
+ // A relaunch, a deep link or a notification click can restore a tray-hidden
+ // window without the tray. restore() alone paints the window on Windows but
+ // does not make it the foreground window, so it drops all input (#127349).
+ // Finish the activation like restoreHidden() does. Defer it, because the
+ // native restore must finish first (same reason as the deferred hide).
+ const release = () => {
+ if (released(win) && process.platform === 'win32') {
+ setImmediate(() => {
+ if (!win.isDestroyed() && !win.isMinimized() && win.isVisible()) {
+ win.show()
+ win.focus()
+ }
+ })
+ }
+
syncDock()
- })
+ }
+
+ win.on('show', release)
+ win.on('restore', release)
win.on('closed', () => {
windows.delete(win)
hidden.delete(win)