Merge pull request #6780 from electron/update-available-check

Mark update available until restart
This commit is contained in:
Cheng Zhao 2016-08-09 20:44:26 +09:00 committed by GitHub
commit 01f92a83ab
2 changed files with 19 additions and 9 deletions

View file

@ -10,7 +10,7 @@ class AutoUpdater extends EventEmitter {
return this.emitError('No update available, can\'t quit and install') return this.emitError('No update available, can\'t quit and install')
} }
squirrelUpdate.processStart() squirrelUpdate.processStart()
return app.quit() app.quit()
} }
getFeedURL () { getFeedURL () {
@ -34,21 +34,17 @@ class AutoUpdater extends EventEmitter {
return this.emitError(error) return this.emitError(error)
} }
if (update == null) { if (update == null) {
this.updateAvailable = false
return this.emit('update-not-available') return this.emit('update-not-available')
} }
this.updateAvailable = true this.updateAvailable = true
this.emit('update-available') this.emit('update-available')
squirrelUpdate.update(this.updateURL, (error) => { squirrelUpdate.update(this.updateURL, (error) => {
var date, releaseNotes, version
if (error != null) { if (error != null) {
return this.emitError(error) return this.emitError(error)
} }
releaseNotes = update.releaseNotes const {releaseNotes, version} = update
version = update.version // Date is not available on Windows, so fake it.
const date = new Date()
// Following information is not available on Windows, so fake them.
date = new Date()
this.emit('update-downloaded', {}, releaseNotes, version, date, this.updateURL, () => { this.emit('update-downloaded', {}, releaseNotes, version, date, this.updateURL, () => {
this.quitAndInstall() this.quitAndInstall()
}) })
@ -59,7 +55,7 @@ class AutoUpdater extends EventEmitter {
// Private: Emit both error object and message, this is to keep compatibility // Private: Emit both error object and message, this is to keep compatibility
// with Old APIs. // with Old APIs.
emitError (message) { emitError (message) {
return this.emit('error', new Error(message), message) this.emit('error', new Error(message), message)
} }
} }

View file

@ -50,5 +50,19 @@ if (!process.mas) {
done() done()
}) })
}) })
describe('quitAndInstall', function () {
it('emits an error on Windows when no update is available', function (done) {
if (process.platform !== 'win32') {
return done()
}
ipcRenderer.once('auto-updater-error', function (event, message) {
assert.equal(message, 'No update available, can\'t quit and install')
done()
})
autoUpdater.quitAndInstall()
})
})
}) })
} }