summaryrefslogtreecommitdiff
path: root/main.js
blob: 8ea44967ab7955f1b524a883f08ba27d5faebff2 (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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
const { app, BrowserWindow, globalShortcut, ipcMain } = require('electron');
const path = require('path');

require('@electron/remote/main').initialize();

process.env['ELECTRON_DISABLE_SECURITY_WARNINGS'] = 'true';

const createWindow = () => {
    const mainWindow = new BrowserWindow({
        backgroundColor: "#90a14a",
        frame: false,
        show: false,
        fullscreen: false,
        maximizable: true,
        fullscreenable: false,
        webPreferences: {
            sandbox: false,
            webviewTag: true,
            nodeIntegration: true,
            contextIsolation: false,
            enableRemoteModule: true
        }
    });

    mainWindow.maximize();

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

    ipcMain.on('createGlobalShortcut', (event, args) => {
        globalShortcut.register(args[0], () => {
            mainWindow.send(args[1]);
        });
    });

    mainWindow.on('ready-to-show', () => {
        mainWindow.show();
        mainWindow.focus();
    });

    globalShortcut.registerAll(['Alt+Tab', 'Alt+Shift+Tab', 'Ctrl+Alt+Tab', 'Meta+Tab'], () => {
        mainWindow.send("switch");
    });

    globalShortcut.registerAll(['Alt+F4', 'Meta+F4'/*, 'Ctrl+Q'*/], () => {
        mainWindow.send("close");
    });

    globalShortcut.registerAll(['Alt+Shift+F4', 'Meta+Shift+F4', 'Ctrl+Shift+Q'], () => {
        mainWindow.send("forceQuit");
    });

    globalShortcut.register('Alt+Space', () => {
        mainWindow.send("menu");
    });

    globalShortcut.registerAll(['Super+D', 'Meta+D', 'Alt+D'], () => {
        mainWindow.send("desktop");
    });

    globalShortcut.registerAll(['Ctrl+Alt+Delete', 'Meta+Alt+Delete'], () => {
        mainWindow.send("emergency");
    });

    globalShortcut.registerAll(['VolumeUp', 'Meta+Shift+Up', 'Alt+Shift+Up'], () => {
        mainWindow.send("mediakey", "VolumeUp");
    });

    globalShortcut.registerAll(['VolumeDown', 'Meta+Shift+Down', 'Alt+Shift+Down'], () => {
        mainWindow.send("mediakey", "VolumeDown");
    });

    globalShortcut.registerAll(['BrightnessUp', 'Meta+Ctrl+Up', 'Ctrl+Alt+Up'], () => {
        mainWindow.send("mediakey", "BrightnessUp");
    });

    globalShortcut.registerAll(['BrightnessDown', 'Meta+Ctrl+Down', 'Ctrl+Alt+Down'], () => {
        mainWindow.send("mediakey", "BrightnessDown");
    });

    globalShortcut.registerAll(['VolumeMute', 'Meta+Shift+Space', 'Alt+Shift+Space'], () => {
        mainWindow.send("mediakey", "VolumeMute");
    });

    globalShortcut.register('MediaNextTrack', () => {
        mainWindow.send("mediakey", "MediaNextTrack");
    });

    globalShortcut.register('MediaPreviousTrack', () => {
        mainWindow.send("mediakey", "MediaPreviousTrack");
    });

    globalShortcut.register('MediaStop', () => {
        mainWindow.send("mediakey", "MediaStop");
    });

    globalShortcut.register('MediaPlayPause', () => {
        mainWindow.send("mediakey", "MediaPlayPause");
    });

    globalShortcut.registerAll(['PrintScreen', 'Meta+Shift+S', 'Alt+Shift+S'], () => {
        mainWindow.send("mediakey", "PrintScreen");
    });
}
app.whenReady().then(() => {
    createWindow();
});

app.on('window-all-closed', () => {
    app.quit();
});