summaryrefslogtreecommitdiff
path: root/main.js
blob: f72c747c43b516c189f4a02ee3bf1fa19eb0d205 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
const { app, BrowserWindow, session} = require('electron');
const os = require('os');
const {platform} = require("node:os");

require('@electron/remote/main').initialize();
global.hasWindow = false;

global.createWindow = (show) => {
    return new Promise((res) => {
        global.mainWindow = new BrowserWindow({
            width: 1300,
            height: 800,
            title: "Cold Haze",
            minWidth: 800,
            minHeight: 600,
            show: false,
            darkTheme: true,
            transparent: os.platform() === "darwin",
            visualEffectState: "followWindow",
            titleBarStyle: "hidden",
            titleBarOverlay: true,
            vibrancy: os.platform() === "darwin" ? "menu" : null,
            trafficLightPosition: {
                x: 16,
                y: 16
            },
            webPreferences: {
                webviewTag: true,
                nodeIntegration: true,
                contextIsolation: false,
                partition: "persist:default",
                scrollBounce: true,
                webSecurity: false,
                enableRemoteModule: true
            }
        })

        require('@electron/remote/main').enable(mainWindow.webContents);
        mainWindow.loadFile('index.html');

        mainWindow.once('ready-to-show', () => {
            if (show) showWindow();
            res();
        });

        mainWindow.on('close', (event) => {
            hideWindow();
            event.preventDefault();
        });
    });
}

global.hideWindow = () => {
    global['hasWindow'] = false;
    if (process.platform === "darwin") app.dock.hide();
    mainWindow.hide();
}

global.showWindow = () => {
    global['hasWindow'] = true;
    if (process.platform === "darwin") app.dock.show();
    mainWindow.show();
}

global.navigateTo = (url) => {
    mainWindow.send("navigate", url);
}

process.on('uncaughtException', (e) => {
    console.error(e);
})

app.whenReady().then(async () => {
    if ((await session.fromPartition("persist:default").cookies.get({url: 'https://ponies.equestria.horse'})).length > 0) {
        if (process.platform === "darwin") app.dock.hide();
        createWindow();
    } else {
        if (process.platform === "darwin") app.dock.show();
        createWindow(true);
    }

    try {
        require('./luna/index');
    } catch (e) {
        console.error(e);
    }

    app.on('activate', () => {
        if (!global['hasWindow']) showWindow();
    });
});