aboutsummaryrefslogtreecommitdiff
path: root/src/windowCreator.ts
blob: 859ee0353108e422cc8f1ad042e97e93f21825ed (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
import { BrowserWindow } from 'electron';
import * as path from 'path';

export default class windowCreator {
    static mainWindow: Electron.BrowserWindow;
    static application: Electron.App;
    static BrowserWindow;
    private static onWindowAllClosed() {
        if (process.platform !== 'darwin') {
            windowCreator.application.quit();
        }
    }

    private static onClose() {
        // Dereference the window object. 
        windowCreator.mainWindow = null;
    }

    private static onReady() {
        windowCreator.mainWindow = new windowCreator.BrowserWindow({
            width: 800,
            height: 600,
            webPreferences: {
                preload: path.join(__dirname, 'preload.js'),
                nodeIntegration: true
            },
        });
        windowCreator.mainWindow
            .loadURL('file://' + __dirname + '/../app.html');
        windowCreator.mainWindow.on('closed', windowCreator.onClose);
    }

    static main(app: Electron.App, browserWindow: typeof BrowserWindow) {
        // we pass the Electron.App object and the  
        // Electron.BrowserWindow into this function 
        // so this class has no dependencies. This 
        // makes the code easier to write tests for 
        windowCreator.BrowserWindow = browserWindow;
        windowCreator.application = app;
        windowCreator.application.on('window-all-closed', windowCreator.onWindowAllClosed);
        windowCreator.application.on('ready', windowCreator.onReady);
    }
}