forked from kolay-v/GrinchPlayer
-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
80 lines (66 loc) · 1.9 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
77
78
79
80
'use strict';
const path = require('path');
const {app, BrowserWindow} = require('electron');
// eslint-disable-next-line no-unused-vars
const cache = require('v8-compile-cache');
const {is} = require('electron-util');
const unhandled = require('electron-unhandled');
const debug = require('electron-debug');
const config = require('./config');
unhandled();
debug();
// Note: Must match `build.appId` in package.json
app.setAppUserModelId('com.Nik.GrinchPlayer');
app.disableHardwareAcceleration();
// Set userData to current folder (portable app)
if(process.platform == 'win32'){
app.setPath('userData', process.env.PORTABLE_EXECUTABLE_DIR + '/' + app.getName());
}else{
app.setPath('userData', __dirname);
}
// 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: 1280,
height: 768,
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();
})();