-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.js
76 lines (61 loc) · 1.77 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
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
'use strict';
const path = require('path');
const {app, BrowserWindow} = require('electron');
const {is} = require('electron-util');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
const contextMenu = require('electron-context-menu');
const config = require('./config');
unhandled();
debug();
contextMenu();
// Note: Must match `build.appId` in package.json
app.setAppUserModelId('com.Nik.GrinchPlayer');
// Set userData to current folder (portable app)
// app.setPath('userData', process.env.PORTABLE_EXECUTABLE_DIR + '/' + app.getName());
// Prevent variables from being garbage collected
let mainWindow;
const bounds = config.get('bounds') || {};
const createMainWindow = async () => {
const appName = app.getName() + ' v' + app.getVersion();
const iconPath = path.join(__dirname, 'static/icon-64.png');
const win = new BrowserWindow({
title: appName,
show: false,
frame: false,
icon: iconPath,
width: 1600,
height: 1200,
webPreferences: {
nodeIntegration: true
}
});
win.setBounds(bounds);
win.on('ready-to-show', () => {
win.show();
});
win.on('close', () => {
config.set('bounds', win.getBounds());
});
win.on('closed', () => {
// Dereference the window
// For multiple windows store them in an array
mainWindow = undefined;
});
await win.loadFile(path.join(__dirname, 'index.html'));
return win;
};
app.on('window-all-closed', () => {
if (!is.macos) {
app.quit();
}
});
app.on('activate', () => {
if (!mainWindow) {
mainWindow = createMainWindow();
}
});
(async () => {
await app.whenReady();
mainWindow = await createMainWindow();
})();