From 3716aaf00bc080ba91a2743c69fc4bbf72e23c83 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Tue, 2 Feb 2016 11:56:05 -0800 Subject: [PATCH 01/49] Spike out an update wrapper MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- src/application-delegate.coffee | 28 +++++++++++++ src/atom-environment.coffee | 3 ++ src/browser/auto-update-manager.coffee | 14 +++++++ src/update.js | 56 ++++++++++++++++++++++++++ 4 files changed, 101 insertions(+) create mode 100644 src/update.js diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index cc1f4c946..a4262965f 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -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...) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 0ee12fe93..e6830ceaa 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -115,6 +115,9 @@ class AtomEnvironment extends Model # Public: A {TextEditorRegistry} instance textEditors: null + # Public: An {Update} instance + update: null + saveStateDebounceInterval: 1000 ### diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index 2df338761..c58d317cb 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -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 diff --git a/src/update.js b/src/update.js new file mode 100644 index 000000000..fcadbc21c --- /dev/null +++ b/src/update.js @@ -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 + } +} From 1eaf30fae979ecda2b6cd6e5df99d31069e01f22 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Tue, 2 Feb 2016 22:34:11 -0800 Subject: [PATCH 02/49] 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 () { From 6505c650089a9d63b0529000603fcf4e4a4d3473 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Wed, 3 Feb 2016 14:20:24 -0800 Subject: [PATCH 03/49] add out/ to gitignore --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index 6eec21c2a..bce6c56d3 100644 --- a/.gitignore +++ b/.gitignore @@ -15,3 +15,4 @@ debug.log docs/output docs/includes spec/fixtures/evil-files/ +out/ From 44d78327458bf65b0be90c7ec4c9bccf5ee3a385 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Wed, 3 Feb 2016 14:20:56 -0800 Subject: [PATCH 04/49] add @update to AtomEnvironment --- src/atom-environment.coffee | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index e6830ceaa..31562a392 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -41,6 +41,7 @@ TextEditor = require './text-editor' TextBuffer = require 'text-buffer' Gutter = require './gutter' TextEditorRegistry = require './text-editor-registry' +Update = require './update' WorkspaceElement = require './workspace-element' PanelContainerElement = require './panel-container-element' @@ -191,6 +192,7 @@ class AtomEnvironment extends Model @themes.workspace = @workspace @textEditors = new TextEditorRegistry + @update = new Update() @config.load() From 6fce680a2890b698eea10a056f85dc63ae0e67a3 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Wed, 3 Feb 2016 14:21:46 -0800 Subject: [PATCH 05/49] Send check-for-update message over ipc --- src/browser/atom-application.coffee | 3 +++ src/browser/auto-update-manager.coffee | 3 ++- src/update.js | 7 ++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 40b04c3a1..ebcc9717b 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -304,6 +304,9 @@ class AtomApplication ipcMain.on 'execute-javascript-in-dev-tools', (event, code) -> event.sender.devToolsWebContents?.executeJavaScript(code) + ipcMain.on 'check-for-update', => + @autoUpdateManager.check() + setupDockMenu: -> if process.platform is 'darwin' dockMenu = Menu.buildFromTemplate [ diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index 064ccf27c..c17d9aead 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -3,6 +3,7 @@ _ = require 'underscore-plus' Config = require '../config' {EventEmitter} = require 'events' path = require 'path' +ipc = require 'ipc' IdleState = 'idle' CheckingState = 'checking' @@ -47,7 +48,7 @@ class AutoUpdateManager autoUpdater.on 'update-available', => @setState(DownladingState) - # We use sendMessage to send an event called 'update-available' below + # We use sendMessage to send an event called 'update-available' in 'update-downloaded' # 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 diff --git a/src/update.js b/src/update.js index 4abffc0b0..452a3647f 100644 --- a/src/update.js +++ b/src/update.js @@ -1,6 +1,7 @@ 'use babel' import {Emitter, CompositeDisposable} from 'event-kit' +import ipc from 'ipc' export default class Update { constructor () { @@ -55,10 +56,6 @@ export default class Update { } check () { - // TODO - } - - getState () { - // TODO + ipc.send('check-for-update') } } From a8a5006950c61863ad784bbf8f0a01a98b9ea1d9 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Wed, 3 Feb 2016 14:21:56 -0800 Subject: [PATCH 06/49] Add missing subscription event --- src/application-delegate.coffee | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index 8368e10ec..f70bd7d0c 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -182,6 +182,9 @@ class ApplicationDelegate new Disposable -> ipcRenderer.removeListener('message', outerCallback) + onDidBeginDownloadingUpdate: (callback) -> + @onUpdateAvailable(callback) + onDidBeginCheckingForUpdate: (callback) -> outerCallback = (message, detail) -> if message is 'checking-for-update' From bdb9866ff1a1b1fa9411e261a43357c15159e351 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Wed, 3 Feb 2016 17:15:05 -0800 Subject: [PATCH 07/49] remove errant log statement --- src/browser/auto-update-manager.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index c17d9aead..2b6539bd8 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -106,7 +106,6 @@ class AutoUpdateManager @checkForUpdatesIntervalID = null check: ({hidePopups}={}) -> - console.log 'checking for update' unless hidePopups autoUpdater.once 'update-not-available', @onUpdateNotAvailable autoUpdater.once 'error', @onUpdateError From 6d77e97901e7b304a75afacd59fec05e75c0bb14 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Wed, 3 Feb 2016 17:32:54 -0800 Subject: [PATCH 08/49] The app delegate uses the `message` channel here. --- spec/update-spec.js | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/spec/update-spec.js b/spec/update-spec.js index 9e12bab48..8c8247538 100644 --- a/spec/update-spec.js +++ b/spec/update-spec.js @@ -18,11 +18,10 @@ fdescribe('Update', () => { 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') + webContents.send('message', 'update-available', {releaseVersion: '1.2.3'}) + webContents.send('message', 'did-begin-downloading-update') + webContents.send('message', 'checking-for-update') + webContents.send('message', 'update-not-available') waitsFor(() => { noUpdateSpy.callCount > 0 From e6a86d38d1d9a841fb7d7fffedab344fe8c4e5d2 Mon Sep 17 00:00:00 2001 From: Daniel Hengeveld Date: Fri, 5 Feb 2016 12:11:18 -0800 Subject: [PATCH 09/49] this doesn't work --- spec/update-spec.js | 1 + 1 file changed, 1 insertion(+) diff --git a/spec/update-spec.js b/spec/update-spec.js index 8c8247538..4d66da666 100644 --- a/spec/update-spec.js +++ b/spec/update-spec.js @@ -17,6 +17,7 @@ fdescribe('Update', () => { update.onDidBeginDownload(downloadingSpy) update.onUpdateNotAvailable(noUpdateSpy) + // This doesn't work const webContents = remote.getCurrentWebContents() webContents.send('message', 'update-available', {releaseVersion: '1.2.3'}) webContents.send('message', 'did-begin-downloading-update') From 004a0e870d83b3b067964890c280e1118844b5c2 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 18 Feb 2016 23:40:18 -0800 Subject: [PATCH 10/49] Add ApplicationDelegate listener disposables to subscriptions --- src/update.js | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/src/update.js b/src/update.js index 452a3647f..b4699fbec 100644 --- a/src/update.js +++ b/src/update.js @@ -10,15 +10,26 @@ export default class Update { } 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') - }) + this.subscriptions.add( + atom.applicationDelegate.onDidBeginDownloadingUpdate(() => { + this.emitter.emit('did-begin-downloading-update') + }) + ) + this.subscriptions.add( + atom.applicationDelegate.onDidBeginCheckingForUpdate(() => { + this.emitter.emit('did-begin-checking-for-update') + }) + ) + this.subscriptions.add( + atom.applicationDelegate.onDidCompleteDownloadingUpdate(() => { + this.emitter.emit('did-complete-downloading-update') + }) + ) + this.subscriptions.add( + atom.applicationDelegate.onUpdateNotAvailable(() => { + this.emitter.emit('update-not-available') + }) + ) } dispose () { From adc086d4859ed63ef031bb25caa2ec19bdfe69a8 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 18 Feb 2016 23:41:23 -0800 Subject: [PATCH 11/49] Add specs for Update methods (::check left TODO) --- spec/update-spec.js | 102 ++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 93 insertions(+), 9 deletions(-) diff --git a/spec/update-spec.js b/spec/update-spec.js index 4d66da666..0f2f66289 100644 --- a/spec/update-spec.js +++ b/spec/update-spec.js @@ -2,36 +2,120 @@ import Update from '../src/update' import remote from 'remote' +import ipc from 'ipc' fdescribe('Update', () => { + let update + + afterEach(() => { + update.dispose() + }) + describe('::initialize', () => { it('subscribes to appropriate applicationDelegate events', () => { - const update = new Update() - update.initialize() + update = new Update() const downloadingSpy = jasmine.createSpy('downloadingSpy') const checkingSpy = jasmine.createSpy('checkingSpy') const noUpdateSpy = jasmine.createSpy('noUpdateSpy') + const completedDownloadSpy = jasmine.createSpy('completedDownloadSpy') - update.onDidBeginCheckingForUpdate(checkingSpy) - update.onDidBeginDownload(downloadingSpy) - update.onUpdateNotAvailable(noUpdateSpy) + update.emitter.on('did-begin-checking-for-update', checkingSpy) + update.emitter.on('did-begin-downloading-update', downloadingSpy) + update.emitter.on('did-complete-downloading-update', completedDownloadSpy) + update.emitter.on('update-not-available', noUpdateSpy) + + update.initialize() - // This doesn't work const webContents = remote.getCurrentWebContents() - webContents.send('message', 'update-available', {releaseVersion: '1.2.3'}) - webContents.send('message', 'did-begin-downloading-update') webContents.send('message', 'checking-for-update') + webContents.send('message', 'did-begin-downloading-update') + webContents.send('message', 'update-available', {releaseVersion: '1.2.3'}) webContents.send('message', 'update-not-available') waitsFor(() => { - noUpdateSpy.callCount > 0 + return noUpdateSpy.callCount > 0 }) + runs(() => { expect(downloadingSpy.callCount).toBe(1) expect(checkingSpy.callCount).toBe(1) expect(noUpdateSpy.callCount).toBe(1) + expect(completedDownloadSpy.callCount).toBe(1) }) }) }) + + beforeEach(() => { + update = new Update() + update.initialize() + }) + + describe('::onDidBeginCheckingForUpdate', () => { + it('subscribes to "did-begin-checking-for-update" event', () => { + const spy = jasmine.createSpy('spy') + update.onDidBeginCheckingForUpdate(spy) + update.emitter.emit('did-begin-checking-for-update') + expect(spy.callCount).toBe(1) + }) + }) + + describe('::onDidBeginDownload', () => { + it('subscribes to "did-begin-downloading-update" event', () => { + const spy = jasmine.createSpy('spy') + update.onDidBeginDownload(spy) + update.emitter.emit('did-begin-downloading-update') + expect(spy.callCount).toBe(1) + }) + }) + + describe('::onDidCompleteDownload', () => { + it('subscribes to "did-complete-downloading-update" event', () => { + const spy = jasmine.createSpy('spy') + update.onDidCompleteDownload(spy) + update.emitter.emit('did-complete-downloading-update') + expect(spy.callCount).toBe(1) + }) + }) + + describe('::onUpdateNotAvailable', () => { + it('subscribes to "update-not-available" event', () => { + const spy = jasmine.createSpy('spy') + update.onUpdateNotAvailable(spy) + update.emitter.emit('update-not-available') + expect(spy.callCount).toBe(1) + }) + }) + + describe('::onUpdateAvailable', () => { + it('subscribes to "update-available" event', () => { + const spy = jasmine.createSpy('spy') + update.onUpdateAvailable(spy) + update.emitter.emit('update-available') + expect(spy.callCount).toBe(1) + }) + }) + + // TODO: spec is timing out. spy is not called + // describe('::check', () => { + // it('sends "check-for-update" event', () => { + // const spy = jasmine.createSpy('spy') + // ipc.on('check-for-update', () => { + // spy() + // }) + // update.check() + // waitsFor(() => { + // return spy.callCount > 0 + // }) + // }) + // }) + + describe('::dispose', () => { + it('disposes of subscriptions', () => { + expect(update.subscriptions.disposables).not.toBeNull() + update.dispose() + expect(update.subscriptions.disposables).toBeNull() + }) + }) + }) From 3e29cd57626945827d6930bfea5d31760184fa8a Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Thu, 18 Feb 2016 23:50:27 -0800 Subject: [PATCH 12/49] Merge branch 'master' into dh-expose-updates --- src/application-delegate.coffee | 18 +++++++++--------- src/browser/atom-application.coffee | 3 +++ 2 files changed, 12 insertions(+), 9 deletions(-) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index f70bd7d0c..2aaeb35ff 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -186,31 +186,31 @@ class ApplicationDelegate @onUpdateAvailable(callback) onDidBeginCheckingForUpdate: (callback) -> - outerCallback = (message, detail) -> + outerCallback = (event, message, detail) -> if message is 'checking-for-update' callback(detail) - ipc.on('message', outerCallback) + ipcRenderer.on('message', outerCallback) new Disposable -> - ipc.removeListener('message', outerCallback) + ipcRenderer.removeListener('message', outerCallback) onDidCompleteDownloadingUpdate: (callback) -> - outerCallback = (message, detail) -> + outerCallback = (event, message, detail) -> if message is 'update-available' callback(detail) - ipc.on('message', outerCallback) + ipcRenderer.on('message', outerCallback) new Disposable -> - ipc.removeListener('message', outerCallback) + ipcRenderer.removeListener('message', outerCallback) onUpdateNotAvailable: (callback) -> - outerCallback = (message, detail) -> + outerCallback = (event, message, detail) -> if message is 'update-not-available' callback(detail) - ipc.on('message', outerCallback) + ipcRenderer.on('message', outerCallback) new Disposable -> - ipc.removeListener('message', outerCallback) + ipcRenderer.removeListener('message', outerCallback) onApplicationMenuCommand: (callback) -> diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index ebcc9717b..fad69b967 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -307,6 +307,9 @@ class AtomApplication ipcMain.on 'check-for-update', => @autoUpdateManager.check() + ipcMain.on 'execute-javascript-in-dev-tools', (event, code) -> + event.sender.devToolsWebContents?.executeJavaScript(code) + setupDockMenu: -> if process.platform is 'darwin' dockMenu = Menu.buildFromTemplate [ From 5cda45b5c73b893e1352d099aa7e3f9e3ecb611d Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Fri, 19 Feb 2016 12:36:09 -0800 Subject: [PATCH 13/49] =?UTF-8?q?Use=20ipcRenderer=20from=20=E2=80=98elect?= =?UTF-8?q?ron=E2=80=99=20rather=20than=20=E2=80=98pic=E2=80=99=20module?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/update.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/update.js b/src/update.js index b4699fbec..5389c35e8 100644 --- a/src/update.js +++ b/src/update.js @@ -1,7 +1,7 @@ 'use babel' import {Emitter, CompositeDisposable} from 'event-kit' -import ipc from 'ipc' +import {ipcRenderer} from 'electron' export default class Update { constructor () { @@ -67,6 +67,6 @@ export default class Update { } check () { - ipc.send('check-for-update') + ipcRenderer.send('check-for-update') } } From 16ebefca3f2a7c4fa23ac0106009ca413c7541b3 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Fri, 19 Feb 2016 12:36:38 -0800 Subject: [PATCH 14/49] =?UTF-8?q?Remove=20unnecessary=20=E2=80=98ipc'=20mo?= =?UTF-8?q?dule=20import?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/browser/auto-update-manager.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/browser/auto-update-manager.coffee b/src/browser/auto-update-manager.coffee index 2b6539bd8..c8c57cb01 100644 --- a/src/browser/auto-update-manager.coffee +++ b/src/browser/auto-update-manager.coffee @@ -3,7 +3,6 @@ _ = require 'underscore-plus' Config = require '../config' {EventEmitter} = require 'events' path = require 'path' -ipc = require 'ipc' IdleState = 'idle' CheckingState = 'checking' From 19d30c7dc955b557927571fbf60038fc446e4a6d Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Fri, 19 Feb 2016 12:40:51 -0800 Subject: [PATCH 15/49] Improve specs for `Update` class --- spec/update-spec.js | 104 ++++++++++---------------------------------- 1 file changed, 23 insertions(+), 81 deletions(-) diff --git a/spec/update-spec.js b/spec/update-spec.js index 0f2f66289..bd50113c2 100644 --- a/spec/update-spec.js +++ b/spec/update-spec.js @@ -1,62 +1,29 @@ 'use babel' import Update from '../src/update' -import remote from 'remote' -import ipc from 'ipc' +import {remote} from 'electron' +const electronAutoUpdater = remote.require('electron').autoUpdater -fdescribe('Update', () => { +describe('Update', () => { let update - afterEach(() => { - update.dispose() - }) - - describe('::initialize', () => { - it('subscribes to appropriate applicationDelegate events', () => { - update = new Update() - - const downloadingSpy = jasmine.createSpy('downloadingSpy') - const checkingSpy = jasmine.createSpy('checkingSpy') - const noUpdateSpy = jasmine.createSpy('noUpdateSpy') - const completedDownloadSpy = jasmine.createSpy('completedDownloadSpy') - - update.emitter.on('did-begin-checking-for-update', checkingSpy) - update.emitter.on('did-begin-downloading-update', downloadingSpy) - update.emitter.on('did-complete-downloading-update', completedDownloadSpy) - update.emitter.on('update-not-available', noUpdateSpy) - - update.initialize() - - const webContents = remote.getCurrentWebContents() - webContents.send('message', 'checking-for-update') - webContents.send('message', 'did-begin-downloading-update') - webContents.send('message', 'update-available', {releaseVersion: '1.2.3'}) - webContents.send('message', 'update-not-available') - - waitsFor(() => { - return noUpdateSpy.callCount > 0 - }) - - runs(() => { - expect(downloadingSpy.callCount).toBe(1) - expect(checkingSpy.callCount).toBe(1) - expect(noUpdateSpy.callCount).toBe(1) - expect(completedDownloadSpy.callCount).toBe(1) - }) - }) - }) - beforeEach(() => { update = new Update() update.initialize() }) + afterEach(() => { + update.dispose() + }) + describe('::onDidBeginCheckingForUpdate', () => { it('subscribes to "did-begin-checking-for-update" event', () => { const spy = jasmine.createSpy('spy') update.onDidBeginCheckingForUpdate(spy) - update.emitter.emit('did-begin-checking-for-update') - expect(spy.callCount).toBe(1) + electronAutoUpdater.emit('checking-for-update') + waitsFor(() => { + return spy.callCount === 1 + }) }) }) @@ -64,8 +31,10 @@ fdescribe('Update', () => { it('subscribes to "did-begin-downloading-update" event', () => { const spy = jasmine.createSpy('spy') update.onDidBeginDownload(spy) - update.emitter.emit('did-begin-downloading-update') - expect(spy.callCount).toBe(1) + electronAutoUpdater.emit('update-available') + waitsFor(() => { + return spy.callCount === 1 + }) }) }) @@ -73,8 +42,10 @@ fdescribe('Update', () => { it('subscribes to "did-complete-downloading-update" event', () => { const spy = jasmine.createSpy('spy') update.onDidCompleteDownload(spy) - update.emitter.emit('did-complete-downloading-update') - expect(spy.callCount).toBe(1) + electronAutoUpdater.emit('update-downloaded', null, null, {releaseVersion: '1.2.3'}) + waitsFor(() => { + return spy.callCount === 1 + }) }) }) @@ -82,39 +53,10 @@ fdescribe('Update', () => { it('subscribes to "update-not-available" event', () => { const spy = jasmine.createSpy('spy') update.onUpdateNotAvailable(spy) - update.emitter.emit('update-not-available') - expect(spy.callCount).toBe(1) - }) - }) - - describe('::onUpdateAvailable', () => { - it('subscribes to "update-available" event', () => { - const spy = jasmine.createSpy('spy') - update.onUpdateAvailable(spy) - update.emitter.emit('update-available') - expect(spy.callCount).toBe(1) - }) - }) - - // TODO: spec is timing out. spy is not called - // describe('::check', () => { - // it('sends "check-for-update" event', () => { - // const spy = jasmine.createSpy('spy') - // ipc.on('check-for-update', () => { - // spy() - // }) - // update.check() - // waitsFor(() => { - // return spy.callCount > 0 - // }) - // }) - // }) - - describe('::dispose', () => { - it('disposes of subscriptions', () => { - expect(update.subscriptions.disposables).not.toBeNull() - update.dispose() - expect(update.subscriptions.disposables).toBeNull() + electronAutoUpdater.emit('update-not-available') + waitsFor(() => { + return spy.callCount === 1 + }) }) }) From dd53c6f85644701cd0c6b61e7cfca5c69d098df0 Mon Sep 17 00:00:00 2001 From: Katrina Uychaco Date: Fri, 19 Feb 2016 15:35:42 -0800 Subject: [PATCH 16/49] Use `onDidCompleteDownloadingUpdate` in `listenForUpdates` MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This gets a bit confusing… It was formerly `@applicationDelegate.onUpdateAvailable`, but `::onUpdateAvailable` listens for the `did-begin-downloading-update` event and `::onDidCompleteDownloadingUpdate` listens for the `update-available` event. Note that ‘available’ here means successfully downloaded and ready to be used and NOT available to be downloaded. --- src/atom-environment.coffee | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 31562a392..b9527b947 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -891,7 +891,8 @@ class AtomEnvironment extends Model @emitter.emit 'update-available', details listenForUpdates: -> - @disposables.add(@applicationDelegate.onUpdateAvailable(@updateAvailable.bind(this))) + # listen for updates available locally (that have been successfully downloaded) + @disposables.add(@applicationDelegate.onDidCompleteDownloadingUpdate(@updateAvailable.bind(this))) setBodyPlatformClass: -> @document.body.classList.add("platform-#{process.platform}") From 342f72b6a14a8bd7280133e034ab8fc07e1b3257 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:07:11 -0800 Subject: [PATCH 17/49] Rename `Update` `AutoUpdateManager` --- ...te-spec.js => auto-update-manager-spec.js} | 21 +++++++++---------- src/atom-environment.coffee | 8 +++---- src/{update.js => auto-update-manager.js} | 2 +- 3 files changed, 15 insertions(+), 16 deletions(-) rename spec/{update-spec.js => auto-update-manager-spec.js} (75%) rename src/{update.js => auto-update-manager.js} (97%) diff --git a/spec/update-spec.js b/spec/auto-update-manager-spec.js similarity index 75% rename from spec/update-spec.js rename to spec/auto-update-manager-spec.js index bd50113c2..b78830c33 100644 --- a/spec/update-spec.js +++ b/spec/auto-update-manager-spec.js @@ -1,25 +1,25 @@ 'use babel' -import Update from '../src/update' +import AutoUpdateManager from '../src/auto-update-manager' import {remote} from 'electron' const electronAutoUpdater = remote.require('electron').autoUpdater -describe('Update', () => { - let update +fdescribe('AutoUpdateManager (renderer)', () => { + let autoUpdateManager beforeEach(() => { - update = new Update() - update.initialize() + autoUpdateManager = new AutoUpdateManager() + autoUpdateManager.initialize() }) afterEach(() => { - update.dispose() + autoUpdateManager.dispose() }) describe('::onDidBeginCheckingForUpdate', () => { it('subscribes to "did-begin-checking-for-update" event', () => { const spy = jasmine.createSpy('spy') - update.onDidBeginCheckingForUpdate(spy) + autoUpdateManager.onDidBeginCheckingForUpdate(spy) electronAutoUpdater.emit('checking-for-update') waitsFor(() => { return spy.callCount === 1 @@ -30,7 +30,7 @@ describe('Update', () => { describe('::onDidBeginDownload', () => { it('subscribes to "did-begin-downloading-update" event', () => { const spy = jasmine.createSpy('spy') - update.onDidBeginDownload(spy) + autoUpdateManager.onDidBeginDownload(spy) electronAutoUpdater.emit('update-available') waitsFor(() => { return spy.callCount === 1 @@ -41,7 +41,7 @@ describe('Update', () => { describe('::onDidCompleteDownload', () => { it('subscribes to "did-complete-downloading-update" event', () => { const spy = jasmine.createSpy('spy') - update.onDidCompleteDownload(spy) + autoUpdateManager.onDidCompleteDownload(spy) electronAutoUpdater.emit('update-downloaded', null, null, {releaseVersion: '1.2.3'}) waitsFor(() => { return spy.callCount === 1 @@ -52,12 +52,11 @@ describe('Update', () => { describe('::onUpdateNotAvailable', () => { it('subscribes to "update-not-available" event', () => { const spy = jasmine.createSpy('spy') - update.onUpdateNotAvailable(spy) + autoUpdateManager.onUpdateNotAvailable(spy) electronAutoUpdater.emit('update-not-available') waitsFor(() => { return spy.callCount === 1 }) }) }) - }) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index b9527b947..4fead0da9 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -41,7 +41,7 @@ TextEditor = require './text-editor' TextBuffer = require 'text-buffer' Gutter = require './gutter' TextEditorRegistry = require './text-editor-registry' -Update = require './update' +AutoUpdateManager = require './auto-update-manager' WorkspaceElement = require './workspace-element' PanelContainerElement = require './panel-container-element' @@ -116,8 +116,8 @@ class AtomEnvironment extends Model # Public: A {TextEditorRegistry} instance textEditors: null - # Public: An {Update} instance - update: null + # Public: An {AutoUpdateManager} instance + autoUpdater: null saveStateDebounceInterval: 1000 @@ -192,7 +192,7 @@ class AtomEnvironment extends Model @themes.workspace = @workspace @textEditors = new TextEditorRegistry - @update = new Update() + @autoUpdater = new AutoUpdateManager @config.load() diff --git a/src/update.js b/src/auto-update-manager.js similarity index 97% rename from src/update.js rename to src/auto-update-manager.js index 5389c35e8..1f0f39f29 100644 --- a/src/update.js +++ b/src/auto-update-manager.js @@ -3,7 +3,7 @@ import {Emitter, CompositeDisposable} from 'event-kit' import {ipcRenderer} from 'electron' -export default class Update { +export default class AutoUpdateManager { constructor () { this.subscriptions = new CompositeDisposable() this.emitter = new Emitter() From e40c91d3538e512004e058b8c21bd53994a36a69 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:08:59 -0800 Subject: [PATCH 18/49] All subscriptions can be in one call --- src/auto-update-manager.js | 12 +++--------- 1 file changed, 3 insertions(+), 9 deletions(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 1f0f39f29..006eadf9e 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -13,19 +13,13 @@ export default class AutoUpdateManager { this.subscriptions.add( atom.applicationDelegate.onDidBeginDownloadingUpdate(() => { this.emitter.emit('did-begin-downloading-update') - }) - ) - this.subscriptions.add( + }), atom.applicationDelegate.onDidBeginCheckingForUpdate(() => { this.emitter.emit('did-begin-checking-for-update') - }) - ) - this.subscriptions.add( + }), atom.applicationDelegate.onDidCompleteDownloadingUpdate(() => { this.emitter.emit('did-complete-downloading-update') - }) - ) - this.subscriptions.add( + }), atom.applicationDelegate.onUpdateNotAvailable(() => { this.emitter.emit('update-not-available') }) From ddff53bfc56b373c479c4c50c1f4dde6a04c80d7 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:10:56 -0800 Subject: [PATCH 19/49] Postfix ifs --- src/application-delegate.coffee | 16 +++++----------- 1 file changed, 5 insertions(+), 11 deletions(-) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index 2aaeb35ff..a853cd8ea 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -166,8 +166,7 @@ class ApplicationDelegate onDidOpenLocations: (callback) -> outerCallback = (event, message, detail) -> - if message is 'open-locations' - callback(detail) + callback(detail) if message is 'open-locations' ipcRenderer.on('message', outerCallback) new Disposable -> @@ -175,8 +174,7 @@ class ApplicationDelegate onUpdateAvailable: (callback) -> outerCallback = (event, message, detail) -> - if message is 'did-begin-downloading-update' - callback(detail) + callback(detail) if message is 'did-begin-downloading-update' ipcRenderer.on('message', outerCallback) new Disposable -> @@ -187,8 +185,7 @@ class ApplicationDelegate onDidBeginCheckingForUpdate: (callback) -> outerCallback = (event, message, detail) -> - if message is 'checking-for-update' - callback(detail) + callback(detail) if message is 'checking-for-update' ipcRenderer.on('message', outerCallback) new Disposable -> @@ -196,8 +193,7 @@ class ApplicationDelegate onDidCompleteDownloadingUpdate: (callback) -> outerCallback = (event, message, detail) -> - if message is 'update-available' - callback(detail) + callback(detail) if message is 'update-available' ipcRenderer.on('message', outerCallback) new Disposable -> @@ -205,14 +201,12 @@ class ApplicationDelegate onUpdateNotAvailable: (callback) -> outerCallback = (event, message, detail) -> - if message is 'update-not-available' - callback(detail) + callback(detail) if message is 'update-not-available' ipcRenderer.on('message', outerCallback) new Disposable -> ipcRenderer.removeListener('message', outerCallback) - onApplicationMenuCommand: (callback) -> outerCallback = (event, args...) -> callback(args...) From b481a06cbfb7628d31c3690e9429961da2867e9a Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:14:05 -0800 Subject: [PATCH 20/49] Pass the app delegate into AutoUpdateManager --- spec/auto-update-manager-spec.js | 2 +- src/atom-environment.coffee | 1 + src/auto-update-manager.js | 10 +++++----- 3 files changed, 7 insertions(+), 6 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index b78830c33..93df903de 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -9,7 +9,7 @@ fdescribe('AutoUpdateManager (renderer)', () => { beforeEach(() => { autoUpdateManager = new AutoUpdateManager() - autoUpdateManager.initialize() + autoUpdateManager.initialize(atom.applicationDelegate) }) afterEach(() => { diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 4fead0da9..e492c7067 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -193,6 +193,7 @@ class AtomEnvironment extends Model @textEditors = new TextEditorRegistry @autoUpdater = new AutoUpdateManager + @autoUpdater.initialize(@applicationDelegate) @config.load() diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 006eadf9e..c0f0b39bb 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -9,18 +9,18 @@ export default class AutoUpdateManager { this.emitter = new Emitter() } - initialize () { + initialize (updateEventEmitter) { this.subscriptions.add( - atom.applicationDelegate.onDidBeginDownloadingUpdate(() => { + updateEventEmitter.onDidBeginDownloadingUpdate(() => { this.emitter.emit('did-begin-downloading-update') }), - atom.applicationDelegate.onDidBeginCheckingForUpdate(() => { + updateEventEmitter.onDidBeginCheckingForUpdate(() => { this.emitter.emit('did-begin-checking-for-update') }), - atom.applicationDelegate.onDidCompleteDownloadingUpdate(() => { + updateEventEmitter.onDidCompleteDownloadingUpdate(() => { this.emitter.emit('did-complete-downloading-update') }), - atom.applicationDelegate.onUpdateNotAvailable(() => { + updateEventEmitter.onUpdateNotAvailable(() => { this.emitter.emit('update-not-available') }) ) From a876e85899cd2ebb4056d356ae5dc22866f561b8 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:14:52 -0800 Subject: [PATCH 21/49] check -> checkForUpdate --- src/auto-update-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index c0f0b39bb..05de08a3a 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -60,7 +60,7 @@ export default class AutoUpdateManager { ) } - check () { + checkForUpdate () { ipcRenderer.send('check-for-update') } } From eaba6943194153c55ad753e5e6137f8f64a254bd Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:14:59 -0800 Subject: [PATCH 22/49] =?UTF-8?q?Let=E2=80=99s=20make=20this=20private=20f?= =?UTF-8?q?or=20now?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/atom-environment.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index e492c7067..481e762ca 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -116,7 +116,7 @@ class AtomEnvironment extends Model # Public: A {TextEditorRegistry} instance textEditors: null - # Public: An {AutoUpdateManager} instance + # Private: An {AutoUpdateManager} instance autoUpdater: null saveStateDebounceInterval: 1000 From 3a5c8271629f6ebd9d4b03779f3b019d1bad5bc9 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:23:11 -0800 Subject: [PATCH 23/49] Add dispose spec --- spec/auto-update-manager-spec.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 93df903de..6aa791373 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -59,4 +59,29 @@ fdescribe('AutoUpdateManager (renderer)', () => { }) }) }) + + describe('::dispose', () => { + it('subscribes to "update-not-available" event', () => { + const spy = jasmine.createSpy('spy') + const doneIndicator = jasmine.createSpy('spy') + atom.applicationDelegate.onUpdateNotAvailable(doneIndicator) + autoUpdateManager.dispose() + autoUpdateManager.onDidBeginCheckingForUpdate(spy) + autoUpdateManager.onDidBeginDownload(spy) + autoUpdateManager.onDidCompleteDownload(spy) + autoUpdateManager.onUpdateNotAvailable(spy) + electronAutoUpdater.emit('checking-for-update') + electronAutoUpdater.emit('update-available') + electronAutoUpdater.emit('update-downloaded', null, null, {releaseVersion: '1.2.3'}) + electronAutoUpdater.emit('update-not-available') + + waitsFor(() => { + return doneIndicator.callCount === 1 + }) + + runs(() => { + expect(spy.callCount).toBe(0) + }) + }) + }) }) From c9293e7733502c0551438a41633031c902ab43c6 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:34:31 -0800 Subject: [PATCH 24/49] Pass the version info through the event --- spec/auto-update-manager-spec.js | 7 +++++-- src/auto-update-manager.js | 4 ++-- 2 files changed, 7 insertions(+), 4 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 6aa791373..e23c1911d 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -42,10 +42,13 @@ fdescribe('AutoUpdateManager (renderer)', () => { it('subscribes to "did-complete-downloading-update" event', () => { const spy = jasmine.createSpy('spy') autoUpdateManager.onDidCompleteDownload(spy) - electronAutoUpdater.emit('update-downloaded', null, null, {releaseVersion: '1.2.3'}) + electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3') waitsFor(() => { return spy.callCount === 1 }) + runs(() => { + expect(spy.mostRecentCall.args[0].releaseVersion).toBe('1.2.3') + }) }) }) @@ -72,7 +75,7 @@ fdescribe('AutoUpdateManager (renderer)', () => { autoUpdateManager.onUpdateNotAvailable(spy) electronAutoUpdater.emit('checking-for-update') electronAutoUpdater.emit('update-available') - electronAutoUpdater.emit('update-downloaded', null, null, {releaseVersion: '1.2.3'}) + electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3') electronAutoUpdater.emit('update-not-available') waitsFor(() => { diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 05de08a3a..f46197f8d 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -17,8 +17,8 @@ export default class AutoUpdateManager { updateEventEmitter.onDidBeginCheckingForUpdate(() => { this.emitter.emit('did-begin-checking-for-update') }), - updateEventEmitter.onDidCompleteDownloadingUpdate(() => { - this.emitter.emit('did-complete-downloading-update') + updateEventEmitter.onDidCompleteDownloadingUpdate((details) => { + this.emitter.emit('did-complete-downloading-update', details) }), updateEventEmitter.onUpdateNotAvailable(() => { this.emitter.emit('update-not-available') From fa0f6f35258b5cbb9fb347c2858ee0ab258d1df5 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:35:35 -0800 Subject: [PATCH 25/49] =?UTF-8?q?Use=20the=20renderer=20AutoUpdateManager?= =?UTF-8?q?=20in=20atom-environment=E2=80=99s=20update=20events?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/atom-environment.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 481e762ca..f1fe1b459 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -893,7 +893,7 @@ class AtomEnvironment extends Model listenForUpdates: -> # listen for updates available locally (that have been successfully downloaded) - @disposables.add(@applicationDelegate.onDidCompleteDownloadingUpdate(@updateAvailable.bind(this))) + @disposables.add(@autoUpdater.onDidCompleteDownload(@updateAvailable.bind(this))) setBodyPlatformClass: -> @document.body.classList.add("platform-#{process.platform}") From 341abbfc261d2b9206cf2d85cdd7bf147d4760cd Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:35:50 -0800 Subject: [PATCH 26/49] Nof. Nope. --- spec/auto-update-manager-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index e23c1911d..ff2fc0682 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -4,7 +4,7 @@ import AutoUpdateManager from '../src/auto-update-manager' import {remote} from 'electron' const electronAutoUpdater = remote.require('electron').autoUpdater -fdescribe('AutoUpdateManager (renderer)', () => { +describe('AutoUpdateManager (renderer)', () => { let autoUpdateManager beforeEach(() => { From e9e372b69e42d0ab8659bc3e446e6df57ce987a0 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:48:15 -0800 Subject: [PATCH 27/49] Dispose emitter --- spec/auto-update-manager-spec.js | 2 +- src/auto-update-manager.js | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index ff2fc0682..f4e7622b2 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -68,11 +68,11 @@ describe('AutoUpdateManager (renderer)', () => { const spy = jasmine.createSpy('spy') const doneIndicator = jasmine.createSpy('spy') atom.applicationDelegate.onUpdateNotAvailable(doneIndicator) - autoUpdateManager.dispose() autoUpdateManager.onDidBeginCheckingForUpdate(spy) autoUpdateManager.onDidBeginDownload(spy) autoUpdateManager.onDidCompleteDownload(spy) autoUpdateManager.onUpdateNotAvailable(spy) + autoUpdateManager.dispose() electronAutoUpdater.emit('checking-for-update') electronAutoUpdater.emit('update-available') electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3') diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index f46197f8d..681978cb6 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -28,6 +28,7 @@ export default class AutoUpdateManager { dispose () { this.subscriptions.dispose() + this.emitter.dispose() } onDidBeginCheckingForUpdate (callback) { From 4afe6df2c4edc8a4bfc8b5db07ee27a88f7df908 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:48:26 -0800 Subject: [PATCH 28/49] Reorder for consistency --- src/auto-update-manager.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 681978cb6..5f37196ed 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -11,12 +11,12 @@ export default class AutoUpdateManager { initialize (updateEventEmitter) { this.subscriptions.add( - updateEventEmitter.onDidBeginDownloadingUpdate(() => { - this.emitter.emit('did-begin-downloading-update') - }), updateEventEmitter.onDidBeginCheckingForUpdate(() => { this.emitter.emit('did-begin-checking-for-update') }), + updateEventEmitter.onDidBeginDownloadingUpdate(() => { + this.emitter.emit('did-begin-downloading-update') + }), updateEventEmitter.onDidCompleteDownloadingUpdate((details) => { this.emitter.emit('did-complete-downloading-update', details) }), From b60e1957a88c0a9c2585434f94cbeadc9a51f3b6 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 17:48:43 -0800 Subject: [PATCH 29/49] Return the disposables! --- src/auto-update-manager.js | 20 +++++--------------- 1 file changed, 5 insertions(+), 15 deletions(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 5f37196ed..0bb793b44 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -32,33 +32,23 @@ export default class AutoUpdateManager { } onDidBeginCheckingForUpdate (callback) { - this.subscriptions.add( - this.emitter.on('did-begin-checking-for-update', callback) - ) + return this.emitter.on('did-begin-checking-for-update', callback) } onDidBeginDownload (callback) { - this.subscriptions.add( - this.emitter.on('did-begin-downloading-update', callback) - ) + return this.emitter.on('did-begin-downloading-update', callback) } onDidCompleteDownload (callback) { - this.subscriptions.add( - this.emitter.on('did-complete-downloading-update', callback) - ) + return this.emitter.on('did-complete-downloading-update', callback) } onUpdateAvailable (callback) { - this.subscriptions.add( - this.emitter.on('update-available', callback) - ) + return this.emitter.on('update-available', callback) } onUpdateNotAvailable (callback) { - this.subscriptions.add( - this.emitter.on('update-not-available', callback) - ) + return this.emitter.on('update-not-available', callback) } checkForUpdate () { From d3340d070f456c6e181da7e38624cc5af9d3f062 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 23 Feb 2016 18:12:04 -0800 Subject: [PATCH 30/49] =?UTF-8?q?UpdateAvailable=20isn=E2=80=99t=20really?= =?UTF-8?q?=20a=20thing=20in=20this=20world?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/auto-update-manager.js | 4 ---- 1 file changed, 4 deletions(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 0bb793b44..cc3035fdf 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -43,10 +43,6 @@ export default class AutoUpdateManager { return this.emitter.on('did-complete-downloading-update', callback) } - onUpdateAvailable (callback) { - return this.emitter.on('update-available', callback) - } - onUpdateNotAvailable (callback) { return this.emitter.on('update-not-available', callback) } From e477751c1986743882d551d54fa3d2b99bd189a0 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Feb 2016 16:00:48 -0800 Subject: [PATCH 31/49] Make the autoupdater functions consistently names --- spec/auto-update-manager-spec.js | 12 ++++++------ src/auto-update-manager.js | 4 ++-- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index f4e7622b2..499e2cb3b 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -27,10 +27,10 @@ describe('AutoUpdateManager (renderer)', () => { }) }) - describe('::onDidBeginDownload', () => { + describe('::onDidBeginDownloadingUpdate', () => { it('subscribes to "did-begin-downloading-update" event', () => { const spy = jasmine.createSpy('spy') - autoUpdateManager.onDidBeginDownload(spy) + autoUpdateManager.onDidBeginDownloadingUpdate(spy) electronAutoUpdater.emit('update-available') waitsFor(() => { return spy.callCount === 1 @@ -38,10 +38,10 @@ describe('AutoUpdateManager (renderer)', () => { }) }) - describe('::onDidCompleteDownload', () => { + describe('::onDidCompleteDownloadingUpdate', () => { it('subscribes to "did-complete-downloading-update" event', () => { const spy = jasmine.createSpy('spy') - autoUpdateManager.onDidCompleteDownload(spy) + autoUpdateManager.onDidCompleteDownloadingUpdate(spy) electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3') waitsFor(() => { return spy.callCount === 1 @@ -69,8 +69,8 @@ describe('AutoUpdateManager (renderer)', () => { const doneIndicator = jasmine.createSpy('spy') atom.applicationDelegate.onUpdateNotAvailable(doneIndicator) autoUpdateManager.onDidBeginCheckingForUpdate(spy) - autoUpdateManager.onDidBeginDownload(spy) - autoUpdateManager.onDidCompleteDownload(spy) + autoUpdateManager.onDidBeginDownloadingUpdate(spy) + autoUpdateManager.onDidCompleteDownloadingUpdate(spy) autoUpdateManager.onUpdateNotAvailable(spy) autoUpdateManager.dispose() electronAutoUpdater.emit('checking-for-update') diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index cc3035fdf..e7852f2d9 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -35,11 +35,11 @@ export default class AutoUpdateManager { return this.emitter.on('did-begin-checking-for-update', callback) } - onDidBeginDownload (callback) { + onDidBeginDownloadingUpdate (callback) { return this.emitter.on('did-begin-downloading-update', callback) } - onDidCompleteDownload (callback) { + onDidCompleteDownloadingUpdate (callback) { return this.emitter.on('did-complete-downloading-update', callback) } From c19296efb753167619a66532ecb6481339415b9d Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Feb 2016 16:01:23 -0800 Subject: [PATCH 32/49] Add isEnabled function to AutoUpdateManager --- spec/auto-update-manager-spec.js | 32 ++++++++++++++++++++++++++++++++ src/auto-update-manager.js | 27 +++++++++++++++++++++++++-- 2 files changed, 57 insertions(+), 2 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 499e2cb3b..6e3c037ef 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -63,6 +63,38 @@ describe('AutoUpdateManager (renderer)', () => { }) }) + describe('::isEnabled', () => { + let platform, releaseChannel + it('returns true on OS X and Windows, when in stable', () => { + spyOn(autoUpdateManager, 'getPlatform').andCallFake(() => platform) + spyOn(autoUpdateManager, 'getReleaseChannel').andCallFake(() => releaseChannel) + + platform = 'win32' + releaseChannel = 'stable' + expect(autoUpdateManager.isEnabled()).toBe(true) + + platform = 'win32' + releaseChannel = 'dev' + expect(autoUpdateManager.isEnabled()).toBe(false) + + platform = 'darwin' + releaseChannel = 'stable' + expect(autoUpdateManager.isEnabled()).toBe(true) + + platform = 'darwin' + releaseChannel = 'dev' + expect(autoUpdateManager.isEnabled()).toBe(false) + + platform = 'linux' + releaseChannel = 'stable' + expect(autoUpdateManager.isEnabled()).toBe(false) + + platform = 'linux' + releaseChannel = 'dev' + expect(autoUpdateManager.isEnabled()).toBe(false) + }) + }) + describe('::dispose', () => { it('subscribes to "update-not-available" event', () => { const spy = jasmine.createSpy('spy') diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index e7852f2d9..e99ce83d9 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -31,6 +31,18 @@ export default class AutoUpdateManager { this.emitter.dispose() } + checkForUpdate () { + ipcRenderer.send('check-for-update') + } + + quitAndInstallUpdate () { + ipcRenderer.send('install-update') + } + + isEnabled () { + return this.getReleaseChannel() == 'stable' && (this.getPlatform() === 'darwin' || this.getPlatform() === 'win32') + } + onDidBeginCheckingForUpdate (callback) { return this.emitter.on('did-begin-checking-for-update', callback) } @@ -47,7 +59,18 @@ export default class AutoUpdateManager { return this.emitter.on('update-not-available', callback) } - checkForUpdate () { - ipcRenderer.send('check-for-update') + getPlatform () { + return process.platform + } + + // TODO: We should move this into atom env or something. + getReleaseChannel () { + let version = atom.getVersion() + if (version.indexOf('beta') > -1) { + return 'beta' + } else if (version.indexOf('dev') > -1) { + return 'dev' + } + return 'stable' } } From 1cd530cdf06e4865a91f159fffc0e687ff78610c Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Feb 2016 16:01:44 -0800 Subject: [PATCH 33/49] Add some todo code --- src/auto-update-manager.js | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index e99ce83d9..06b437c3b 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -55,6 +55,12 @@ export default class AutoUpdateManager { return this.emitter.on('did-complete-downloading-update', callback) } + // TODO: When https://github.com/atom/electron/issues/4587 is closed, we can + // add an update-available event. + // onUpdateAvailable (callback) { + // return this.emitter.on('update-available', callback) + // } + onUpdateNotAvailable (callback) { return this.emitter.on('update-not-available', callback) } From 418b1bd8f1bb95c79620d9847518aa33abdb4142 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Feb 2016 16:33:39 -0800 Subject: [PATCH 34/49] Get rid of the initialize method --- spec/auto-update-manager-spec.js | 5 +++-- src/atom-environment.coffee | 3 +-- src/auto-update-manager.js | 12 +++++------- 3 files changed, 9 insertions(+), 11 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 6e3c037ef..2b51ed658 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -8,8 +8,9 @@ describe('AutoUpdateManager (renderer)', () => { let autoUpdateManager beforeEach(() => { - autoUpdateManager = new AutoUpdateManager() - autoUpdateManager.initialize(atom.applicationDelegate) + autoUpdateManager = new AutoUpdateManager({ + applicationDelegate: atom.applicationDelegate + }) }) afterEach(() => { diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index f1fe1b459..04074cfcb 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -192,8 +192,7 @@ class AtomEnvironment extends Model @themes.workspace = @workspace @textEditors = new TextEditorRegistry - @autoUpdater = new AutoUpdateManager - @autoUpdater.initialize(@applicationDelegate) + @autoUpdater = new AutoUpdateManager({@applicationDelegate}) @config.load() diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 06b437c3b..d811996c1 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -4,23 +4,21 @@ import {Emitter, CompositeDisposable} from 'event-kit' import {ipcRenderer} from 'electron' export default class AutoUpdateManager { - constructor () { + constructor ({applicationDelegate}) { this.subscriptions = new CompositeDisposable() this.emitter = new Emitter() - } - initialize (updateEventEmitter) { this.subscriptions.add( - updateEventEmitter.onDidBeginCheckingForUpdate(() => { + applicationDelegate.onDidBeginCheckingForUpdate(() => { this.emitter.emit('did-begin-checking-for-update') }), - updateEventEmitter.onDidBeginDownloadingUpdate(() => { + applicationDelegate.onDidBeginDownloadingUpdate(() => { this.emitter.emit('did-begin-downloading-update') }), - updateEventEmitter.onDidCompleteDownloadingUpdate((details) => { + applicationDelegate.onDidCompleteDownloadingUpdate((details) => { this.emitter.emit('did-complete-downloading-update', details) }), - updateEventEmitter.onUpdateNotAvailable(() => { + applicationDelegate.onUpdateNotAvailable(() => { this.emitter.emit('update-not-available') }) ) From bc138f727e1af484f0110661eafafae6f4861e95 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Feb 2016 16:33:51 -0800 Subject: [PATCH 35/49] Fix usage of the onDidCompleteDownload() method --- src/atom-environment.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 04074cfcb..2122abbbe 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -892,7 +892,7 @@ class AtomEnvironment extends Model listenForUpdates: -> # listen for updates available locally (that have been successfully downloaded) - @disposables.add(@autoUpdater.onDidCompleteDownload(@updateAvailable.bind(this))) + @disposables.add(@autoUpdater.onDidCompleteDownloadingUpdate(@updateAvailable.bind(this))) setBodyPlatformClass: -> @document.body.classList.add("platform-#{process.platform}") From 68951494d2e6c4becfa44be38d90a49f79f7c3b9 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Thu, 25 Feb 2016 17:32:02 -0800 Subject: [PATCH 36/49] isEnabled -> platformSupportsUpdates --- spec/auto-update-manager-spec.js | 14 +++++++------- src/auto-update-manager.js | 2 +- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 2b51ed658..e12f85c5b 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -64,7 +64,7 @@ describe('AutoUpdateManager (renderer)', () => { }) }) - describe('::isEnabled', () => { + describe('::platformSupportsUpdates', () => { let platform, releaseChannel it('returns true on OS X and Windows, when in stable', () => { spyOn(autoUpdateManager, 'getPlatform').andCallFake(() => platform) @@ -72,27 +72,27 @@ describe('AutoUpdateManager (renderer)', () => { platform = 'win32' releaseChannel = 'stable' - expect(autoUpdateManager.isEnabled()).toBe(true) + expect(autoUpdateManager.platformSupportsUpdates()).toBe(true) platform = 'win32' releaseChannel = 'dev' - expect(autoUpdateManager.isEnabled()).toBe(false) + expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) platform = 'darwin' releaseChannel = 'stable' - expect(autoUpdateManager.isEnabled()).toBe(true) + expect(autoUpdateManager.platformSupportsUpdates()).toBe(true) platform = 'darwin' releaseChannel = 'dev' - expect(autoUpdateManager.isEnabled()).toBe(false) + expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) platform = 'linux' releaseChannel = 'stable' - expect(autoUpdateManager.isEnabled()).toBe(false) + expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) platform = 'linux' releaseChannel = 'dev' - expect(autoUpdateManager.isEnabled()).toBe(false) + expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) }) }) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index d811996c1..497097864 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -37,7 +37,7 @@ export default class AutoUpdateManager { ipcRenderer.send('install-update') } - isEnabled () { + platformSupportsUpdates () { return this.getReleaseChannel() == 'stable' && (this.getPlatform() === 'darwin' || this.getPlatform() === 'win32') } From 7a1ad8263aa63438df16247663cf99e5073d4d72 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Fri, 26 Feb 2016 16:37:59 -0800 Subject: [PATCH 37/49] Rename `quitAndInstallUpdate` to `restartAndInstallUpdate` --- src/auto-update-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 497097864..eae979d9d 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -33,7 +33,7 @@ export default class AutoUpdateManager { ipcRenderer.send('check-for-update') } - quitAndInstallUpdate () { + restartAndInstallUpdate () { ipcRenderer.send('install-update') } From 3a32b30d5a98f704a310c96fa1d7bc8309d7d412 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Fri, 26 Feb 2016 16:38:56 -0800 Subject: [PATCH 38/49] Add mechanism to get the AutoUpdateManager's state --- src/auto-update-manager.js | 4 ++++ src/browser/atom-application.coffee | 3 +++ 2 files changed, 7 insertions(+) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index eae979d9d..14ec44c29 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -37,6 +37,10 @@ export default class AutoUpdateManager { ipcRenderer.send('install-update') } + getState () { + return ipcRenderer.sendSync('get-auto-update-manager-state') + } + platformSupportsUpdates () { return this.getReleaseChannel() == 'stable' && (this.getPlatform() === 'darwin' || this.getPlatform() === 'win32') } diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index fad69b967..fdfea5474 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -307,6 +307,9 @@ class AtomApplication ipcMain.on 'check-for-update', => @autoUpdateManager.check() + ipcMain.on 'get-auto-update-manager-state', (event) => + event.returnValue = @autoUpdateManager.getState() + ipcMain.on 'execute-javascript-in-dev-tools', (event, code) -> event.sender.devToolsWebContents?.executeJavaScript(code) From 8307fb84265509bcaaed99f9c6b8b452f9a56bfb Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Fri, 26 Feb 2016 16:39:42 -0800 Subject: [PATCH 39/49] Change logic for `platformSupportsUpdates --- src/auto-update-manager.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 14ec44c29..c1446ed5d 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -42,7 +42,7 @@ export default class AutoUpdateManager { } platformSupportsUpdates () { - return this.getReleaseChannel() == 'stable' && (this.getPlatform() === 'darwin' || this.getPlatform() === 'win32') + return this.getReleaseChannel() !== 'dev' && this.getState() !== 'unsupported' } onDidBeginCheckingForUpdate (callback) { From d831ec73ed6adeccc1b355f96167daf1630031af Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 29 Feb 2016 16:42:25 -0800 Subject: [PATCH 40/49] Fix platformSupportsUpdates() specs --- spec/auto-update-manager-spec.js | 20 ++++++-------------- 1 file changed, 6 insertions(+), 14 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index e12f85c5b..2b65d09e5 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -65,32 +65,24 @@ describe('AutoUpdateManager (renderer)', () => { }) describe('::platformSupportsUpdates', () => { - let platform, releaseChannel + let state, releaseChannel it('returns true on OS X and Windows, when in stable', () => { - spyOn(autoUpdateManager, 'getPlatform').andCallFake(() => platform) + spyOn(autoUpdateManager, 'getState').andCallFake(() => state) spyOn(autoUpdateManager, 'getReleaseChannel').andCallFake(() => releaseChannel) - platform = 'win32' + state = 'idle' releaseChannel = 'stable' expect(autoUpdateManager.platformSupportsUpdates()).toBe(true) - platform = 'win32' + state = 'idle' releaseChannel = 'dev' expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) - platform = 'darwin' - releaseChannel = 'stable' - expect(autoUpdateManager.platformSupportsUpdates()).toBe(true) - - platform = 'darwin' - releaseChannel = 'dev' - expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) - - platform = 'linux' + state = 'unsupported' releaseChannel = 'stable' expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) - platform = 'linux' + state = 'unsupported' releaseChannel = 'dev' expect(autoUpdateManager.platformSupportsUpdates()).toBe(false) }) From 8eb1326d4c7170768cb0d71908803220c28aab0f Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 29 Feb 2016 16:42:37 -0800 Subject: [PATCH 41/49] Add some TODOs --- src/application-delegate.coffee | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index a853cd8ea..dff496fdd 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -174,6 +174,9 @@ class ApplicationDelegate onUpdateAvailable: (callback) -> outerCallback = (event, message, detail) -> + # TODO: Yes, this is strange that `onUpdateAvailable` is listening for + # `did-begin-downloading-update`. We currently have no mechanism to know + # if there is an update, so begin of downloading is a good proxy. callback(detail) if message is 'did-begin-downloading-update' ipcRenderer.on('message', outerCallback) @@ -193,6 +196,7 @@ class ApplicationDelegate onDidCompleteDownloadingUpdate: (callback) -> outerCallback = (event, message, detail) -> + # TODO: We could rename this event to `did-complete-downloading-update` callback(detail) if message is 'update-available' ipcRenderer.on('message', outerCallback) From 75aca7ee0c9e1a61349114f5d3d78b676d58b2b2 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Mon, 29 Feb 2016 16:47:53 -0800 Subject: [PATCH 42/49] Add a deprecation TODO --- src/atom-environment.coffee | 1 + 1 file changed, 1 insertion(+) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 2122abbbe..df9130453 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -884,6 +884,7 @@ class AtomEnvironment extends Model detail: error.message dismissable: true + # TODO: We should deprecate the update events here, and use `atom.autoUpdater` instead onUpdateAvailable: (callback) -> @emitter.on 'update-available', callback From 58bf090724bd9b0f5917d9ce1dde2746c53e38d4 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Mar 2016 14:41:38 -0800 Subject: [PATCH 43/49] Rename `dispose` -> `destroy` --- spec/auto-update-manager-spec.js | 8 ++++---- src/atom-environment.coffee | 1 + src/auto-update-manager.js | 2 +- 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 2b65d09e5..9c82400ef 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -14,7 +14,7 @@ describe('AutoUpdateManager (renderer)', () => { }) afterEach(() => { - autoUpdateManager.dispose() + autoUpdateManager.destroy() }) describe('::onDidBeginCheckingForUpdate', () => { @@ -88,8 +88,8 @@ describe('AutoUpdateManager (renderer)', () => { }) }) - describe('::dispose', () => { - it('subscribes to "update-not-available" event', () => { + describe('::destroy', () => { + it('unsubscribes from all events', () => { const spy = jasmine.createSpy('spy') const doneIndicator = jasmine.createSpy('spy') atom.applicationDelegate.onUpdateNotAvailable(doneIndicator) @@ -97,7 +97,7 @@ describe('AutoUpdateManager (renderer)', () => { autoUpdateManager.onDidBeginDownloadingUpdate(spy) autoUpdateManager.onDidCompleteDownloadingUpdate(spy) autoUpdateManager.onUpdateNotAvailable(spy) - autoUpdateManager.dispose() + autoUpdateManager.destroy() electronAutoUpdater.emit('checking-for-update') electronAutoUpdater.emit('update-available') electronAutoUpdater.emit('update-downloaded', null, null, '1.2.3') diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index df9130453..4fecd01aa 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -338,6 +338,7 @@ class AtomEnvironment extends Model @commands.clear() @stylesElement.remove() @config.unobserveUserConfig() + @autoUpdater.destroy() @uninstallWindowEventHandler() diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index c1446ed5d..3b2d27439 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -24,7 +24,7 @@ export default class AutoUpdateManager { ) } - dispose () { + destroy () { this.subscriptions.dispose() this.emitter.dispose() } From 81c07a2af9322e32b758c088663887b233db1808 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Mar 2016 14:42:53 -0800 Subject: [PATCH 44/49] :art: Cleanup spec desc --- spec/auto-update-manager-spec.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 9c82400ef..7436be291 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -66,7 +66,7 @@ describe('AutoUpdateManager (renderer)', () => { describe('::platformSupportsUpdates', () => { let state, releaseChannel - it('returns true on OS X and Windows, when in stable', () => { + it('returns true on OS X and Windows when in stable', () => { spyOn(autoUpdateManager, 'getState').andCallFake(() => state) spyOn(autoUpdateManager, 'getReleaseChannel').andCallFake(() => releaseChannel) From 02368a9fc680f658dacbd0b06e1531959dd6c340 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Mar 2016 14:51:45 -0800 Subject: [PATCH 45/49] Add `atom.getReleaseChannel` --- spec/atom-environment-spec.coffee | 15 +++++++++++++++ src/atom-environment.coffee | 10 ++++++++++ 2 files changed, 25 insertions(+) diff --git a/spec/atom-environment-spec.coffee b/spec/atom-environment-spec.coffee index 1f8eb08e7..6685d4060 100644 --- a/spec/atom-environment-spec.coffee +++ b/spec/atom-environment-spec.coffee @@ -328,3 +328,18 @@ describe "AtomEnvironment", -> runs -> {releaseVersion} = updateAvailableHandler.mostRecentCall.args[0] expect(releaseVersion).toBe 'version' + + describe "::getReleaseChannel()", -> + [version] = [] + beforeEach -> + spyOn(atom, 'getVersion').andCallFake -> version + + it "returns the correct channel based on the version number", -> + version = '1.5.6' + expect(atom.getReleaseChannel()).toBe 'stable' + + version = '1.5.0-beta10' + expect(atom.getReleaseChannel()).toBe 'beta' + + version = '1.7.0-dev-5340c91' + expect(atom.getReleaseChannel()).toBe 'dev' diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 4fecd01aa..14d3f78c9 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -417,6 +417,16 @@ class AtomEnvironment extends Model getVersion: -> @appVersion ?= @getLoadSettings().appVersion + # Returns the release channel as a {String}. Will return one of `'dev', 'beta', 'stable'` + getReleaseChannel: -> + version = @getVersion() + if version.indexOf('beta') > -1 + 'beta' + else if version.indexOf('dev') > -1 + 'dev' + else + 'stable' + # Public: Returns a {Boolean} that is `true` if the current version is an official release. isReleasedVersion: -> not /\w{7}/.test(@getVersion()) # Check if the release is a 7-character SHA prefix From 0b36d85bdac5679097f48cefa3f0bd44fe367b4c Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Mar 2016 14:51:57 -0800 Subject: [PATCH 46/49] :art: Remove whitespace --- src/atom-environment.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/atom-environment.coffee b/src/atom-environment.coffee index 14d3f78c9..06296fbaf 100644 --- a/src/atom-environment.coffee +++ b/src/atom-environment.coffee @@ -846,7 +846,6 @@ class AtomEnvironment extends Model @applicationDelegate.setTemporaryWindowState(state) savePromise.catch(reject).then(resolve) - loadState: -> if @enablePersistence if stateKey = @getStateKey(@getLoadSettings().initialPaths) From 4d11ff25d0953c1debdacaef1b05f9a736b164f4 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Mar 2016 14:59:02 -0800 Subject: [PATCH 47/49] Use atom.getReleaseChannel() --- spec/auto-update-manager-spec.js | 2 +- src/auto-update-manager.js | 13 +------------ 2 files changed, 2 insertions(+), 13 deletions(-) diff --git a/spec/auto-update-manager-spec.js b/spec/auto-update-manager-spec.js index 7436be291..6f7dbbb1a 100644 --- a/spec/auto-update-manager-spec.js +++ b/spec/auto-update-manager-spec.js @@ -68,7 +68,7 @@ describe('AutoUpdateManager (renderer)', () => { let state, releaseChannel it('returns true on OS X and Windows when in stable', () => { spyOn(autoUpdateManager, 'getState').andCallFake(() => state) - spyOn(autoUpdateManager, 'getReleaseChannel').andCallFake(() => releaseChannel) + spyOn(atom, 'getReleaseChannel').andCallFake(() => releaseChannel) state = 'idle' releaseChannel = 'stable' diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 3b2d27439..4a184faf8 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -42,7 +42,7 @@ export default class AutoUpdateManager { } platformSupportsUpdates () { - return this.getReleaseChannel() !== 'dev' && this.getState() !== 'unsupported' + return atom.getReleaseChannel() !== 'dev' && this.getState() !== 'unsupported' } onDidBeginCheckingForUpdate (callback) { @@ -70,15 +70,4 @@ export default class AutoUpdateManager { getPlatform () { return process.platform } - - // TODO: We should move this into atom env or something. - getReleaseChannel () { - let version = atom.getVersion() - if (version.indexOf('beta') > -1) { - return 'beta' - } else if (version.indexOf('dev') > -1) { - return 'dev' - } - return 'stable' - } } From 492e89c8fff3d9fa96634a8510eab1f3222dfe42 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Mar 2016 14:59:41 -0800 Subject: [PATCH 48/49] Move raw ipc calls into the applicationDelegate --- src/application-delegate.coffee | 9 +++++++++ src/auto-update-manager.js | 7 ++++--- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/src/application-delegate.coffee b/src/application-delegate.coffee index dff496fdd..3aff9e457 100644 --- a/src/application-delegate.coffee +++ b/src/application-delegate.coffee @@ -235,3 +235,12 @@ class ApplicationDelegate disablePinchToZoom: -> webFrame.setZoomLevelLimits(1, 1) + + checkForUpdate: -> + ipcRenderer.send('check-for-update') + + restartAndInstallUpdate: -> + ipcRenderer.send('install-update') + + getAutoUpdateManagerState: -> + ipcRenderer.sendSync('get-auto-update-manager-state') diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 4a184faf8..01ead9bbe 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -5,6 +5,7 @@ import {ipcRenderer} from 'electron' export default class AutoUpdateManager { constructor ({applicationDelegate}) { + this.applicationDelegate = applicationDelegate this.subscriptions = new CompositeDisposable() this.emitter = new Emitter() @@ -30,15 +31,15 @@ export default class AutoUpdateManager { } checkForUpdate () { - ipcRenderer.send('check-for-update') + this.applicationDelegate.checkForUpdate() } restartAndInstallUpdate () { - ipcRenderer.send('install-update') + this.applicationDelegate.restartAndInstallUpdate() } getState () { - return ipcRenderer.sendSync('get-auto-update-manager-state') + return this.applicationDelegate.getAutoUpdateManagerState() } platformSupportsUpdates () { From f884c987e29acef83a40164b681950a7fd8bf047 Mon Sep 17 00:00:00 2001 From: Ben Ogle Date: Tue, 1 Mar 2016 15:12:38 -0800 Subject: [PATCH 49/49] Remove unnecessary import --- src/auto-update-manager.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/auto-update-manager.js b/src/auto-update-manager.js index 01ead9bbe..62cc03f85 100644 --- a/src/auto-update-manager.js +++ b/src/auto-update-manager.js @@ -1,7 +1,6 @@ 'use babel' import {Emitter, CompositeDisposable} from 'event-kit' -import {ipcRenderer} from 'electron' export default class AutoUpdateManager { constructor ({applicationDelegate}) {