Merge pull request #6566 from electron/win-autoupdater-es6

Move autoUpdater to ES6
This commit is contained in:
Cheng Zhao 2016-07-26 12:46:00 +09:00 committed by GitHub
commit 8d941a6559

View file

@ -1,17 +1,11 @@
'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')
} }
@ -19,15 +13,15 @@ AutoUpdater.prototype.quitAndInstall = function () {
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')
} }
@ -64,8 +58,9 @@ 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()