mirror of
https://github.com/balena-io/etcher.git
synced 2025-04-24 15:27:17 +00:00
Merge pull request #2875 from balena-io/fix-auto-updater
Fix auto updater
This commit is contained in:
commit
5cfb95e8ea
@ -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
|
||||
------------------------
|
||||
|
||||
|
@ -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' ], {
|
||||
|
2
npm-shrinkwrap.json
generated
2
npm-shrinkwrap.json
generated
@ -14377,4 +14377,4 @@
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user