@@ -52,6 +52,16 @@ export class WindowsAPI {
5252 d ( `Observing window[${ windowId } ]` )
5353 }
5454
55+ private createWindowTabsDetails ( win : Electron . BaseWindow ) {
56+ return Array . from ( this . ctx . store . tabs )
57+ . filter ( ( tab ) => {
58+ const ownerWindow = this . ctx . store . tabToWindow . get ( tab )
59+ return ownerWindow ?. isDestroyed ( ) ? false : ownerWindow ?. id === win . id
60+ } )
61+ . map ( ( tab ) => this . ctx . store . tabDetailsCache . get ( tab . id ) as chrome . tabs . Tab )
62+ . filter ( Boolean )
63+ }
64+
5565 private createWindowDetails ( win : Electron . BaseWindow ) {
5666 const details : Partial < chrome . windows . Window > = {
5767 id : win . id ,
@@ -60,13 +70,7 @@ export class WindowsAPI {
6070 left : win . getPosition ( ) [ 0 ] ,
6171 width : win . getSize ( ) [ 0 ] ,
6272 height : win . getSize ( ) [ 1 ] ,
63- tabs : Array . from ( this . ctx . store . tabs )
64- . filter ( ( tab ) => {
65- const ownerWindow = this . ctx . store . tabToWindow . get ( tab )
66- return ownerWindow ?. isDestroyed ( ) ? false : ownerWindow ?. id === win . id
67- } )
68- . map ( ( tab ) => this . ctx . store . tabDetailsCache . get ( tab . id ) as chrome . tabs . Tab )
69- . filter ( Boolean ) ,
73+ tabs : this . createWindowTabsDetails ( win ) ,
7074 incognito : ! this . ctx . session . isPersistent ( ) ,
7175 type : 'normal' , // TODO
7276 state : getWindowState ( win ) ,
@@ -80,7 +84,12 @@ export class WindowsAPI {
8084
8185 private getWindowDetails ( win : Electron . BaseWindow ) {
8286 if ( this . ctx . store . windowDetailsCache . has ( win . id ) ) {
83- return this . ctx . store . windowDetailsCache . get ( win . id )
87+ const cachedDetails = this . ctx . store . windowDetailsCache . get ( win . id )
88+ // Update the cached details with the latest tabs, otherwise it will be stale.
89+ if ( cachedDetails ) {
90+ cachedDetails . tabs = this . createWindowTabsDetails ( win )
91+ }
92+ return cachedDetails
8493 }
8594 const details = this . createWindowDetails ( win )
8695 return details
0 commit comments