Skip to content
Permalink
Browse files

fix(app): ensure autoupdate setting is honoured

  • Loading branch information...
mrfelton committed Jul 31, 2019
1 parent 99f67ac commit 0ffa26b89e8260674e82ad8f46aee5d186d1d0cf
Showing with 34 additions and 13 deletions.
  1. +34 −13 electron/updater.js
@@ -6,22 +6,21 @@ import delay from '@zap/utils/delay'
import createScheduler from '@zap/utils/scheduler'
import { updaterLog } from '@zap/utils/log'

autoUpdater.logger = updaterLog

/**
* @class ZapUpdater
*
* The ZapUpdater class manages the electron auto update process.
*/
class ZapUpdater {
constructor(mainWindow, options = {}) {
const settings = { ...config.autopilot, options }

this.mainWindow = mainWindow
this.isActive = false
this.scheduler = createScheduler()
this.settings = {}

autoUpdater.logger = updaterLog
autoUpdater.channel = settings.channel
autoUpdater.allowDowngrade = false
this.configure({ ...config.autoupdate, ...options })

autoUpdater.on('update-downloaded', () => {
const opt = {
@@ -40,15 +39,30 @@ class ZapUpdater {
})

// Enable updates if needed.
if (settings.active && !isDev) {
if (this.settings.active && !isDev) {
this.enableAutoUpdates()
} else {
updaterLog.info('Automatic updates not enabled')
}

ipcMain.on('configureAutoUpdater', (event, settings) => {
settings.active ? this.enableAutoUpdates() : this.disableAutoUpdates()
this.configure(settings)
this.settings.active ? this.enableAutoUpdates() : this.disableAutoUpdates()
})
}

/**
* configure - Configure the auto updater.
*
* @param {object} settings Settings
*/
configure(settings) {
Object.assign(this.settings, settings)

autoUpdater.allowDowngrade = false
autoUpdater.channel = this.settings.channel
}

/**
* enableAutoUpdates - Enable automatic updates.
*/
@@ -57,16 +71,18 @@ class ZapUpdater {
return
}
try {
updaterLog.info('Automatic Updates enabled')
this.isActive = true
updaterLog.info('Automatic updates enabled')
autoUpdater.checkForUpdates()
this.scheduler.addTask({
taskId: 'checkForUpdates',
task: () => autoUpdater.checkForUpdates(),
baseDelay: config.autoupdate.interval,
baseDelay: this.settings.interval,
})
this.isActive = true
} catch (error) {
updaterLog.warn('Cannot check for updates', error.message)
updaterLog.warn('There was a problem enabling auto updates: %s', error.message)
this.isActive = false
this.scheduler.removeAllTasks()
}
}

@@ -77,8 +93,13 @@ class ZapUpdater {
if (!this.isActive || isDev) {
return
}
this.scheduler.removeTask('checkForUpdates')
updaterLog.info('Automatic Updates disabled')
try {
this.scheduler.removeAllTasks()
this.isActive = false
updaterLog.info('Automatic updates disabled')
} catch (error) {
updaterLog.warn('There was a problem disabling auto updates: %s', error.message)
}
}
}

0 comments on commit 0ffa26b

Please sign in to comment.
You can’t perform that action at this time.