From 4d4ee6bf3b6fe3467dc67d7427f156d99ef72ffd Mon Sep 17 00:00:00 2001 From: Antonio Scandurra Date: Thu, 31 Mar 2016 10:13:41 +0200 Subject: [PATCH] Add `applicationDelegate.getAutoUpdateManagerErrorMessage()` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sometimes, the error event gets emitted before the renderer process has the chance to subscribe. Therefore, we expose an `autoUpdateManager.getErrorMessage()` in the browser process, so that we don’t lose that information. --- spec/auto-update-manager-spec.js | 1 - src/application-delegate.coffee | 3 +++ src/auto-update-manager.js | 9 ++++++--- src/browser/atom-application.coffee | 3 +++ src/browser/auto-update-manager.coffee | 10 +++++++--- 5 files changed, 19 insertions(+), 7 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 12fe0c825..581e5e7c3 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -70,7 +70,6 @@ describe('AutoUpdateManager (renderer)', () => { autoUpdateManager.onUpdateError(spy) electronAutoUpdater.emit('error', {}, 'an error') waitsFor(() => spy.callCount === 1) - runs(() => expect(spy).toHaveBeenCalledWith('an error')) }) }) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index ecefc4b67..8bfae13fc 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -252,3 +252,6 @@ class ApplicationDelegate getAutoUpdateManagerState: -> ipcRenderer.sendSync('get-auto-update-manager-state') + + getAutoUpdateManagerErrorMessage: -> + ipcRenderer.sendSync('get-auto-update-manager-error') diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index a6cea92fe..fb6325a26 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -21,9 +21,8 @@ export default class AutoUpdateManager { applicationDelegate.onUpdateNotAvailable(() => { this.emitter.emit('update-not-available') }), - applicationDelegate.onUpdateError((message) => { - console.error(message) - this.emitter.emit('update-error', message) + applicationDelegate.onUpdateError(() => { + this.emitter.emit('update-error') }) ) } @@ -45,6 +44,10 @@ export default class AutoUpdateManager { return this.applicationDelegate.getAutoUpdateManagerState() } + getErrorMessage () { + return this.applicationDelegate.getAutoUpdateManagerErrorMessage() + } + platformSupportsUpdates () { return atom.getReleaseChannel() !== 'dev' && this.getState() !== 'unsupported' } diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 4767c9065..e58b31e10 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -311,6 +311,9 @@ class AtomApplication ipcMain.on 'get-auto-update-manager-state', (event) => event.returnValue = @autoUpdateManager.getState() + ipcMain.on 'get-auto-update-manager-error', (event) => + event.returnValue = @autoUpdateManager.getErrorMessage() + ipcMain.on 'execute-javascript-in-dev-tools', (event, code) -> event.sender.devToolsWebContents?.executeJavaScript(code) diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index 391d1f0b4..06a71698d 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -32,8 +32,8 @@ class AutoUpdateManager {autoUpdater} = require 'electron' autoUpdater.on 'error', (event, message) => - @setState(ErrorState) - @emitWindowEvent('update-error', message) + @setState(ErrorState, message) + @emitWindowEvent('update-error') console.error "Error Downloading Update: #{message}" autoUpdater.setFeedURL @feedUrl @@ -83,14 +83,18 @@ class AutoUpdateManager atomWindow.sendMessage(eventName, payload) return - setState: (state) -> + setState: (state, errorMessage) -> return if @state is state @state = state + @errorMessage = errorMessage @emit 'state-changed', @state getState: -> @state + getErrorMessage: -> + @errorMessage + scheduleUpdateCheck: -> # Only schedule update check periodically if running in release version and # and there is no existing scheduled update check.