Move auto-updater-win to ES6
This commit is contained in:
parent
c730800f0c
commit
20e26a9639
1 changed files with 50 additions and 55 deletions
|
@ -1,71 +1,66 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const app = require('electron').app
|
const {app} = require('electron')
|
||||||
const EventEmitter = require('events').EventEmitter
|
const {EventEmitter} = require('events')
|
||||||
const squirrelUpdate = require('./squirrel-update-win')
|
const squirrelUpdate = require('./squirrel-update-win')
|
||||||
const util = require('util')
|
|
||||||
|
|
||||||
function AutoUpdater () {
|
class AutoUpdater extends EventEmitter {
|
||||||
EventEmitter.call(this)
|
quitAndInstall () {
|
||||||
}
|
if (!this.updateAvailable) {
|
||||||
|
return this.emitError('No update available, can\'t quit and install')
|
||||||
util.inherits(AutoUpdater, EventEmitter)
|
|
||||||
|
|
||||||
AutoUpdater.prototype.quitAndInstall = function () {
|
|
||||||
if (!this.updateAvailable) {
|
|
||||||
return this.emitError('No update available, can\'t quit and install')
|
|
||||||
}
|
|
||||||
squirrelUpdate.processStart()
|
|
||||||
return app.quit()
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoUpdater.prototype.getFeedURL = function () {
|
|
||||||
return this.updateURL
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoUpdater.prototype.setFeedURL = function (updateURL, headers) {
|
|
||||||
this.updateURL = updateURL
|
|
||||||
}
|
|
||||||
|
|
||||||
AutoUpdater.prototype.checkForUpdates = function () {
|
|
||||||
if (!this.updateURL) {
|
|
||||||
return this.emitError('Update URL is not set')
|
|
||||||
}
|
|
||||||
if (!squirrelUpdate.supported()) {
|
|
||||||
return this.emitError('Can not find Squirrel')
|
|
||||||
}
|
|
||||||
this.emit('checking-for-update')
|
|
||||||
squirrelUpdate.download(this.updateURL, (error, update) => {
|
|
||||||
if (error != null) {
|
|
||||||
return this.emitError(error)
|
|
||||||
}
|
}
|
||||||
if (update == null) {
|
squirrelUpdate.processStart()
|
||||||
this.updateAvailable = false
|
return app.quit()
|
||||||
return this.emit('update-not-available')
|
}
|
||||||
|
|
||||||
|
getFeedURL () {
|
||||||
|
return this.updateURL
|
||||||
|
}
|
||||||
|
|
||||||
|
setFeedURL (updateURL, headers) {
|
||||||
|
this.updateURL = updateURL
|
||||||
|
}
|
||||||
|
|
||||||
|
checkForUpdates () {
|
||||||
|
if (!this.updateURL) {
|
||||||
|
return this.emitError('Update URL is not set')
|
||||||
}
|
}
|
||||||
this.updateAvailable = true
|
if (!squirrelUpdate.supported()) {
|
||||||
this.emit('update-available')
|
return this.emitError('Can not find Squirrel')
|
||||||
squirrelUpdate.update(this.updateURL, (error) => {
|
}
|
||||||
var date, releaseNotes, version
|
this.emit('checking-for-update')
|
||||||
|
squirrelUpdate.download(this.updateURL, (error, update) => {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return this.emitError(error)
|
return this.emitError(error)
|
||||||
}
|
}
|
||||||
releaseNotes = update.releaseNotes
|
if (update == null) {
|
||||||
version = update.version
|
this.updateAvailable = false
|
||||||
|
return this.emit('update-not-available')
|
||||||
|
}
|
||||||
|
this.updateAvailable = true
|
||||||
|
this.emit('update-available')
|
||||||
|
squirrelUpdate.update(this.updateURL, (error) => {
|
||||||
|
var date, releaseNotes, version
|
||||||
|
if (error != null) {
|
||||||
|
return this.emitError(error)
|
||||||
|
}
|
||||||
|
releaseNotes = update.releaseNotes
|
||||||
|
version = update.version
|
||||||
|
|
||||||
// Following information is not available on Windows, so fake them.
|
// Following information is not available on Windows, so fake them.
|
||||||
date = new Date()
|
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()
|
||||||
|
})
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
})
|
}
|
||||||
}
|
|
||||||
|
|
||||||
// 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.
|
||||||
AutoUpdater.prototype.emitError = function (message) {
|
emitError (message) {
|
||||||
return this.emit('error', new Error(message), message)
|
return this.emit('error', new Error(message), message)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
module.exports = new AutoUpdater()
|
module.exports = new AutoUpdater()
|
||||||
|
|
Loading…
Add table
Reference in a new issue