Skip to content

Commit

Permalink
Add a few more things before stepping aside to work on another issue
Browse files Browse the repository at this point in the history
…maybe rebase this away…
  • Loading branch information
thedaniel authored and benogle committed Mar 1, 2016
1 parent 3716aaf commit 1eaf30f
Show file tree
Hide file tree
Showing 4 changed files with 54 additions and 10 deletions.
37 changes: 37 additions & 0 deletions spec/update-spec.js
Original file line number Diff line number Diff line change
@@ -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)
})
})
})
})
4 changes: 2 additions & 2 deletions src/application-delegate.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
Expand Down
11 changes: 5 additions & 6 deletions src/browser/auto-update-manager.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ class AutoUpdateManager

autoUpdater.on 'update-not-available', =>
@setState(NoUpdateAvailableState)
@emitWindowEvent('update-not-available')

autoUpdater.on 'update-available', =>
@setState(DownladingState)
Expand All @@ -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
Expand All @@ -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

Expand Down
12 changes: 10 additions & 2 deletions src/update.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
'use babel'

import {Emitter} from 'event-kit'
import {Emitter, CompositeDisposable} from 'event-kit'

export default class Update {
constructor () {
Expand Down Expand Up @@ -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 () {
Expand Down

0 comments on commit 1eaf30f

Please sign in to comment.