2021-01-06 02:35:46 +01:00
|
|
|
import type { BrowserWindowConstructorOptions, LoadURLOptions } from 'electron';
|
2021-01-04 23:40:15 +01:00
|
|
|
import { SimpleMutex } from '../mutex/simple-mutex';
|
2021-01-06 02:35:46 +01:00
|
|
|
import type { SessionHelperInterface } from '../session/session-helper-interface';
|
|
|
|
import type { SiteAppWindowInterface } from './site-app-window-interface';
|
2021-01-04 23:40:15 +01:00
|
|
|
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.
|
|
|
|
*/
|
2021-01-06 02:35:46 +01:00
|
|
|
export abstract class SiteAppWindow extends UrlAppWindow implements SiteAppWindowInterface {
|
|
|
|
private windowLock: MutexInterface;
|
2021-01-04 23:40:15 +01:00
|
|
|
|
|
|
|
protected constructor(
|
2021-01-07 04:51:07 +01:00
|
|
|
logger: LoggerInterface,
|
2021-01-06 02:35:46 +01:00
|
|
|
sessionHelper: SessionHelperInterface,
|
2021-01-04 23:40:15 +01:00
|
|
|
uri: string,
|
|
|
|
options: BrowserWindowConstructorOptions = {},
|
|
|
|
loadOptions: LoadURLOptions = {}
|
|
|
|
) {
|
2021-01-07 04:51:07 +01:00
|
|
|
super(logger, sessionHelper, uri, options, loadOptions);
|
2021-01-04 23:40:15 +01:00
|
|
|
this.windowLock = new SimpleMutex();
|
|
|
|
}
|
|
|
|
|
|
|
|
public acquireLock(): Promise<Mutex.ReleaseFunction> {
|
|
|
|
return this.windowLock.acquire();
|
|
|
|
}
|
2021-01-05 02:29:01 +01:00
|
|
|
|
|
|
|
protected onClosed(): void {
|
|
|
|
this.windowLock.reset();
|
|
|
|
}
|
2021-01-04 23:40:15 +01:00
|
|
|
}
|