From c842ca1f127cb6e9b1850929c7b6a319c323536b Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 09:52:04 -0800 Subject: [PATCH 1/4] Don't use ES6 class for AutoUpdater windows class --- .../api/lib/auto-updater/auto-updater-win.js | 88 +++++++++---------- 1 file changed, 44 insertions(+), 44 deletions(-) diff --git a/atom/browser/api/lib/auto-updater/auto-updater-win.js b/atom/browser/api/lib/auto-updater/auto-updater-win.js index f8a07902f21..1c81763f35e 100644 --- a/atom/browser/api/lib/auto-updater/auto-updater-win.js +++ b/atom/browser/api/lib/auto-updater/auto-updater-win.js @@ -4,59 +4,59 @@ const app = require('electron').app; const EventEmitter = require('events').EventEmitter; const squirrelUpdate = require('./squirrel-update-win'); -class AutoUpdater extends EventEmitter { - constructor() { - super(); - } +function AutoUpdater() { + EventEmitter.call(this) +} - quitAndInstall() { - squirrelUpdate.processStart(); - return app.quit(); - } +require('util').inherits(AutoUpdater, EventEmitter); - setFeedURL(updateURL) { - return this.updateURL = updateURL; - } +AutoUpdater.prototype.quitAndInstall = function() { + squirrelUpdate.processStart(); + return app.quit(); +} - checkForUpdates() { - if (!this.updateURL) { - return this.emitError('Update URL is not set'); - } - if (!squirrelUpdate.supported()) { - return this.emitError('Can not find Squirrel'); - } - this.emit('checking-for-update'); - return squirrelUpdate.download(this.updateURL, (function(_this) { - return function(error, update) { +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'); + } + 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) { 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) { - return _this.emitError(error); - } - releaseNotes = update.releaseNotes, version = update.version; + releaseNotes = update.releaseNotes, version = update.version; - // Following information is not available on Windows, so fake them. - date = new Date; - return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() { - return _this.quitAndInstall(); - }); + // Following information is not available on Windows, so fake them. + date = new Date; + return _this.emit('update-downloaded', {}, releaseNotes, version, date, _this.updateURL, function() { + return _this.quitAndInstall(); }); - }; - })(this)); - } + }); + }; + })(this)); +} - // Private: Emit both error object and message, this is to keep compatibility - // with Old APIs. - emitError(message) { - return this.emit('error', new Error(message), message); - } +// Private: Emit both error object and message, this is to keep compatibility +// with Old APIs. +AutoUpdater.prototype.emitError = (message) { + return this.emit('error', new Error(message), message); } module.exports = new AutoUpdater; From 6617592224a9e57e0513e9e05ed59e8a235d67d6 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 10:01:01 -0800 Subject: [PATCH 2/4] Remove lint errors --- .../browser/api/lib/auto-updater/auto-updater-win.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/atom/browser/api/lib/auto-updater/auto-updater-win.js b/atom/browser/api/lib/auto-updater/auto-updater-win.js index 1c81763f35e..f5f2202f58d 100644 --- a/atom/browser/api/lib/auto-updater/auto-updater-win.js +++ b/atom/browser/api/lib/auto-updater/auto-updater-win.js @@ -5,7 +5,7 @@ const EventEmitter = require('events').EventEmitter; const squirrelUpdate = require('./squirrel-update-win'); function AutoUpdater() { - EventEmitter.call(this) + EventEmitter.call(this); } require('util').inherits(AutoUpdater, EventEmitter); @@ -13,11 +13,11 @@ require('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) { @@ -51,12 +51,12 @@ AutoUpdater.prototype.checkForUpdates = function() { }); }; })(this)); -} +}; // Private: Emit both error object and message, this is to keep compatibility // with Old APIs. -AutoUpdater.prototype.emitError = (message) { +AutoUpdater.prototype.emitError = function(message) { return this.emit('error', new Error(message), message); -} +}; module.exports = new AutoUpdater; From 7da4c3acf7b2ac901ef5c5ff2828cec55e434c09 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 11:00:34 -0800 Subject: [PATCH 3/4] Use const for util require --- atom/browser/api/lib/auto-updater/auto-updater-win.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atom/browser/api/lib/auto-updater/auto-updater-win.js b/atom/browser/api/lib/auto-updater/auto-updater-win.js index f5f2202f58d..1270f8f2bdb 100644 --- a/atom/browser/api/lib/auto-updater/auto-updater-win.js +++ b/atom/browser/api/lib/auto-updater/auto-updater-win.js @@ -3,12 +3,13 @@ const app = require('electron').app; const EventEmitter = require('events').EventEmitter; const squirrelUpdate = require('./squirrel-update-win'); +const util = require('util'); function AutoUpdater() { EventEmitter.call(this); } -require('util').inherits(AutoUpdater, EventEmitter); +util.inherits(AutoUpdater, EventEmitter); AutoUpdater.prototype.quitAndInstall = function() { squirrelUpdate.processStart(); From 3ab14e14e9fae0a78ff7f9e88ac7087b87ef1182 Mon Sep 17 00:00:00 2001 From: Kevin Sawicki Date: Wed, 3 Feb 2016 12:53:56 -0800 Subject: [PATCH 4/4] Add initial auto updater specs --- spec/api-auto-updater-spec.js | 34 ++++++++++++++++++++++++++++++++++ spec/static/main.js | 5 +++++ 2 files changed, 39 insertions(+) create mode 100644 spec/api-auto-updater-spec.js diff --git a/spec/api-auto-updater-spec.js b/spec/api-auto-updater-spec.js new file mode 100644 index 00000000000..72a1d90a7fe --- /dev/null +++ b/spec/api-auto-updater-spec.js @@ -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(''); + }); + }); +}); diff --git a/spec/static/main.js b/spec/static/main.js index 13d2dd6a6e1..125ef72f609 100644 --- a/spec/static/main.js +++ b/spec/static/main.js @@ -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,