@@ -234,24 +234,25 @@ export class AppState {
234
234
235
235
private static versionLockNamePrefix = 'version:' ;
236
236
237
+ public activeVersions : Set < string > = new Set ( ) ;
238
+
237
239
private getVersionLockName ( ver : string ) {
238
240
return `${ AppState . versionLockNamePrefix } ${ ver } ` ;
239
241
}
240
242
241
243
/**
242
- * Retrieves all Electron versions that are currently active in some window.
244
+ * Updates the Electron versions that are currently active in some window.
243
245
*/
244
- public async getActiveVersions ( ) : Promise < Set < string > > {
245
- return ( ( await navigator . locks . query ( ) ) . held || [ ] ) . reduce < Set < string > > (
246
- ( acc , item ) => {
247
- if ( item . name ?. startsWith ( AppState . versionLockNamePrefix ) ) {
248
- acc . add ( item . name . split ( AppState . versionLockNamePrefix ) [ 1 ] ) ;
249
- }
246
+ private async updateActiveVersions ( ) : Promise < void > {
247
+ this . activeVersions = ( ( await navigator . locks . query ( ) ) . held || [ ] ) . reduce <
248
+ Set < string >
249
+ > ( ( acc , item ) => {
250
+ if ( item . name ?. startsWith ( AppState . versionLockNamePrefix ) ) {
251
+ acc . add ( item . name . split ( AppState . versionLockNamePrefix ) [ 1 ] ) ;
252
+ }
250
253
251
- return acc ;
252
- } ,
253
- new Set ( ) ,
254
- ) ;
254
+ return acc ;
255
+ } , new Set ( ) ) ;
255
256
}
256
257
257
258
constructor ( versions : RunnableVersion [ ] ) {
@@ -262,6 +263,7 @@ export class AppState {
262
263
addAcceleratorToBlock : action ,
263
264
addLocalVersion : action ,
264
265
addNewVersions : action ,
266
+ activeVersions : observable ,
265
267
channelsToShow : observable ,
266
268
clearConsole : action ,
267
269
currentElectronVersion : computed ,
@@ -505,6 +507,12 @@ export class AppState {
505
507
const { type, payload } = event . data ;
506
508
507
509
switch ( type ) {
510
+ case AppStateBroadcastMessageType . activeVersionsChanged : {
511
+ this . updateActiveVersions ( ) ;
512
+
513
+ break ;
514
+ }
515
+
508
516
case AppStateBroadcastMessageType . isDownloadingAll : {
509
517
this . isDownloadingAll = payload ;
510
518
break ;
@@ -824,9 +832,7 @@ export class AppState {
824
832
public async removeVersion ( ver : RunnableVersion ) : Promise < void > {
825
833
const { version, state, source } = ver ;
826
834
827
- const activeVersions = await this . getActiveVersions ( ) ;
828
-
829
- if ( activeVersions . has ( ver . version ) ) {
835
+ if ( this . activeVersions . has ( ver . version ) ) {
830
836
console . log ( `State: Not removing active version ${ version } ` ) ;
831
837
return ;
832
838
}
@@ -1007,6 +1013,15 @@ export class AppState {
1007
1013
this . getVersionLockName ( version ) ,
1008
1014
{ mode : 'shared' } ,
1009
1015
( lock ) => {
1016
+ // let other windows know we're using this version
1017
+ this . broadcastChannel . postMessage ( {
1018
+ type : AppStateBroadcastMessageType . activeVersionsChanged ,
1019
+ } ) ;
1020
+
1021
+ // the current window's state also needs an update - that's how
1022
+ // the current window knows it can't remove this version
1023
+ this . updateActiveVersions ( ) ;
1024
+
1010
1025
this . hasActiveLock = Boolean ( lock ) ;
1011
1026
1012
1027
/**
0 commit comments