Merge pull request #4350 from atom/dont-use-es6-class-for-auto-updater

Don't use ES6 class for auto updater
This commit is contained in:
Kevin Sawicki 2016-02-11 11:27:10 -08:00
commit 38e8208639
3 changed files with 86 additions and 46 deletions

View file

@ -3,22 +3,24 @@
const app = require('electron').app;
const EventEmitter = require('events').EventEmitter;
const squirrelUpdate = require('./squirrel-update-win');
const util = require('util');
class AutoUpdater extends EventEmitter {
constructor() {
super();
function AutoUpdater() {
EventEmitter.call(this);
}
quitAndInstall() {
util.inherits(AutoUpdater, EventEmitter);
AutoUpdater.prototype.quitAndInstall = function() {
squirrelUpdate.processStart();
return app.quit();
}
};
setFeedURL(updateURL) {
AutoUpdater.prototype.setFeedURL = function(updateURL) {
return this.updateURL = updateURL;
}
};
checkForUpdates() {
AutoUpdater.prototype.checkForUpdates = function() {
if (!this.updateURL) {
return this.emitError('Update URL is not set');
}
@ -50,13 +52,12 @@ class AutoUpdater extends EventEmitter {
});
};
})(this));
}
};
// Private: Emit both error object and message, this is to keep compatibility
// with Old APIs.
emitError(message) {
AutoUpdater.prototype.emitError = function(message) {
return this.emit('error', new Error(message), message);
}
}
};
module.exports = new AutoUpdater;

View file

@ -0,0 +1,34 @@
const assert = require('assert');
const autoUpdater = require('electron').remote.autoUpdater;
const ipcRenderer = require('electron').ipcRenderer;
describe('autoUpdater module', function() {
describe('checkForUpdates', function() {
it('emits an error on Windows when called the feed URL is not set', function (done) {
if (process.platform !== 'win32') {
return done();
}
ipcRenderer.once('auto-updater-error', function(event, message) {
assert.equal(message, 'Update URL is not set');
done();
});
autoUpdater.setFeedURL('');
autoUpdater.checkForUpdates();
});
});
describe('setFeedURL', function() {
it('emits an error on Mac OS X when the application is unsigned', function (done) {
if (process.platform !== 'darwin') {
return done();
}
ipcRenderer.once('auto-updater-error', function(event, message) {
assert.equal(message, 'Could not get code signature for running application');
done();
});
autoUpdater.setFeedURL('');
});
});
});

View file

@ -72,6 +72,11 @@ app.on('ready', function() {
// Test if using protocol module would crash.
electron.protocol.registerStringProtocol('test-if-crashes', function() {});
// Send auto updater errors to window to be verified in specs
electron.autoUpdater.on('error', function (error) {
window.send('auto-updater-error', error.message)
});
window = new BrowserWindow({
title: 'Electron Tests',
show: false,