From 1eaf30fae979ecda2b6cd6e5df99d31069e01f22 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Tue, 2 Feb 2016 22:34:11 -0800 Subject: [PATCH] Add a few more things before stepping aside to work on another issue MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit …maybe rebase this away… --- spec/update-spec.js | 37 ++++++++++++++++++++++++++ src/application-delegate.coffee | 4 +-- src/browser/auto-update-manager.coffee | 11 ++++---- src/update.js | 12 +++++++-- 4 files changed, 54 insertions(+), 10 deletions(-) create mode 100644 spec/update-spec.js diff --git a/spec/update-spec.js b/spec/update-spec.js new file mode 100644 index 000000000..9e12bab48 --- /dev/null +++ b/spec/update-spec.js @@ -0,0 +1,37 @@ +'use babel' + +import Update from '../src/update' +import remote from 'remote' + +fdescribe('Update', () => { + describe('::initialize', () => { + it('subscribes to appropriate applicationDelegate events', () => { + const update = new Update() + update.initialize() + + const downloadingSpy = jasmine.createSpy('downloadingSpy') + const checkingSpy = jasmine.createSpy('checkingSpy') + const noUpdateSpy = jasmine.createSpy('noUpdateSpy') + + update.onDidBeginCheckingForUpdate(checkingSpy) + update.onDidBeginDownload(downloadingSpy) + update.onUpdateNotAvailable(noUpdateSpy) + + const webContents = remote.getCurrentWebContents() + // AutoUpdateManager sends these from main process land + webContents.send('update-available', {releaseVersion: '1.2.3'}) + webContents.send('did-begin-downloading-update') + webContents.send('checking-for-update') + webContents.send('update-not-available') + + waitsFor(() => { + noUpdateSpy.callCount > 0 + }) + runs(() => { + expect(downloadingSpy.callCount).toBe(1) + expect(checkingSpy.callCount).toBe(1) + expect(noUpdateSpy.callCount).toBe(1) + }) + }) + }) +}) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index a4262965f..8368e10ec 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -175,7 +175,7 @@ class ApplicationDelegate onUpdateAvailable: (callback) -> outerCallback = (event, message, detail) -> - if message is 'update-available' + if message is 'did-begin-downloading-update' callback(detail) ipcRenderer.on('message', outerCallback) @@ -193,7 +193,7 @@ class ApplicationDelegate onDidCompleteDownloadingUpdate: (callback) -> outerCallback = (message, detail) -> - if message is 'update-downloaded' + if message is 'update-available' callback(detail) ipc.on('message', outerCallback) diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index c58d317cb..064ccf27c 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -43,6 +43,7 @@ class AutoUpdateManager autoUpdater.on 'update-not-available', => @setState(NoUpdateAvailableState) + @emitWindowEvent('update-not-available') autoUpdater.on 'update-available', => @setState(DownladingState) @@ -55,7 +56,7 @@ class AutoUpdateManager autoUpdater.on 'update-downloaded', (event, releaseNotes, @releaseVersion) => @setState(UpdateAvailableState) - @emitUpdateAvailableEvent(@getWindows()...) + @emitUpdateAvailableEvent() @config.onDidChange 'core.automaticallyUpdate', ({newValue}) => if newValue @@ -71,15 +72,13 @@ class AutoUpdateManager when 'linux' @setState(UnsupportedState) - emitUpdateAvailableEvent: (windows...) -> + emitUpdateAvailableEvent: -> return unless @releaseVersion? @emitWindowEvent('update-available', {@releaseVersion}) - for atomWindow in windows - atomWindow.sendMessage('update-available', {@releaseVersion}) return - emitWindowEvent: (eventName, windows, payload) -> - for atomWindow in windows + emitWindowEvent: (eventName, payload) -> + for atomWindow in @getWindows() atomWindow.sendMessage(eventName, payload) return diff --git a/src/update.js b/src/update.js index fcadbc21c..4abffc0b0 100644 --- a/src/update.js +++ b/src/update.js @@ -1,6 +1,6 @@ 'use babel' -import {Emitter} from 'event-kit' +import {Emitter, CompositeDisposable} from 'event-kit' export default class Update { constructor () { @@ -42,8 +42,16 @@ export default class Update { ) } + onUpdateAvailable (callback) { + this.subscriptions.add( + this.emitter.on('update-available', callback) + ) + } + onUpdateNotAvailable (callback) { - this.subscriptions.add() + this.subscriptions.add( + this.emitter.on('update-not-available', callback) + ) } check () {