Use hidden menu items for update processes

Esse commit está contido em:
probablycorey
2014-04-07 14:17:44 -07:00
commit d4ae836225
3 arquivos alterados com 29 adições e 30 exclusões
+4 -2
Ver Arquivo
@@ -4,8 +4,10 @@
submenu: [
{ label: 'About Atom', command: 'application:about' }
{ label: 'View License', command: 'application:open-license' }
{ label: "VERSION", enabled: false }
{ label: "Check for Update", command: 'application:noop', metadata: {autoUpdate: true}}
{ label: 'VERSION', enabled: false }
{ label: 'Check for Update', command: 'application:check-for-update', visible: false}
{ label: 'Downloading Update', enabled: false, visible: false}
{ label: 'Restart and Install Update', command: 'application:install-update', enabled: false, visible: false}
{ type: 'separator' }
{ label: 'Preferences...', command: 'application:show-settings' }
{ label: 'Open Your Config', command: 'application:open-your-config' }
+18 -23
Ver Arquivo
@@ -13,7 +13,7 @@ class ApplicationMenu
@menu = Menu.buildFromTemplate @getDefaultTemplate()
Menu.setApplicationMenu @menu
global.atomApplication.autoUpdateManager.on 'state-changed', (state) =>
@update(@template, @keystrokesByCommand) if @template?
@showUpdateMenuItem(state)
# Public: Updates the entire menu with the given keybindings.
#
@@ -23,15 +23,13 @@ class ApplicationMenu
# An Object where the keys are commands and the values are Arrays containing
# the keystroke.
update: (template, keystrokesByCommand) ->
@template = _.clone(template)
@keystrokesByCommand = _.clone(keystrokesByCommand)
@translateTemplate(template, keystrokesByCommand)
@substituteVersion(template)
@setUpdateMenuItemState(template)
@menu = Menu.buildFromTemplate(template)
Menu.setApplicationMenu(@menu)
@showUpdateMenuItem(global.atomApplication.autoUpdateManager.getState())
# Flattens the given menu and submenu items into an single Array.
#
# * menu:
@@ -73,27 +71,24 @@ class ApplicationMenu
item.label = "Version #{@version}"
# Sets the proper label, command and enabled state for the update menu item
setUpdateMenuItemState: (template) ->
item = _.find(@flattenMenuTemplate(template), (i) -> i.metadata.autoUpdate)
return unless item?
showUpdateMenuItem: (state) ->
checkForUpdateItem = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Check for Update')
downloadingUpdateItem = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Downloading Update')
installUpdateItem = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Restart and Install Update')
item.enabled = true
console.log global.atomApplication.autoUpdateManager.getState()
switch global.atomApplication.autoUpdateManager.getState()
return unless checkForUpdateItem? and downloadingUpdateItem? and installUpdateItem?
checkForUpdateItem.visible = false
downloadingUpdateItem.visible = false
installUpdateItem.visible = false
switch state
when 'idle', 'error', 'no-update-available'
item.label = 'Check for Update'
item.command = 'application:check-for-update'
when 'checking'
item.enabled = false
item.label = 'Checking for Update'
when 'downloading'
item.enabled = false
item.label = 'Downloading Update'
checkForUpdateItem.visible = true
when 'checking', 'downloading'
downloadingUpdateItem.visible = true
when 'update-available'
item.label = 'Restart and Install Update'
item.command = 'application:install-update'
console.log require('util').inspect(item)
installUpdateItem.visible = true
# Default list of menu items.
#
+7 -5
Ver Arquivo
@@ -17,7 +17,7 @@ class AutoUpdateManager
@state = IDLE_STATE
# Only released versions should check for updates.
# return if /\w{7}/.test(@getVersion())
return if /\w{7}/.test(@getVersion())
autoUpdater.setFeedUrl "https://atom.io/api/updates?version=#{@getVersion()}"
@@ -39,7 +39,7 @@ class AutoUpdateManager
for atomWindow in @getWindows()
atomWindow.sendCommand('window:update-available', [releaseVersion, releaseNotes])
@check()
@check(hidePopups: true)
setState: (state) ->
return unless @state != state
@@ -49,9 +49,11 @@ class AutoUpdateManager
getState: ->
@state
check: ->
autoUpdater.once 'update-not-available', @onUpdateNotAvailable
autoUpdater.once 'error', @onUpdateError
check: ({hidePopups}={})->
unless hidePopups
autoUpdater.once 'update-not-available', @onUpdateNotAvailable
autoUpdater.once 'error', @onUpdateError
autoUpdater.checkForUpdates()
install: ->