Use Squirrel API for auto-updates

This commit is contained in:
probablycorey
2014-02-03 12:51:38 -08:00
parent c730910f7c
commit cc233fb7f6
2 changed files with 22 additions and 21 deletions

View File

@@ -72,7 +72,7 @@ class AtomApplication
@listenForArgumentsFromNewProcess()
@setupJavaScriptArguments()
@handleEvents()
@checkForUpdates()
@setupAutoUpdater()
@openWithOptions(options)
@@ -117,16 +117,28 @@ class AtomApplication
app.commandLine.appendSwitch 'js-flags', '--harmony_collections --harmony-proxies'
# Private: Enable updates unless running from a local build of Atom.
checkForUpdates: ->
versionIsSha = /\w{7}/.test @version
setupAutoUpdater: ->
autoUpdater.setFeedUrl "http://localhost:9393/releases/latest?version=#{@version}"
if versionIsSha
autoUpdater.setAutomaticallyDownloadsUpdates false
autoUpdater.setAutomaticallyChecksForUpdates false
else
autoUpdater.setAutomaticallyDownloadsUpdates true
autoUpdater.setAutomaticallyChecksForUpdates true
autoUpdater.checkForUpdatesInBackground()
autoUpdater.on 'checking-for-update', =>
@applicationMenu.showInstallUpdateItem(false)
@applicationMenu.showCheckForUpdateItem(false)
autoUpdater.on 'update-not-available', =>
@applicationMenu.showInstallUpdateItem(false)
@applicationMenu.showCheckForUpdateItem(true)
autoUpdater.on 'update-downloaded', (event, releaseNotes, releaseName, releaseDate, releaseURL) =>
atomWindow.sendCommand('window:update-available', releaseName) for atomWindow in @windows
@applicationMenu.showInstallUpdateItem(true)
@applicationMenu.showCheckForUpdateItem(false)
@updateVersion = releaseName
autoUpdater.on 'error', (event, message)=>
@applicationMenu.showInstallUpdateItem(false)
@applicationMenu.showCheckForUpdateItem(true)
autoUpdater.checkForUpdates()
# Private: Registers basic application commands, non-idempotent.
handleEvents: ->
@@ -170,12 +182,6 @@ class AtomApplication
event.preventDefault()
@openUrl({urlToOpen, @devMode})
autoUpdater.on 'ready-for-update-on-quit', (event, version, quitAndUpdateCallback) =>
event.preventDefault()
@updateVersion = version
@applicationMenu.showDownloadUpdateItem(version, quitAndUpdateCallback)
atomWindow.sendCommand('window:update-available', version) for atomWindow in @windows
# A request from the associated render process to open a new render process.
ipc.on 'open', (processId, routingId, options) =>
if options?

View File

@@ -1,6 +1,5 @@
global.shellStartTime = Date.now()
autoUpdater = require 'auto-updater'
crashReporter = require 'crash-reporter'
app = require 'app'
fs = require 'fs'
@@ -42,7 +41,6 @@ start = ->
app.on 'will-finish-launching', ->
setupCrashReporter()
setupAutoUpdater()
app.on 'finish-launching', ->
app.removeListener 'open-file', addPathToOpen
@@ -66,9 +64,6 @@ global.devResourcePath = path.join(app.getHomeDir(), 'github', 'atom')
setupCrashReporter = ->
crashReporter.start(productName: 'Atom', companyName: 'GitHub')
setupAutoUpdater = ->
autoUpdater.setFeedUrl 'https://speakeasy.githubapp.com/apps/27/appcast.xml'
parseCommandLine = ->
version = app.getVersion()
options = optimist(process.argv[1..])