This repository has been archived by the owner on Mar 11, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
222 lines (180 loc) · 5.13 KB
/
main.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
'use strict'
const {app} = require('electron')
if (require('electron-squirrel-startup')) app.quit()
const updater = require('electron-simple-updater')
const path = require('path')
//const autoUpdater = require('electron').autoUpdater
const BrowserWindow = require('electron').BrowserWindow
const {ipcMain} = require('electron')
// ------------------------------------------- squirrel stuff (for updating) ----------------------------------------------------------------
updater.init({
checkUpdateOnStart: true,
autoDownload: true
})
if (handleSquirrelEvent()) app.quit()
function handleSquirrelEvent () {
if (process.argv.length === 1) {
return false
}
const ChildProcess = require('child_process')
const appFolder = path.resolve(process.execPath, '..')
const rootAtomFolder = path.resolve(appFolder, '..')
const updateDotExe = path.resolve(path.join(rootAtomFolder, 'Update.exe'))
const exeName = path.basename(process.execPath)
const spawn = function (command, args) {
let spawnedProcess
try {
spawnedProcess = ChildProcess.spawn(command, args, {
detached: true
})
} catch (err) {}
return spawnedProcess
}
const spawnUpdate = function (args) {
return spawn(updateDotExe, args)
}
const squirrelEvent = process.argv[1]
switch (squirrelEvent) {
case '--squirrel-install':
case '--squirrel-updated':
// Optionally do things such as:
// - Add your .exe to the PATH
// - Write to the registry for things like file associations and
// explorer context menus
// Install desktop and start menu shortcuts
spawnUpdate(['--createShortcut', exeName])
setTimeout(app.quit, 1000)
return true
case '--squirrel-uninstall':
// Undo anything you did in the --squirrel-install and
// --squirrel-updated handlers
// Remove desktop and start menu shortcuts
spawnUpdate(['--removeShortcut', exeName])
setTimeout(app.quit, 1000)
return true
case '--squirrel-obsolete':
// This is called on the outgoing version of your app before
// we update to the new version - it's the opposite of
// --squirrel-updated
app.quit()
return true
}
}
// ------------------------------------------- real stuff that does something ----------------------------------------------------------------
let win
let downWin
let webWin
let loadWin
function createWindows () {
// web process
webWin = new BrowserWindow({
icon: 'resources/icon/icon.ico',
width: 1000,
height: 500,
show: false
})
webWin.loadURL(`file://${__dirname}/app/web.html`)
/*webWin.webContents.openDevTools({
mode: 'detach'
})*/
// download process
downWin = new BrowserWindow({
icon: 'resources/icon/icon.ico',
width: 1000,
height: 500,
show: false
})
downWin.loadURL(`file://${__dirname}/app/dwn.html`)
/*downWin.webContents.openDevTools({
mode: 'detach'
})*/
// Create the browser window.
win = new BrowserWindow({
icon: 'resources/icon/icon.ico',
width: 1300,
height: 700,
minWidth: 1300,
minHeight: 700,
maxWidth: 1300,
maxHeight: 700,
resizeable: false,
show: false,
frame: false
}).on('close', () => {
app.quit()
})
/*
win.webContents.openDevTools({
mode: 'detach'
})*/
win.loadURL(`file://${__dirname}/index.html`)
updater.addListener('checking-for-update', function (event) {
win.webContents.send('checking-for-update')
})
updater.addListener('update-not-available', function (event) {
win.webContents.send('update-not-available')
})
updater.addListener('update-available(meta)', function (event) {
win.webContents.send('update-available')
})
updater.addListener('update-downloaded(meta)', function (event) {
win.webContents.send('update-available', meta)
})
loadWin = new BrowserWindow({
icon: 'resources/icon/icon.ico',
width: 162,
height: 162,
frame: false,
transparent: true
})
loadWin.loadURL(`file://${__dirname}/app/loading.html`)
setUpIpcHandlers()
}
function setUpIpcHandlers () {
ipcMain.on('to-dwn', function (event, arg) {
downWin.webContents.send('to-dwn', arg)
})
ipcMain.on('to-web', function (event, arg) {
webWin.webContents.send('to-web', arg)
})
ipcMain.on('to-app', function (event, arg) {
win.webContents.send('to-app', arg)
})
}
const shouldQuit = app.makeSingleInstance(function (commandLine, workingDirectory) {
if (win) {
if (win.isMinimized()) win.restore()
if (!win.isVisible()) win.show()
win.focus()
}
})
if (shouldQuit) {
app.quit()
}
app.on('ready', function () {
createWindows()
})
app.on('activate', function () {
if (win === null) {
createWindows()
}
})
ipcMain.on('winprogress-change', function (event, arg) {
win.setProgressBar(arg.progress)
})
ipcMain.on('app-loaded', function (event) {
win.show()
loadWin.destroy()
})
ipcMain.on('focus-window', function (event) {
win.focus()
})
ipcMain.on('close-app', function (event) {
app.quit()
})
ipcMain.on('minimize-app', function (event) {
win.minimize()
})
ipcMain.on('restart-update', function (event) {
updater.quitAndInstall()
})