2020-02-08 23:26:57 +01:00
|
|
|
import { BrowserWindow } from 'electron';
|
|
|
|
import os from 'os';
|
|
|
|
import { IAppWindow } from './i-app-window';
|
2020-03-02 23:15:44 +01:00
|
|
|
import { injectable } from 'inversify';
|
2020-02-08 23:26:57 +01:00
|
|
|
import BrowserWindowConstructorOptions = Electron.BrowserWindowConstructorOptions;
|
|
|
|
|
|
|
|
let defaultOptions = {
|
|
|
|
width: 1600,
|
|
|
|
height: 900,
|
|
|
|
webPreferences: {
|
|
|
|
nodeIntegration: false,
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
switch (os.platform()) {
|
|
|
|
case 'win32':
|
|
|
|
defaultOptions = {
|
|
|
|
...defaultOptions,
|
|
|
|
...{
|
|
|
|
icon: 'resources/icon.ico',
|
|
|
|
},
|
|
|
|
};
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
|
|
|
|
@injectable()
|
|
|
|
export abstract class AppWindow implements IAppWindow {
|
|
|
|
protected _window: BrowserWindow | null;
|
|
|
|
|
|
|
|
protected constructor(options: BrowserWindowConstructorOptions = {}) {
|
|
|
|
this.initialize(options);
|
|
|
|
}
|
|
|
|
|
|
|
|
public get window(): BrowserWindow {
|
|
|
|
return this._window;
|
|
|
|
}
|
|
|
|
|
|
|
|
public open(): Promise<void> {
|
|
|
|
if (this.isClosed()) {
|
|
|
|
this.initialize();
|
|
|
|
}
|
|
|
|
|
|
|
|
return this._window.loadFile('frontend/index.html');
|
|
|
|
}
|
|
|
|
|
|
|
|
public isClosed(): boolean {
|
|
|
|
return !this._window;
|
|
|
|
}
|
|
|
|
|
|
|
|
private initialize(options: BrowserWindowConstructorOptions = {}): void {
|
|
|
|
this._window = new BrowserWindow({ ...defaultOptions, ...options });
|
|
|
|
|
|
|
|
this._window.on('closed', () => {
|
|
|
|
this._window = null;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|