Socialify

Folder ..

Viewing windowCreator.ts
45 lines (41 loc) • 1.5 KB

 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
44
45
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
            },
            titleBarStyle: 'hiddenInset',
            frame: false
        });
        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);
    }
}