diff --git a/docs/USER-DOCUMENTATION.md b/docs/USER-DOCUMENTATION.md index 2285c795ad..cb361c856e 100644 --- a/docs/USER-DOCUMENTATION.md +++ b/docs/USER-DOCUMENTATION.md @@ -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 ------------------------ diff --git a/lib/gui/etcher.js b/lib/gui/etcher.js index 00047ab0d6..66187ced59 100644 --- a/lib/gui/etcher.js +++ b/lib/gui/etcher.js @@ -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 updatablePackageTypes = [ + 'appimage', + 'nsis', + 'dmg' +] +const packageUpdatable = _.includes(updatablePackageTypes, packageType) +let packageUpdated = false /** * @@ -40,14 +49,19 @@ 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() + 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) { + await autoUpdater.downloadUpdate() + packageUpdated = true + } + } catch (err) { + analytics.logException(err) } - } catch (err) { - analytics.logException(err) } await Bluebird.delay(interval) } @@ -110,7 +124,7 @@ const createMainWindow = () => { autoUpdater.on('error', (err) => { analytics.logException(err) }) - if (settings.get('updatesEnabled')) { + if (packageUpdatable) { try { const onlineConfig = await getConfig(configUrl) const autoUpdaterConfig = _.get(onlineConfig, [ 'autoUpdates', 'autoUpdaterConfig' ], { diff --git a/npm-shrinkwrap.json b/npm-shrinkwrap.json index ca1ab375f1..0378d125ed 100644 --- a/npm-shrinkwrap.json +++ b/npm-shrinkwrap.json @@ -14377,4 +14377,4 @@ } } } -} +} \ No newline at end of file