Move auto-updater-win to ES6

This commit is contained in:
Samuel Attard 2016-07-26 11:40:55 +10:00
parent c730800f0c
commit 20e26a9639

View file

@ -1,33 +1,27 @@
'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 () {
}
util.inherits(AutoUpdater, EventEmitter)
AutoUpdater.prototype.quitAndInstall = function () {
if (!this.updateAvailable) { if (!this.updateAvailable) {
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() return app.quit()
} }
AutoUpdater.prototype.getFeedURL = function () { getFeedURL () {
return this.updateURL return this.updateURL
} }
AutoUpdater.prototype.setFeedURL = function (updateURL, headers) { setFeedURL (updateURL, headers) {
this.updateURL = updateURL this.updateURL = updateURL
} }
AutoUpdater.prototype.checkForUpdates = function () { checkForUpdates () {
if (!this.updateURL) { if (!this.updateURL) {
return this.emitError('Update URL is not set') return this.emitError('Update URL is not set')
} }
@ -60,12 +54,13 @@ AutoUpdater.prototype.checkForUpdates = function () {
}) })
}) })
}) })
} }
// 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()