37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
|
import * as Electron from 'electron';
|
||
|
|
||
|
import { Type, ObjectUtil } from '@ucap/core';
|
||
|
|
||
|
import { getBrowserWindowSettings } from './decorators/browser-window-configuration';
|
||
|
import { AppConfiguration } from '../app';
|
||
|
import { Attacher } from './attacher';
|
||
|
import { ElectronBrowserWindow } from './electron-browser-window';
|
||
|
|
||
|
export abstract class Builder {
|
||
|
static build<T extends ElectronBrowserWindow>(
|
||
|
configuration: Partial<AppConfiguration>,
|
||
|
browserWindowType: Type<T>
|
||
|
): T {
|
||
|
const _configuration = getBrowserWindowSettings(
|
||
|
ObjectUtil.classOf(browserWindowType)
|
||
|
);
|
||
|
|
||
|
const constructorOptions = ObjectUtil.isFunction(
|
||
|
_configuration.constructorOptions
|
||
|
)
|
||
|
? _configuration.constructorOptions(configuration)
|
||
|
: _configuration.constructorOptions;
|
||
|
|
||
|
const _browserWindow = new Electron.BrowserWindow(constructorOptions);
|
||
|
const browserWindow = new browserWindowType(_configuration, _browserWindow);
|
||
|
|
||
|
Attacher.attach(browserWindow);
|
||
|
|
||
|
return browserWindow;
|
||
|
}
|
||
|
|
||
|
static destroy<T extends ElectronBrowserWindow>(instance: T) {
|
||
|
Attacher.dettach(instance);
|
||
|
}
|
||
|
}
|