Skip to content

Commit

Permalink
Fix auto-updater check for updates
Browse files Browse the repository at this point in the history
Change-type: patch
Changelog-entry: Fix auto-updater check for updates
Signed-off-by: Lorenzo Alberto Maria Ambrosi <[email protected]>
  • Loading branch information
thundron committed Aug 2, 2019
1 parent 3a68d84 commit 5703a29
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 8 deletions.
33 changes: 25 additions & 8 deletions lib/gui/etcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,27 @@ const path = require('path')
const _ = require('lodash')
const { autoUpdater } = require('electron-updater')
const Bluebird = require('bluebird')
const compareVersions = require('compare-versions')
const EXIT_CODES = require('../shared/exit-codes')
const buildWindowMenu = require('./menu')
const settings = require('./app/models/settings')
const analytics = require('./app/modules/analytics')
const { getConfig } = require('../shared/utils')
const { version, packageType } = require('../../package.json')
/* eslint-disable lodash/prefer-lodash-method */
/* eslint-disable no-magic-numbers */

const config = settings.getDefaults()

const configUrl = settings.get('configUrl') || 'https://balena.io/etcher/static/config.json'
const packageTypes = [
'rpm',
'deb',
'linux',
'portable',
'zip'
]
const packageUpdatable = _.includes(packageTypes, packageType)
let packageUpdated = false

/**
*
Expand All @@ -40,14 +51,20 @@ const configUrl = settings.get('configUrl') || 'https://balena.io/etcher/static/
const checkForUpdates = async (interval) => {
// We use a while loop instead of a setInterval to preserve
// async execution time between each function call
while (true) {
try {
const release = await autoUpdater.checkForUpdates()
if (release.updateInfo.stagingPercentage) {
await autoUpdater.downloadUpdate()
// eslint-disable-next-line no-unmodified-loop-condition
while (packageUpdatable && !packageUpdated) {
if (settings.get('updatesEnabled')) {
try {
const release = await autoUpdater.checkForUpdates()
const isOutdated = compareVersions(release.updateInfo.version, version) > 0
const shouldUpdate = parseInt(release.updateInfo.stagingPercentage, 10) > 0
if (shouldUpdate && isOutdated && !packageUpdated) {
await autoUpdater.downloadUpdate()
packageUpdated = true
}
} catch (err) {
analytics.logException(err)
}
} catch (err) {
analytics.logException(err)
}
await Bluebird.delay(interval)
}
Expand Down
5 changes: 5 additions & 0 deletions npm-shrinkwrap.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@
"bluebird": "^3.5.3",
"bootstrap-sass": "^3.3.6",
"color": "^2.0.1",
"compare-versions": "3.5.0",
"d3": "^4.13.0",
"debug": "^3.1.0",
"electron-is-running-in-asar": "^1.0.0",
Expand Down

0 comments on commit 5703a29

Please sign in to comment.