diff --git a/src/renderer/state.ts b/src/renderer/state.ts index 79249c0fa0..a6bfac4e13 100644 --- a/src/renderer/state.ts +++ b/src/renderer/state.ts @@ -837,33 +837,52 @@ export class AppState { return; } - console.log(`State: Removing Electron ${version}`); - if (source === VersionSource.local) { - if (version in this.versions) { - delete this.versions[version]; - saveLocalVersions(Object.values(this.versions)); - } else { - console.log(`State: Version ${version} already removed, doing nothing`); - } - } else { - if ( - state === InstallState.installed || - state == InstallState.downloaded - ) { - await this.installer.remove(version); - if (this.installer.state(version) === InstallState.missing) { - const typeDefsCleaner = async () => { - window.ElectronFiddle.app.electronTypes.uncache(ver); - }; + await navigator.locks.request( + this.getVersionLockName(version), + { + mode: 'exclusive', + ifAvailable: true, + }, + async (lock) => { + // another window is already removing this version + if (!lock) { + return; + } - await typeDefsCleaner(); + console.log(`State: Removing Electron ${version}`); - this.broadcastVersionStates([ver]); + if (source === VersionSource.local) { + if (version in this.versions) { + delete this.versions[version]; + saveLocalVersions(Object.values(this.versions)); + } else { + console.log( + `State: Version ${version} already removed, doing nothing`, + ); + } + } else { + if ( + state === InstallState.installed || + state == InstallState.downloaded + ) { + await this.installer.remove(version); + if (this.installer.state(version) === InstallState.missing) { + const typeDefsCleaner = async () => { + window.ElectronFiddle.app.electronTypes.uncache(ver); + }; + + await typeDefsCleaner(); + + this.broadcastVersionStates([ver]); + } + } else { + console.log( + `State: Version ${version} already removed, doing nothing`, + ); + } } - } else { - console.log(`State: Version ${version} already removed, doing nothing`); - } - } + }, + ); } /** @@ -1049,8 +1068,17 @@ export class AppState { } } - // Fetch new binaries, maybe? - await this.downloadVersion(ver); + await navigator.locks.request( + `downloading:${version}`, + { mode: 'exclusive' }, + async (lock) => { + console.log(`exclusive download lock granted:`); + console.log(lock); + + // Fetch new binaries, maybe? + await this.downloadVersion(ver); + }, + ); } /**