mirror of
https://github.com/atom/atom.git
synced 2026-01-24 06:18:03 -05:00
Add a few more things before stepping aside to work on another issue
…maybe rebase this away…
This commit is contained in:
committed by
Ben Ogle
parent
3716aaf00b
commit
1eaf30fae9
37
spec/update-spec.js
Normal file
37
spec/update-spec.js
Normal 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)
|
||||
})
|
||||
})
|
||||
})
|
||||
})
|
||||
@@ -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)
|
||||
|
||||
@@ -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
|
||||
|
||||
|
||||
@@ -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 () {
|
||||
|
||||
Reference in New Issue
Block a user