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 6, 2019
1 parent f4ac4de commit a1c2b7b
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 25 deletions.
15 changes: 0 additions & 15 deletions docs/USER-DOCUMENTATION.md
Original file line number Diff line number Diff line change
Expand Up @@ -130,21 +130,6 @@ run Etcher on a GNU/Linux system.

- liblzma (for xz decompression)

Simulate an update alert
------------------------

You can set the `ETCHER_FAKE_S3_LATEST_VERSION` environment variable to a valid
semver version (greater than the current version) to trick the application into
thinking that what you put there is the latest available version, therefore
causing the update notification dialog to be presented at startup.

Note that the value of the variable will be ignored if it doesn't match the
release type of the current application version. For example, setting the
variable to a production version (e.g. `ETCHER_FAKE_S3_LATEST_VERSION=2.0.0`)
will be ignored if you're running a snapshot build, and vice-versa.

See [`PUBLISHING.md`][publishing] for more details about release types.

Recovering broken drives
------------------------

Expand Down
33 changes: 24 additions & 9 deletions lib/gui/etcher.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,16 +21,25 @@ const path = require('path')
const _ = require('lodash')
const { autoUpdater } = require('electron-updater')
const Bluebird = require('bluebird')
const semver = require('semver')
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 UPDATABLE_PACKAGE_TYPES = [
'appimage',
'nsis',
'dmg'
]
const packageUpdatable = _.includes(UPDATABLE_PACKAGE_TYPES, packageType)
let packageUpdated = false

/**
*
Expand All @@ -40,14 +49,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 (!packageUpdated) {
if (settings.get('updatesEnabled')) {
try {
const release = await autoUpdater.checkForUpdates()
const isOutdated = semver.compare(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 Expand Up @@ -110,7 +125,7 @@ const createMainWindow = () => {
autoUpdater.on('error', (err) => {
analytics.logException(err)
})
if (settings.get('updatesEnabled')) {
if (packageUpdatable && settings.get('updatesEnabled')) {
try {
const onlineConfig = await getConfig(configUrl)
const autoUpdaterConfig = _.get(onlineConfig, [ 'autoUpdates', 'autoUpdaterConfig' ], {
Expand Down
2 changes: 1 addition & 1 deletion npm-shrinkwrap.json

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

0 comments on commit a1c2b7b

Please sign in to comment.