-
Notifications
You must be signed in to change notification settings - Fork 46
/
index.js
168 lines (147 loc) · 4.37 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
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
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
/**
* Paladium Launcher - https://github.com/Chaika9/paladiumlauncher
* Copyright (C) 2019 Paladium
*/
const {app, BrowserWindow, ipcMain} = require('electron');
const autoUpdater = require('electron-updater').autoUpdater;
const path = require('path');
const url = require('url');
const ejse = require('ejs-electron');
const isDev = require('./app/assets/js/isdev');
let frame;
let isInitAutoUpdater = false;
function initAutoUpdater(event) {
autoUpdater.autoDownload = false;
autoUpdater.allowPrerelease = true;
if(isDev) {
autoUpdater.autoInstallOnAppQuit = false;
autoUpdater.updateConfigPath = path.join(__dirname, 'dev-app-update.yml');
}
autoUpdater.on('update-available', info => {
event.sender.send('autoUpdateNotification', 'update-available', info);
});
autoUpdater.on('update-downloaded', info => {
event.sender.send('autoUpdateNotification', 'update-downloaded', info);
});
autoUpdater.on('download-progress', (info) => {
event.sender.send('autoUpdateNotification', 'download-progress', info);
});
autoUpdater.on('update-not-available', info => {
event.sender.send('autoUpdateNotification', 'update-not-available', info);
});
autoUpdater.on('checking-for-update', () => {
event.sender.send('autoUpdateNotification', 'checking-for-update');
});
autoUpdater.on('error', (err) => {
event.sender.send('autoUpdateNotification', 'realerror', err);
});
}
function initialize() {
app.setName('Paladium Launcher');
app.disableHardwareAcceleration();
if(makeSingleInstance()) {
return app.quit();
}
ipcMain.on('autoUpdateAction', (event, arg, data) => {
switch(arg) {
case 'initAutoUpdater': {
if(!isInitAutoUpdater) {
initAutoUpdater(event);
isInitAutoUpdater = true;
}
event.sender.send('autoUpdateNotification', 'ready');
break;
}
case 'checkForUpdate': {
autoUpdater.checkForUpdates().catch(err => {
event.sender.send('autoUpdateNotification', 'realerror', err);
});
break;
}
case 'downloadUpdate': {
autoUpdater.downloadUpdate();
break;
}
case 'installUpdateNow': {
autoUpdater.quitAndInstall();
break;
}
default: {
console.log('Unknown argument', arg);
break;
}
}
});
app.on('ready', () => {
createWindow();
});
app.on('window-all-closed', () => {
if(process.platform !== 'darwin') {
app.quit();
}
});
app.on('activate', () => {
if(frame === null) {
createWindow();
}
});
}
function createWindow() {
frame = new BrowserWindow({
width: 1280,
height: 720,
minWidth: 1280,
minHeight: 720,
icon: getPlatformIcon('icon'),
frame: false,
webPreferences: {
preload: path.join(__dirname, 'app', 'assets', 'js', 'preloader.js'),
nodeIntegration: true,
contextIsolation: false
},
backgroundColor: '#2f2f2f'
});
frame.loadURL(url.format({
pathname: path.join(__dirname, 'app', 'app.ejs'),
protocol: 'file:',
slashes: true
}));
frame.setMenu(null);
frame.setResizable(true);
frame.on('closed', () => {
frame = null;
});
}
function getPlatformIcon(filename) {
const os = process.platform;
if(os === 'darwin') {
filename = filename + '.icns';
}
else if(os === 'win32') {
filename = filename + '.ico';
}
else {
filename = filename + '.png';
}
return path.join(__dirname, 'app', 'assets', 'images', 'icons', filename);
}
function makeSingleInstance() {
const lock = app.requestSingleInstanceLock();
if(process.mas) {
return false;
}
if(!lock) {
app.quit();
}
else {
app.on('second-instance', (event, commandLine, workingDirectory) => {
if(frame) {
if(frame.isMinimized()) {
frame.restore();
frame.focus();
}
}
});
}
}
initialize();