diff --git a/src/main/modules/app-window/app-window.ts b/src/main/modules/app-window/app-window.ts index 8bc944f..202a62b 100644 --- a/src/main/modules/app-window/app-window.ts +++ b/src/main/modules/app-window/app-window.ts @@ -59,6 +59,7 @@ export abstract class AppWindow implements IAppWindow { this.sessionHelper.setCsp(this._window, this.getCsp()); this._window.on('closed', () => { + this.onClosed(); this._window = null; }); @@ -97,5 +98,7 @@ export abstract class AppWindow implements IAppWindow { event.preventDefault(); } + protected onClosed(): void {} + protected abstract load(window: BrowserWindow): Promise; } diff --git a/src/main/modules/app-window/site-app-window.ts b/src/main/modules/app-window/site-app-window.ts index 1309c66..9328678 100644 --- a/src/main/modules/app-window/site-app-window.ts +++ b/src/main/modules/app-window/site-app-window.ts @@ -24,4 +24,8 @@ export abstract class SiteAppWindow extends UrlAppWindow implements ISiteAppWind public acquireLock(): Promise { return this.windowLock.acquire(); } + + protected onClosed(): void { + this.windowLock.reset(); + } } diff --git a/src/main/modules/mutex/i-mutex.d.ts b/src/main/modules/mutex/i-mutex.d.ts index b6a9fe4..20f5060 100644 --- a/src/main/modules/mutex/i-mutex.d.ts +++ b/src/main/modules/mutex/i-mutex.d.ts @@ -11,6 +11,16 @@ interface IMutex { */ acquire(): Promise; + /** + * release the lock and execute the next consumer. + */ + release(): void; + + /** + * release the lock and do not allow any current consumers to execute. + */ + reset(): void; + isLocked(): boolean; } diff --git a/src/main/modules/mutex/simple-mutex.ts b/src/main/modules/mutex/simple-mutex.ts index a313910..d7c62b9 100644 --- a/src/main/modules/mutex/simple-mutex.ts +++ b/src/main/modules/mutex/simple-mutex.ts @@ -21,6 +21,16 @@ export class SimpleMutex implements IMutex { }); } + public release(): void { + this.locked = false; + this.dispatch(); + } + + public reset(): void { + this.queue = []; + this.locked = false; + } + public isLocked(): boolean { return this.locked; } @@ -37,13 +47,13 @@ export class SimpleMutex implements IMutex { if (!nextResolve) { return; } + // lock the resource this.locked = true; // this is the function which gets called by the consumer to release the lock // it also dispatches the next consumer const releaseFunction = (): void => { - this.locked = false; - this.dispatch(); + this.release(); }; // lock the resource and resolve the promise so the consumer can do its thing