RenaiApp/src/main/modules/app-window/site-app-window.ts

32 lines
1.1 KiB
TypeScript

import type { BrowserWindowConstructorOptions, LoadURLOptions } from 'electron';
import { SimpleMutex } from '../mutex/simple-mutex';
import type { SessionHelperInterface } from '../session/session-helper-interface';
import type { SiteAppWindowInterface } from './site-app-window-interface';
import { UrlAppWindow } from './url-app-window';
/**
* This class represents an app window of a site which need to be crawled via the built-in chromium of Electron.
* It offers a lock so that multiple calls do executed simultaneously on the same chromium window.
*/
export abstract class SiteAppWindow extends UrlAppWindow implements SiteAppWindowInterface {
private windowLock: MutexInterface;
protected constructor(
sessionHelper: SessionHelperInterface,
uri: string,
options: BrowserWindowConstructorOptions = {},
loadOptions: LoadURLOptions = {}
) {
super(sessionHelper, uri, options, loadOptions);
this.windowLock = new SimpleMutex();
}
public acquireLock(): Promise<Mutex.ReleaseFunction> {
return this.windowLock.acquire();
}
protected onClosed(): void {
this.windowLock.reset();
}
}