-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
59 lines (51 loc) · 1.39 KB
/
index.js
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
var { app, BrowserWindow, globalShortcut, ipcMain: ipc } = require('electron');
var fs = require('fs');
/**
* @type {BrowserWindow}
*/
let window;
app.on('second-instance', (e) => {
e.preventDefault();
if(window) {
if(!window.isVisible())
window.show();
if(window.isMinimized())
window.maximize();
}
});
app.on('ready', () => {
window = new BrowserWindow({
width: 1000,
height: 700,
frame: false,
minWidth: 1000,
minHeight: 700,
title: "osu! mixer",
icon: "assets/osu-mixer-logo.ico",
show: false,
webPreferences: {
nodeIntegration: true
}
});
window.loadFile("./pages/index.html");
window.on('ready-to-show', () => {
window.show();
});
});
app.on('window-all-closed', app.exit);
/**
*
* @param {{keys:String[],action:String}[]} shortcuts
*/
function registerShortcuts(shortcuts) {
globalShortcut.unregisterAll();
for(let i = 0; i < shortcuts.length; i++) {
globalShortcut.register(shortcuts[i].keys.join("+"), () => {
window.webContents.executeJavaScript(`vars.settings.settings.run("${shortcuts[i].action}")`);
});
}
}
ipc.on("shortcuts", (_ev, shortcuts) => {
fs.writeFileSync(`${app.getPath("userData")}\\shortcuts.json`, JSON.stringify(shortcuts));
registerShortcuts(shortcuts);
});