Skip to content

The agent that grows with you

fix(desktop): call isFocused on the window instead of destructuring it

kshitijk4poor44533f11e397
diff --git a/apps/desktop/electron/main-window-lifecycle.test.ts b/apps/desktop/electron/main-window-lifecycle.test.ts
index 329ba0c4046..e944af3286c 100644
--- a/apps/desktop/electron/main-window-lifecycle.test.ts
+++ b/apps/desktop/electron/main-window-lifecycle.test.ts
@@ -73,32 +73,44 @@ test('leaves live-window focus to deep-link delivery', () => {
// Regression for #130810: an explicit relaunch restores + shows + focuses
// (activation), so a minimized or tray-hidden window comes back instead of
-// flashing the taskbar. This must use show(), not showInactive().
+// flashing the taskbar. This must use show(), not showInactive(). The window
+// is a class instance whose methods read `this`, like a real BrowserWindow:
+// destructuring a method off it (`{ isFocused }`) throws "Object has been
+// destroyed" in Electron and dropped every activation (latent since #83998).
test('explicit relaunch activates a minimized tray-hidden window', () => {
const calls: string[] = []
- let minimized = true
- let visible = false
- let focused = false
-
- activateWindow({
- isDestroyed: () => false,
- isMinimized: () => minimized,
- isVisible: () => visible,
- isFocused: () => focused,
- restore: () => {
+
+ class FakeWindow {
+ minimized = true
+ visible = false
+ focused = false
+ isDestroyed() {
+ return false
+ }
+ isMinimized() {
+ return this.minimized
+ }
+ isVisible() {
+ return this.visible
+ }
+ isFocused() {
+ return this.focused
+ }
+ restore() {
calls.push('restore')
- minimized = false
- visible = false
- },
- show: () => {
+ this.minimized = false
+ }
+ show() {
calls.push('show')
- visible = true
- },
- focus: () => {
+ this.visible = true
+ }
+ focus() {
calls.push('focus')
- focused = true
+ this.focused = true
}
- })
+ }
+
+ activateWindow(new FakeWindow())
assert.deepEqual(calls, ['restore', 'show', 'focus'])
})
diff --git a/apps/desktop/electron/window-focus-policy.ts b/apps/desktop/electron/window-focus-policy.ts
index d1d2ff487dd..0cd9548fb0c 100644
--- a/apps/desktop/electron/window-focus-policy.ts
+++ b/apps/desktop/electron/window-focus-policy.ts
@@ -40,6 +40,6 @@ export function revealAction(windowVisible: boolean): 'showInactive' | 'none' {
* doesn't already have it. A `.focus()` call on an already-focused window
* is a foreground pump on Windows and a no-op everywhere else — skip it.
*/
-export function shouldFocusToTakeKeyboard({ isFocused }: FocusPolicyWindow): boolean {
- return !isFocused()
+export function shouldFocusToTakeKeyboard(window: FocusPolicyWindow): boolean {
+ return !window.isFocused()
}