summaryrefslogtreecommitdiff
path: root/main.js
blob: 73315ca53d7073b5384c4802b5ec58afa9c36eff (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
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const { app, BrowserWindow, ipcMain, shell } = require('electron')
const path = require('path')

const nativeImage = require('electron').nativeImage;
var icon = nativeImage.createFromPath(__dirname + '/src/images/favicon.png');

icon.setTemplateImage(true);

var isMaximized = false;

const createWindow = () => {
    const win = new BrowserWindow({
        width: 1280,
        height: 720,
        minWidth: 600,
        minHeight: 400,
        webPreferences: {
            nodeIntegration: true,
            contextIsolation: false,
            preload: path.join(__dirname, 'preload.js')
        },
        autoHideMenuBar: true,
        titleBarStyle: 'hiddenInset',
        frame: false,
        icon: icon
    })

    win.loadFile('index.html')
    
    win.webContents.setWindowOpenHandler(({ url }) => {
        shell.openExternal(url);
        return { action: 'deny' };
    });
    

    ipcMain.on('max', () => {
        if (isMaximized) {
            win.restore()
            isMaximized = false;
        } else {
            win.maximize()
            isMaximized = true;
        }
    })

    ipcMain.on('min', () => {
        win.minimize()
    })
}

app.whenReady().then(() => {
    createWindow()

    app.on('activate', () => {
        if (BrowserWindow.getAllWindows().length === 0) createWindow()
    })
})

app.on('window-all-closed', () => {
    if (process.platform !== 'darwin') app.quit()
})