Add a few more things before stepping aside to work on another issue

…maybe rebase this away…
This commit is contained in:
Daniel Hengeveld
2016-02-02 22:34:11 -08:00
committed by Ben Ogle
parent 3716aaf00b
commit 1eaf30fae9
4 changed files with 54 additions and 10 deletions

37
spec/update-spec.js Normal file
View File

@@ -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)
})
})
})
})

View File

@@ -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)

View File

@@ -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

View File

@@ -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 () {