Use ES6 style class
This commit is contained in:
parent
caf7cf5582
commit
02f055b784
1 changed files with 49 additions and 48 deletions
|
@ -1,63 +1,64 @@
|
||||||
|
'use strict';
|
||||||
|
|
||||||
const app = require('electron').app;
|
const app = require('electron').app;
|
||||||
const EventEmitter = require('events').EventEmitter;
|
const EventEmitter = require('events').EventEmitter;
|
||||||
const url = require('url');
|
const url = require('url');
|
||||||
const squirrelUpdate = require('./squirrel-update-win');
|
const squirrelUpdate = require('./squirrel-update-win');
|
||||||
const util = require('util');
|
|
||||||
|
|
||||||
function AutoUpdater() {
|
class AutoUpdater extends EventEmitter {
|
||||||
AutoUpdater.super_.call(this);
|
constructor() {
|
||||||
}
|
super();
|
||||||
|
|
||||||
util.inherits(AutoUpdater, EventEmitter);
|
|
||||||
|
|
||||||
AutoUpdater.prototype.quitAndInstall = function() {
|
|
||||||
squirrelUpdate.processStart();
|
|
||||||
return app.quit();
|
|
||||||
};
|
|
||||||
|
|
||||||
AutoUpdater.prototype.setFeedURL = function(updateURL) {
|
|
||||||
return 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');
|
quitAndInstall() {
|
||||||
|
squirrelUpdate.processStart();
|
||||||
|
return app.quit();
|
||||||
}
|
}
|
||||||
this.emit('checking-for-update');
|
|
||||||
return squirrelUpdate.download(this.updateURL, (function(_this) {
|
setFeedURL(updateURL) {
|
||||||
return function(error, update) {
|
return this.updateURL = updateURL;
|
||||||
if (error != null) {
|
}
|
||||||
return _this.emitError(error);
|
|
||||||
}
|
checkForUpdates() {
|
||||||
if (update == null) {
|
if (!this.updateURL) {
|
||||||
return _this.emit('update-not-available');
|
return this.emitError('Update URL is not set');
|
||||||
}
|
}
|
||||||
_this.emit('update-available');
|
if (!squirrelUpdate.supported()) {
|
||||||
return squirrelUpdate.update(_this.updateURL, function(error) {
|
return this.emitError('Can not find Squirrel');
|
||||||
var date, releaseNotes, version;
|
}
|
||||||
|
this.emit('checking-for-update');
|
||||||
|
return squirrelUpdate.download(this.updateURL, (function(_this) {
|
||||||
|
return function(error, update) {
|
||||||
if (error != null) {
|
if (error != null) {
|
||||||
return _this.emitError(error);
|
return _this.emitError(error);
|
||||||
}
|
}
|
||||||
releaseNotes = update.releaseNotes, version = update.version;
|
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) {
|
||||||
|
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;
|
||||||
url = _this.updateURL;
|
url = _this.updateURL;
|
||||||
return _this.emit('update-downloaded', {}, releaseNotes, version, date, url, function() {
|
return _this.emit('update-downloaded', {}, releaseNotes, version, date, url, 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.
|
||||||
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…
Reference in a new issue