Skip to content

Return 404 from window/current when no window is focused - #138

Open
sadiqk2 wants to merge 1 commit into
NativePHP:mainfrom
sadiqk2:fix/window-current-null-focused
Open

Return 404 from window/current when no window is focused#138
sadiqk2 wants to merge 1 commit into
NativePHP:mainfrom
sadiqk2:fix/window-current-null-focused

Conversation

@sadiqk2

@sadiqk2 sadiqk2 commented Aug 14, 2026

Copy link
Copy Markdown
const currentWindow = Object.values(state.windows).find(
    (window) => window.id === BrowserWindow.getFocusedWindow().id,
);

getFocusedWindow() returns null when the app has no focused window — backgrounded, or all windows hidden — so .id throws. getWindowData(undefined) then throws a bare string rather than an Error, which is awkward to surface.

This is reachable from any PHP process that is not driving the UI. A queue worker or the scheduler calling Window::current() hits it whenever the user has the app in the background, so it fails intermittently and for reasons unrelated to the calling code.

404 seemed the closest fit to the existing convention — window/get/:id already answers 404 for a window that does not exist. Happy to return something else if you would rather distinguish "no focus" from "no such window".

getFocusedWindow() returns null whenever the app has no focused window — it is in
the background, or every window is hidden — and the id is read from it without a
check, so the handler throws.

Reachable from any PHP process that is not driving the UI: a queue worker or the
scheduler calling Window::current() will hit it whenever the user is elsewhere.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant