mirror of
https://github.com/atom/atom.git
synced 2026-01-24 14:28:14 -05:00
Spike out an update wrapper
We can expose just a few event subscription methods on atom.update to take care of what most packages (e.g. About) would be interested in. Of course the updater runs on the main thread so we’re proxying them through IPC. It’s fine.
This commit is contained in:
committed by
Ben Ogle
parent
19623b3543
commit
3716aaf00b
@@ -182,6 +182,34 @@ class ApplicationDelegate
|
||||
new Disposable ->
|
||||
ipcRenderer.removeListener('message', outerCallback)
|
||||
|
||||
onDidBeginCheckingForUpdate: (callback) ->
|
||||
outerCallback = (message, detail) ->
|
||||
if message is 'checking-for-update'
|
||||
callback(detail)
|
||||
|
||||
ipc.on('message', outerCallback)
|
||||
new Disposable ->
|
||||
ipc.removeListener('message', outerCallback)
|
||||
|
||||
onDidCompleteDownloadingUpdate: (callback) ->
|
||||
outerCallback = (message, detail) ->
|
||||
if message is 'update-downloaded'
|
||||
callback(detail)
|
||||
|
||||
ipc.on('message', outerCallback)
|
||||
new Disposable ->
|
||||
ipc.removeListener('message', outerCallback)
|
||||
|
||||
onUpdateNotAvailable: (callback) ->
|
||||
outerCallback = (message, detail) ->
|
||||
if message is 'update-not-available'
|
||||
callback(detail)
|
||||
|
||||
ipc.on('message', outerCallback)
|
||||
new Disposable ->
|
||||
ipc.removeListener('message', outerCallback)
|
||||
|
||||
|
||||
onApplicationMenuCommand: (callback) ->
|
||||
outerCallback = (event, args...) ->
|
||||
callback(args...)
|
||||
|
||||
@@ -115,6 +115,9 @@ class AtomEnvironment extends Model
|
||||
# Public: A {TextEditorRegistry} instance
|
||||
textEditors: null
|
||||
|
||||
# Public: An {Update} instance
|
||||
update: null
|
||||
|
||||
saveStateDebounceInterval: 1000
|
||||
|
||||
###
|
||||
|
||||
@@ -39,12 +39,19 @@ class AutoUpdateManager
|
||||
|
||||
autoUpdater.on 'checking-for-update', =>
|
||||
@setState(CheckingState)
|
||||
@emitWindowEvent('checking-for-update')
|
||||
|
||||
autoUpdater.on 'update-not-available', =>
|
||||
@setState(NoUpdateAvailableState)
|
||||
|
||||
autoUpdater.on 'update-available', =>
|
||||
@setState(DownladingState)
|
||||
# We use sendMessage to send an event called 'update-available' below
|
||||
# once the update download is complete. This mismatch between the electron
|
||||
# autoUpdater events is unfortunate but in the interest of not changing the
|
||||
# one existing event handled by applicationDelegate
|
||||
@emitWindowEvent('did-begin-downloading-update')
|
||||
@emit('did-begin-download')
|
||||
|
||||
autoUpdater.on 'update-downloaded', (event, releaseNotes, @releaseVersion) =>
|
||||
@setState(UpdateAvailableState)
|
||||
@@ -66,10 +73,16 @@ class AutoUpdateManager
|
||||
|
||||
emitUpdateAvailableEvent: (windows...) ->
|
||||
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
|
||||
atomWindow.sendMessage(eventName, payload)
|
||||
return
|
||||
|
||||
setState: (state) ->
|
||||
return if @state is state
|
||||
@state = state
|
||||
@@ -93,6 +106,7 @@ class AutoUpdateManager
|
||||
@checkForUpdatesIntervalID = null
|
||||
|
||||
check: ({hidePopups}={}) ->
|
||||
console.log 'checking for update'
|
||||
unless hidePopups
|
||||
autoUpdater.once 'update-not-available', @onUpdateNotAvailable
|
||||
autoUpdater.once 'error', @onUpdateError
|
||||
|
||||
56
src/update.js
Normal file
56
src/update.js
Normal file
@@ -0,0 +1,56 @@
|
||||
'use babel'
|
||||
|
||||
import {Emitter} from 'event-kit'
|
||||
|
||||
export default class Update {
|
||||
constructor () {
|
||||
this.subscriptions = new CompositeDisposable()
|
||||
this.emitter = new Emitter()
|
||||
}
|
||||
|
||||
initialize () {
|
||||
atom.applicationDelegate.onDidBeginDownloadingUpdate(() => {
|
||||
this.emitter.emit('did-begin-downloading-update')
|
||||
})
|
||||
atom.applicationDelegate.onDidBeginCheckingForUpdate(() => {
|
||||
this.emitter.emit('did-begin-checking-for-update')
|
||||
})
|
||||
atom.applicationDelegate.onUpdateAvailable(() => {
|
||||
this.emitter.emit('did-complete-downloading-update')
|
||||
})
|
||||
}
|
||||
|
||||
dispose () {
|
||||
this.subscriptions.dispose()
|
||||
}
|
||||
|
||||
onDidBeginCheckingForUpdate (callback) {
|
||||
this.subscriptions.add(
|
||||
this.emitter.on('did-begin-checking-for-update', callback)
|
||||
)
|
||||
}
|
||||
|
||||
onDidBeginDownload (callback) {
|
||||
this.subscriptions.add(
|
||||
this.emitter.on('did-begin-downloading-update', callback)
|
||||
)
|
||||
}
|
||||
|
||||
onDidCompleteDownload (callback) {
|
||||
this.subscriptions.add(
|
||||
this.emitter.on('did-complete-downloading-update', callback)
|
||||
)
|
||||
}
|
||||
|
||||
onUpdateNotAvailable (callback) {
|
||||
this.subscriptions.add()
|
||||
}
|
||||
|
||||
check () {
|
||||
// TODO
|
||||
}
|
||||
|
||||
getState () {
|
||||
// TODO
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user