You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
1.1 KiB
50 lines
1.1 KiB
7 years ago
|
import { dialog } from 'electron'
|
||
|
import { autoUpdater } from 'electron-updater'
|
||
7 years ago
|
import { updaterLog } from '../utils/log'
|
||
7 years ago
|
|
||
|
autoUpdater.logger = updaterLog
|
||
|
|
||
|
/**
|
||
|
* @class ZapController
|
||
|
*
|
||
|
* The ZapUpdater class manages the electron auto update process.
|
||
|
*/
|
||
|
class ZapUpdater {
|
||
|
/**
|
||
|
* Create a new ZapUpdater instance.
|
||
|
* @param {BrowserWindow} mainWindow BrowserWindow instance to interact with
|
||
|
*/
|
||
|
constructor(mainWindow) {
|
||
|
this.mainWindow = mainWindow
|
||
|
}
|
||
|
|
||
|
init() {
|
||
|
autoUpdater.on('update-downloaded', () => {
|
||
|
const opt = {
|
||
|
type: 'question',
|
||
|
buttons: ['Install', 'Later'],
|
||
|
title: 'Update available',
|
||
|
message: 'An update is available. Restart the app and install?'
|
||
|
}
|
||
|
dialog.showMessageBox(this.mainWindow, opt, choice => {
|
||
|
if (choice !== 0) {
|
||
|
return
|
||
|
}
|
||
|
setTimeout(() => {
|
||
|
autoUpdater.quitAndInstall()
|
||
|
}, 100)
|
||
|
})
|
||
|
})
|
||
|
|
||
|
this.initAutoUpdate()
|
||
|
}
|
||
|
|
||
|
initAutoUpdate() {
|
||
|
autoUpdater.checkForUpdates()
|
||
|
const oneHour = 60 * 60 * 1000
|
||
|
setInterval(() => autoUpdater.checkForUpdates(), oneHour)
|
||
|
}
|
||
|
}
|
||
|
|
||
|
export default ZapUpdater
|