-
Notifications
You must be signed in to change notification settings - Fork 0
/
updater.js
53 lines (47 loc) · 1.64 KB
/
updater.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
const { dialog } = require('electron')
const { autoUpdater } = require('electron-updater')
autoUpdater.logger = require('electron-log');
autoUpdater.logger.transports.file.level = "debug"
autoUpdater.logger.info("set up logger")
autoUpdater.autoDownload = false
autoUpdater.on('error', (error) => {
autoUpdater.logger.info("error")
dialog.showErrorBox('Error: ', error == null ? "unknown" : (error.stack || error).toString())
})
autoUpdater.on('update-available', () => {
dialog.showMessageBox({
type: 'info',
title: 'Found Updates',
message: 'Found updates, do you want update now?',
buttons: ['Sure', 'No']
}).then((buttonIndex, cb) => {
autoUpdater.logger.info(buttonIndex);
if (buttonIndex.response === 0) {
autoUpdater.logger.info("attempting download")
autoUpdater.downloadUpdate()
}
})
})
autoUpdater.on('update-not-available', () => {
dialog.showMessageBox({
title: 'No Updates',
message: 'Current version is up-to-date.'
})
//updater.enabled = true
//updater = null
})
autoUpdater.on('update-downloaded', () => {
dialog.showMessageBox({
title: 'Install Updates',
message: 'Updates downloaded, application will be quit for update...'
}).then( () => {
setImmediate(() => autoUpdater.quitAndInstall())
})
})
// export this to MenuItem click callback
function checkForUpdates (menuItem, focusedWindow, event) {
//updater = menuItem
//updater.enabled = false
autoUpdater.checkForUpdates()
}
module.exports.checkForUpdates = checkForUpdates