-
Notifications
You must be signed in to change notification settings - Fork 2
/
updater.js
54 lines (50 loc) · 1.43 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
54
// Modules and variable definition
const { dialog } = require('electron')
const { autoUpdater } = require('electron-updater')
// Uncomment to log updater events/errors
// autoUpdater.logger = require('electron-log')
// autoUpdater.logger.transports.file.level = 'info'
// Disabable auto-download of updates
autoUpdater.autoDownload = false
// Check for app updates
module.exports = () => {
autoUpdater.on('error', (err) => {
console.log(err)
})
// Check for updates
autoUpdater.checkForUpdates()
// Listen for update
autoUpdater.on('update-available', () => {
// Prompt for user to update
dialog.showMessageBox({
type: 'info',
title: 'Update Available',
message: 'A new version of Moby is available. Do you want to update now?',
buttons: ['Update', 'Cancel'],
defaultId: 0,
cancelId: 1
}).then(result => {
// Download if Update chosen
if (result.response === 0) {
autoUpdater.downloadUpdate()
}
})
})
// Listen for update
autoUpdater.on('update-downloaded', () => {
// Prompt for user to update
dialog.showMessageBox({
type: 'info',
title: 'Update Ready',
message: 'Install and restart now?',
buttons: ['Install', 'Later'],
defaultId: 0,
cancelId: 1
}).then(result => {
// Download if Update chosen
if (result.response === 0) {
autoUpdater.quitAndInstall(false, true)
}
})
})
}