From 0c92273a861187befe53a06f944ba416994e88e5 Mon Sep 17 00:00:00 2001 From: Evan Date: Sun, 29 Mar 2026 16:08:28 +0100 Subject: [PATCH] fix: refresh cached window tab details on read --- .../src/browser/api/windows.ts | 25 +++++++++++++------ 1 file changed, 17 insertions(+), 8 deletions(-) diff --git a/packages/electron-chrome-extensions/src/browser/api/windows.ts b/packages/electron-chrome-extensions/src/browser/api/windows.ts index 76ed5339..02a3f9a0 100644 --- a/packages/electron-chrome-extensions/src/browser/api/windows.ts +++ b/packages/electron-chrome-extensions/src/browser/api/windows.ts @@ -51,6 +51,16 @@ export class WindowsAPI { d(`Observing window[${windowId}]`) } + private createWindowTabsDetails(win: Electron.BaseWindow) { + return Array.from(this.ctx.store.tabs) + .filter((tab) => { + const ownerWindow = this.ctx.store.tabToWindow.get(tab) + return ownerWindow?.isDestroyed() ? false : ownerWindow?.id === win.id + }) + .map((tab) => this.ctx.store.tabDetailsCache.get(tab.id) as chrome.tabs.Tab) + .filter(Boolean) + } + private createWindowDetails(win: Electron.BaseWindow) { const details: Partial = { id: win.id, @@ -59,13 +69,7 @@ export class WindowsAPI { left: win.getPosition()[0], width: win.getSize()[0], height: win.getSize()[1], - tabs: Array.from(this.ctx.store.tabs) - .filter((tab) => { - const ownerWindow = this.ctx.store.tabToWindow.get(tab) - return ownerWindow?.isDestroyed() ? false : ownerWindow?.id === win.id - }) - .map((tab) => this.ctx.store.tabDetailsCache.get(tab.id) as chrome.tabs.Tab) - .filter(Boolean), + tabs: this.createWindowTabsDetails(win), incognito: !this.ctx.session.isPersistent(), type: 'normal', // TODO state: getWindowState(win), @@ -79,7 +83,12 @@ export class WindowsAPI { private getWindowDetails(win: Electron.BaseWindow) { if (this.ctx.store.windowDetailsCache.has(win.id)) { - return this.ctx.store.windowDetailsCache.get(win.id) + const cachedDetails = this.ctx.store.windowDetailsCache.get(win.id) + // Update the cached details with the latest tabs, otherwise it will be stale. + if (cachedDetails) { + cachedDetails.tabs = this.createWindowTabsDetails(win) + } + return cachedDetails } const details = this.createWindowDetails(win) return details