Merge pull request #1693 from atom/cj-check-for-update-fix

Fix "check for update" crash
This commit is contained in:
Corey Johnson
2014-03-04 14:03:38 -08:00
3 changed files with 30 additions and 22 deletions

View File

@@ -7,6 +7,7 @@
{ label: "VERSION", enabled: false }
{ label: "Restart and Install Update", command: 'application:install-update', visible: false}
{ label: "Check for Update", command: 'application:check-for-update', visible: false}
{ label: "Downloading Update", command: 'application:check-for-update', enabled: false, visible: false}
{ type: 'separator' }
{ label: 'Preferences...', command: 'application:show-settings' }
{ label: 'Open Your Config', command: 'application:open-your-config' }

View File

@@ -71,11 +71,28 @@ class ApplicationMenu
# Toggles Install Update Item
showInstallUpdateItem: (visible=true) ->
if visible
@showDownloadingUpdateItem(false)
@showCheckForUpdateItem(false)
if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Restart and Install Update'))
item.visible = visible
# Toggles Downloading Update Item
showDownloadingUpdateItem: (visible=true) ->
if visible
@showInstallUpdateItem(false)
@showCheckForUpdateItem(false)
if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Downloading Update'))
item.visible = visible
# Toggles Check For Update Item
showCheckForUpdateItem: (visible=true) ->
if visible
@showDownloadingUpdateItem(false)
@showInstallUpdateItem(false)
if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Check for Update'))
item.visible = visible

View File

@@ -133,48 +133,38 @@ class AtomApplication
autoUpdater.setFeedUrl "https://atom.io/api/updates?version=#{@version}"
autoUpdater.on 'checking-for-update', =>
@applicationMenu.showDownloadingUpdateItem(false)
@applicationMenu.showInstallUpdateItem(false)
@applicationMenu.showCheckForUpdateItem(false)
autoUpdater.on 'update-not-available', =>
@applicationMenu.showInstallUpdateItem(false)
@applicationMenu.showCheckForUpdateItem(true)
autoUpdater.on 'update-available', =>
@applicationMenu.showDownloadingUpdateItem(true)
autoUpdater.on 'update-downloaded', (event, releaseNotes, releaseName, releaseDate, releaseURL) =>
atomWindow.sendCommand('window:update-available', [releaseName, releaseNotes]) for atomWindow in @windows
@applicationMenu.showInstallUpdateItem(true)
@applicationMenu.showCheckForUpdateItem(false)
@updateVersion = releaseName
autoUpdater.on 'error', (event, message) =>
@applicationMenu.showInstallUpdateItem(false)
@applicationMenu.showCheckForUpdateItem(true)
# Check for update after Atom has fully started and the menus are created
setTimeout((-> autoUpdater.checkForUpdates()), 5000)
checkForUpdate: ->
autoUpdater.once 'update-available', ->
dialog.showMessageBox
type: 'info'
buttons: ['OK']
message: 'Update available.'
detail: 'A new update is being downloaded.'
@onUpdateNotAvailable ?= =>
autoUpdater.removeListener 'error', @onUpdateError
dialog.showMessageBox type: 'info', buttons: ['OK'], message: 'No update available.', detail: "Version #{@version} is the latest version."
autoUpdater.once 'update-not-available', =>
dialog.showMessageBox
type: 'info'
buttons: ['OK']
message: 'No update available.'
detail: "Version #{@version} is the latest version."
autoUpdater.once 'error', (event, message)->
dialog.showMessageBox
type: 'warning'
buttons: ['OK']
message: 'There was an error checking for updates.'
detail: message
@onUpdateError ?= (event, message) =>
autoUpdater.removeListener 'update-not-available', @onUpdateNotAvailable
dialog.showMessageBox type: 'warning', buttons: ['OK'], message: 'There was an error checking for updates.', detail: message
autoUpdater.on 'update-not-available', @onUpdateNotAvailable
autoUpdater.on 'error', @onUpdateError
autoUpdater.checkForUpdates()
# Registers basic application commands, non-idempotent.