Don't use ES6 class for AutoUpdater windows class

This commit is contained in:
Kevin Sawicki 2016-02-03 09:52:04 -08:00
parent 3af20729bd
commit c842ca1f12

View file

@ -4,59 +4,59 @@ const app = require('electron').app;
const EventEmitter = require('events').EventEmitter; const EventEmitter = require('events').EventEmitter;
const squirrelUpdate = require('./squirrel-update-win'); const squirrelUpdate = require('./squirrel-update-win');
class AutoUpdater extends EventEmitter { function AutoUpdater() {
constructor() { EventEmitter.call(this)
super(); }
}
quitAndInstall() { require('util').inherits(AutoUpdater, EventEmitter);
squirrelUpdate.processStart();
return app.quit();
}
setFeedURL(updateURL) { AutoUpdater.prototype.quitAndInstall = function() {
return this.updateURL = updateURL; squirrelUpdate.processStart();
} return app.quit();
}
checkForUpdates() { AutoUpdater.prototype.setFeedURL = function(updateURL) {
if (!this.updateURL) { return this.updateURL = updateURL;
return this.emitError('Update URL is not set'); }
}
if (!squirrelUpdate.supported()) { AutoUpdater.prototype.checkForUpdates = function() {
return this.emitError('Can not find Squirrel'); if (!this.updateURL) {
} return this.emitError('Update URL is not set');
this.emit('checking-for-update'); }
return squirrelUpdate.download(this.updateURL, (function(_this) { if (!squirrelUpdate.supported()) {
return function(error, update) { return this.emitError('Can not find Squirrel');
}
this.emit('checking-for-update');
return squirrelUpdate.download(this.updateURL, (function(_this) {
return function(error, update) {
if (error != null) {
return _this.emitError(error);
}
if (update == null) {
return _this.emit('update-not-available');
}
_this.emit('update-available');
return squirrelUpdate.update(_this.updateURL, function(error) {
var date, releaseNotes, version;
if (error != null) { if (error != null) {
return _this.emitError(error); return _this.emitError(error);
} }
if (update == null) { releaseNotes = update.releaseNotes, version = update.version;
return _this.emit('update-not-available');
}
_this.emit('update-available');
return squirrelUpdate.update(_this.updateURL, function(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;
return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() { return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() {
return _this.quitAndInstall(); return _this.quitAndInstall();
});
}); });
}; });
})(this)); };
} })(this));
}
// 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) { AutoUpdater.prototype.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;