-
-
Notifications
You must be signed in to change notification settings - Fork 3
/
main.js
executable file
·232 lines (212 loc) · 5.75 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
223
224
225
226
227
228
229
230
231
232
const {
app,
BrowserWindow,
Menu,
protocol,
ipcMain,
dialog,
Notification,
} = require('electron')
const log = require('electron-log')
const ProgressBar = require('electron-progressbar')
const { autoUpdater } = require('electron-updater')
// let updater
var progressbar
autoUpdater.autoDownload = false
app.commandLine.appendSwitch('--autoplay-policy', 'no-user-gesture-required')
let template = []
// if (process.platform === 'darwin') {
// OS X
const name = app.getName()
template.unshift({
label: name,
submenu: [
{
label: 'About ' + name,
role: 'about',
},
{
label: 'Dev Tools',
accelerator: 'Command+I',
click () { win.webContents.openDevTools() },
},
{
label: 'Quit',
accelerator: 'Command+Q',
click () {
if (!(progressbar == null)) {
progressbar.close()
};
app.quit()
},
},
],
})
// }
function createWindow () {
// Create the browser window.
win = new BrowserWindow({
// width: 1440,
// height: 900,
// resizable: false,
resizable: true,
fullscreen: true,
webPreferences: {
devTools: true,
preload: 'js/jquery.min.js',
nodeIntegration: true,
// preload: 'js/jquery-ui.js'
},
backgroundColor: '#000000',
title: 'KDM 1.5 Story',
// frame: false,
})
// global.sharedObj = {path: app.getPath('userData')};
// and load the index.html of the app.
win.loadFile('index.html')
// win.webContents.openDevTools();
}
let win
function sendStatusToWindow (text) {
log.info(text)
// win.webContents.send('message', text);
// console.log(text)
}
// function createDefaultWindow() {
// win = new BrowserWindow();
// win.webContents.openDevTools();
// win.on('closed', () => {
// win = null;
// });
// win.loadURL(`file://${__dirname}/version.html#v${app.getVersion()}`);
// return win;
// }
autoUpdater.on('checking-for-update', () => {
sendStatusToWindow('Checking for update...')
})
// autoUpdater.on('update-available', (info) => {
// sendStatusToWindow('Update available.');
// })
autoUpdater.on('update-available', () => {
// if (process.platform in ["win32", "osx"]) {
if (true) {
dialog.showMessageBox({
title: 'Update ready',
message: 'New app version was released!\nPlease download it from:\nhttps://kdm-story.site.',
})
} else {
dialog.showMessageBox({
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Yes', 'No'],
}, (buttonIndex) => {
if (buttonIndex === 0) {
autoUpdater.downloadUpdate()
progressbar = new ProgressBar({
indeterminate: false,
value: 0,
maxValue: 100,
browserWindow: {
text: 'Downloading update',
detail: 'Wait...',
parent: win,
webPreferences: {
nodeIntegration: true,
},
minimizable: true,
closable: true,
resizable: true,
},
})
progressbar.on('completed', function () {
log.info(`completed...`)
progressbar.detail = 'Finished download!'
})
progressbar.on('aborted', function (value) {
log.info(`aborted! ${value}%`)
})
progressbar.on('progress', function (value) {
sendStatusToWindow(`Downloaded ${value}%...`)
progressbar.detail = `Downloaded: ${value}%`
})
} else {
// updater.enabled = true
// updater = null
}
})
}
})
// autoUpdater.on('update-not-available', (info) => {
// sendStatusToWindow('Update not available.');
// })
autoUpdater.on('error', (err) => {
sendStatusToWindow('Error in auto-updater. ' + err)
dialog.showMessageBox({
title: 'Error:',
message: 'Error in auto update: ' + err,
})
// updater.enabled = true
// updater = null
})
let prevPercent = 0
autoUpdater.on('download-progress', (progressObj) => {
let log_message = 'Download speed: ' + progressObj.bytesPerSecond
log_message = log_message + ' - Downloaded ' + progressObj.percent + '%'
log_message = log_message + ' (' + progressObj.transferred + '/' + progressObj.total + ')'
sendStatusToWindow(log_message)
// dialog.showMessageBox({
// title: 'Download progress',
// message: log_message
// })
// let myNotification = new Notification('Update:', {
// body: log_message
// });
if (Math.floor(progressObj.percent) - prevPercent > 0) {
progressbar.value += Math.floor(progressObj.percent) - prevPercent
prevPercent = Math.floor(progressObj.percent)
};
})
// autoUpdater.on('update-downloaded', (info) => {
// sendStatusToWindow('Update downloaded');
// });
autoUpdater.on('update-not-available', () => {
// dialog.showMessageBox({
// title: 'No Updates',
// message: 'Current version is up-to-date.'
// })
sendStatusToWindow('Current version is up-to-date.')
// updater.enabled = true
// updater = null
})
autoUpdater.on('update-downloaded', () => {
progressbar.setCompleted()
dialog.showMessageBox({
title: 'Install Updates',
message: 'Updates downloaded, application will restart to update...',
}, () => {
setImmediate(() => autoUpdater.quitAndInstall())
})
})
app.on('ready', function () {
// Create the Menu
const menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(menu)
createWindow()
})
app.on('window-all-closed', () => {
if (!(progressbar == null)) {
progressbar.close()
};
app.quit()
})
app.on('ready', function () {
// autoUpdater.checkForUpdatesAndNotify();
log.info('Checking for update...')
autoUpdater.checkForUpdates()
log.info('Done checking!')
})
process.on('uncaughtException', function (error) {
log.warn(error)
})
// app.on('ready', createWindow)