fix(updater): Send UUID and email accounts to enable more specific update distribution

This commit is contained in:
Ben Gotow 2015-10-03 14:45:39 -07:00
parent 94bdcc6900
commit c29220365a
3 changed files with 57 additions and 38 deletions

View file

@ -46,6 +46,7 @@
"moment": "^2.8",
"moment-timezone": "^0.3",
"nslog": "^2.0.0",
"node-uuid": "^1.4",
"optimist": "0.4.0",
"pathwatcher": "^4.4.0",
"property-accessors": "^1",

View file

@ -1,41 +1,51 @@
AutoUpdateManager = require '../src/browser/auto-update-manager'
url = require 'url'
describe "AutoUpdateManager", ->
c1 = get: ->
c2 = get: -> "major"
c3 = get: -> "minor"
c4 = get: -> "patch"
c5 = get: -> "commit"
c6 = get: -> "foo"
base = "https://edgehill.nylas.com/update-check?platform=#{process.platform}&version="
beforeEach ->
@feedUrl = (version, config) ->
m = new AutoUpdateManager(version, config)
spyOn(m, "setupAutoUpdater")
return m.feedUrl
@updateIdentity = null
@config =
set: jasmine.createSpy('config.set')
get: (key) =>
if key is 'nylas.accounts'
return [{email_address: 'ben@nylas.com'},{email_address: 'mark@nylas.com'}]
if key is 'updateIdentity'
return @updateIdentity
describe "with attached commit version", ->
beforeEach ->
@v = "3.222.1-abc"
it "correctly sets the feedURL", ->
expect(@feedUrl(@v, c1)).toBe "#{base}3.222.1-abc&level=patch"
expect(@feedUrl(@v, c2)).toBe "#{base}3.222.1-abc&level=major"
expect(@feedUrl(@v, c3)).toBe "#{base}3.222.1-abc&level=minor"
expect(@feedUrl(@v, c4)).toBe "#{base}3.222.1-abc&level=patch"
expect(@feedUrl(@v, c5)).toBe "#{base}3.222.1-abc&level=commit"
expect(@feedUrl(@v, c6)).toBe "#{base}3.222.1-abc&level=patch"
m = new AutoUpdateManager("3.222.1-abc", @config)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedUrl, true)
expect(query.arch).toBe process.arch
expect(query.platform).toBe process.platform
expect(query.version).toBe "3.222.1-abc"
describe "with no attached commit", ->
beforeEach ->
@v = "3.222.1"
it "correctly sets the feedURL", ->
expect(@feedUrl(@v, c1)).toBe "#{base}3.222.1&level=patch"
expect(@feedUrl(@v, c2)).toBe "#{base}3.222.1&level=major"
expect(@feedUrl(@v, c3)).toBe "#{base}3.222.1&level=minor"
expect(@feedUrl(@v, c4)).toBe "#{base}3.222.1&level=patch"
expect(@feedUrl(@v, c5)).toBe "#{base}3.222.1&level=commit"
expect(@feedUrl(@v, c6)).toBe "#{base}3.222.1&level=patch"
m = new AutoUpdateManager("3.222.1", @config)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedUrl, true)
expect(query.arch).toBe process.arch
expect(query.platform).toBe process.platform
expect(query.version).toBe "3.222.1"
describe "when an update identity is not present", ->
it "should save one to @config and send it", ->
m = new AutoUpdateManager("3.222.1", @config)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedUrl, true)
expect(query.id).toBeDefined()
expect(@config.set).toHaveBeenCalledWith('updateIdentity', query.id)
describe "when an update identity is already set", ->
it "should send it and not save any changes", ->
@updateIdentity = "test-identity"
m = new AutoUpdateManager("3.222.1", @config)
spyOn(m, "setupAutoUpdater")
{query} = url.parse(m.feedUrl, true)
expect(query.id).toEqual(@updateIdentity)
expect(@config.set).not.toHaveBeenCalled()

View file

@ -1,6 +1,7 @@
autoUpdater = null
_ = require 'underscore'
{EventEmitter} = require 'events'
uuid = require 'node-uuid'
path = require 'path'
fs = require 'fs'
@ -19,21 +20,28 @@ class AutoUpdateManager
constructor: (@version, @config, @specMode) ->
@state = IdleState
updaterId = @config.get("updateIdentity")
if not updaterId
updaterId = uuid.v4()
@config.set("updateIdentity", updaterId)
emails = []
accounts = @config.get('nylas.accounts') || []
for account in accounts
if account.email_address?
emails.push(encodeURIComponent(account.email_address))
updaterEmails = emails.join(',')
if process.platform is 'win32'
# Squirrel for Windows can't handle query params
# https://github.com/Squirrel/Squirrel.Windows/issues/132
@feedUrl = "https://edgehill.nylas.com/update-check/win32/#{@getUpgradeLevel()}/#{@version}"
@feedUrl = "https://edgehill.nylas.com/update-check/win32/#{@version}/#{updaterId}/#{updaterEmails}"
else
@feedUrl = "https://edgehill.nylas.com/update-check?platform=#{process.platform}&version=#{@version}&level=#{@getUpgradeLevel()}"
@feedUrl = "https://edgehill.nylas.com/update-check?platform=#{process.platform}&arch=#{process.arch}&version=#{@version}&id=#{updaterId}&emails=#{updaterEmails}"
if not @specMode
process.nextTick => @setupAutoUpdater()
getUpgradeLevel: ->
lvl = @config.get("updateLevel") ? "patch"
if lvl not in ["major", "minor", "patch", "commit"] then lvl = "patch"
return lvl
setupAutoUpdater: ->
if process.platform is 'win32'
autoUpdater = require './auto-updater-win32'