From c908a1633ca2c745a52d495869716b78c719e0ba Mon Sep 17 00:00:00 2001 From: Jackie Luo Date: Thu, 18 Aug 2016 13:17:40 -0700 Subject: [PATCH] fix(autoupdater): Change feed URL when Nylas ID or accounts changes Test Plan: Tested locally. Reviewers: juan, evan Reviewed By: juan, evan Differential Revision: https://phab.nylas.com/D3178 --- spec/auto-update-manager-spec.coffee | 16 +++++++++++++++- src/browser/auto-update-manager.es6 | 19 ++++++++++++++++++- 2 files changed, 33 insertions(+), 2 deletions(-) diff --git a/spec/auto-update-manager-spec.coffee b/spec/auto-update-manager-spec.coffee index adbceda79..fbcfdf659 100644 --- a/spec/auto-update-manager-spec.coffee +++ b/spec/auto-update-manager-spec.coffee @@ -4,14 +4,17 @@ url = require 'url' describe "AutoUpdateManager", -> beforeEach -> @nylasIdentityId = null + @accounts = [{email_address: 'ben@nylas.com'},{email_address: 'mark@nylas.com'}] @specMode = true @config = set: jasmine.createSpy('config.set') get: (key) => if key is 'nylas.accounts' - return [{email_address: 'ben@nylas.com'},{email_address: 'mark@nylas.com'}] + return @accounts if key is 'nylas.identity.id' return @nylasIdentityId + onDidChange: (key, callback) => + callback() describe "with attached commit version", -> it "correctly sets the feedURL", -> @@ -46,3 +49,14 @@ describe "AutoUpdateManager", -> spyOn(m, "setupAutoUpdater") {query} = url.parse(m.feedURL, true) expect(query.id).toEqual(@nylasIdentityId) + + describe "when an update identity is added", -> + it "should update the feed URL", -> + m = new AutoUpdateManager("3.222.1", @config, @specMode) + spyOn(m, "setupAutoUpdater") + {query} = url.parse(m.feedURL, true) + expect(query.id).toEqual('anonymous') + @nylasIdentityId = '1' + m._updateFeedURL() + {query} = url.parse(m.feedURL, true) + expect(query.id).toEqual(@nylasIdentityId) diff --git a/src/browser/auto-update-manager.es6 b/src/browser/auto-update-manager.es6 index b93c48af0..3dd80932a 100644 --- a/src/browser/auto-update-manager.es6 +++ b/src/browser/auto-update-manager.es6 @@ -24,6 +24,21 @@ export default class AutoUpdateManager extends EventEmitter { this.config = config; this.specMode = specMode; + this._updateFeedURL(); + + this.config.onDidChange( + 'nylas.identity.id', + this._updateFeedURL + ); + this.config.onDidChange( + 'nylas.accounts', + this._updateFeedURL + ); + + process.nextTick(() => this.setupAutoUpdater()); + } + + _updateFeedURL = () => { let updaterId = this.config.get("nylas.identity.id"); if (!updaterId) { updaterId = "anonymous"; @@ -46,7 +61,9 @@ export default class AutoUpdateManager extends EventEmitter { this.feedURL = `https://edgehill.nylas.com/update-check?platform=${process.platform}&arch=${process.arch}&version=${this.version}&id=${updaterId}&emails=${updaterEmails}`; } - process.nextTick(() => this.setupAutoUpdater()); + if (autoUpdater) { + autoUpdater.setFeedURL(this.feedURL) + } } setupAutoUpdater() {