implement barebones auto updater
This commit is contained in:
41
main/auto-updater.js
Normal file
41
main/auto-updater.js
Normal file
@@ -0,0 +1,41 @@
|
||||
module.exports = {
|
||||
init
|
||||
}
|
||||
|
||||
var electron = require('electron')
|
||||
|
||||
var config = require('../config')
|
||||
|
||||
// var app = electron.app
|
||||
var autoUpdater = electron.autoUpdater
|
||||
|
||||
function init () {
|
||||
autoUpdater.on('error', function (err) {
|
||||
console.error('error downloading app update', err.message || err)
|
||||
})
|
||||
|
||||
autoUpdater.setFeedURL(config.AUTO_UPDATE_URL)
|
||||
|
||||
// TODO: remove
|
||||
autoUpdater.checkForUpdates()
|
||||
|
||||
/*
|
||||
* We always check for updates on app startup. To keep app startup fast, we delay this
|
||||
* first check so it happens when there is less going on.
|
||||
*/
|
||||
setTimeout(() => autoUpdater.checkForUpdates(), config.AUTO_UPDATE_CHECK_STARTUP_DELAY)
|
||||
|
||||
/*
|
||||
* After the first check for updates, we continually check for updates on a regular
|
||||
* interval. This is to ensure that checks happen even when the app is left open for a
|
||||
* long time.
|
||||
*/
|
||||
setInterval(() => autoUpdater.checkForUpdates(), config.AUTO_UPDATE_CHECK_INTERVAL)
|
||||
|
||||
autoUpdater.on('checking-for-update', () => console.log('checking for app update'))
|
||||
autoUpdater.on('update-available', () => console.log('app update available'))
|
||||
autoUpdater.on('update-not-available', () => console.log('app update not available'))
|
||||
autoUpdater.on('update-downloaded', function (e) {
|
||||
console.log('app update downloaded', e)
|
||||
})
|
||||
}
|
||||
@@ -2,6 +2,7 @@ var electron = require('electron')
|
||||
|
||||
var app = electron.app
|
||||
|
||||
var autoUpdater = require('./auto-updater')
|
||||
var config = require('../config')
|
||||
var ipc = require('./ipc')
|
||||
var menu = require('./menu')
|
||||
@@ -38,7 +39,10 @@ var argv = sliceArgv(process.argv)
|
||||
|
||||
app.on('open-file', onOpen)
|
||||
app.on('open-url', onOpen)
|
||||
app.on('will-finish-launching', setupCrashReporter)
|
||||
app.on('will-finish-launching', function () {
|
||||
autoUpdater.init()
|
||||
setupCrashReporter()
|
||||
})
|
||||
|
||||
app.ipcReady = false // main window has finished loading and IPC is ready
|
||||
app.isQuitting = false
|
||||
|
||||
Reference in New Issue
Block a user