From a36618cc8ac13dc619ccaeb19055f4a09e418e82 Mon Sep 17 00:00:00 2001 From: sadiq khan Date: Fri, 14 Aug 2026 23:07:30 +0530 Subject: [PATCH] Return 404 from window/current when no window is focused MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- .../electron/electron-plugin/src/server/api/window.ts | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/resources/electron/electron-plugin/src/server/api/window.ts b/resources/electron/electron-plugin/src/server/api/window.ts index 63ea220f..ee26e929 100644 --- a/resources/electron/electron-plugin/src/server/api/window.ts +++ b/resources/electron/electron-plugin/src/server/api/window.ts @@ -153,10 +153,15 @@ router.post('/always-on-top', (req, res) => { }); router.get('/current', (req, res) => { + const focused = BrowserWindow.getFocusedWindow(); + + if (!focused) { + res.sendStatus(404); + return; + } + // Find the current window object - const currentWindow = Object.values(state.windows).find( - (window) => window.id === BrowserWindow.getFocusedWindow().id, - ); + const currentWindow = Object.values(state.windows).find((window) => window.id === focused.id); // Get the developer-assigned id for that window const id = Object.keys(state.windows).find((key) => state.windows[key] === currentWindow);