From caeb70cf4a6bd52dc927fe0bae254ec1c4d48720 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Mon, 3 Feb 2014 12:52:01 -0800 Subject: [PATCH] Add 'Check for Updates' menu item --- menus/darwin.cson | 3 ++- src/browser/application-menu.coffee | 20 +++++++------------- src/browser/atom-application.coffee | 26 ++++++++++++++++++++++++++ 3 files changed, 35 insertions(+), 14 deletions(-) diff --git a/menus/darwin.cson b/menus/darwin.cson index 44e88dead..346523299 100644 --- a/menus/darwin.cson +++ b/menus/darwin.cson @@ -4,7 +4,8 @@ submenu: [ { label: 'About Atom', command: 'application:about' } { label: "VERSION", enabled: false } - { label: "Install update", command: 'application:install-update', visible: false } + { label: "Restart and Install Update", command: 'application:install-update', visible: false} + { label: "Check for Update", command: 'application:check-for-update'} { type: 'separator' } { label: 'Preferences...', command: 'application:show-settings' } { label: 'Open Your Config', command: 'application:open-your-config' } diff --git a/src/browser/application-menu.coffee b/src/browser/application-menu.coffee index 7de362838..10f2e45c2 100644 --- a/src/browser/application-menu.coffee +++ b/src/browser/application-menu.coffee @@ -69,19 +69,13 @@ class ApplicationMenu if (item = _.find(@flattenMenuTemplate(template), (i) -> i.label == 'VERSION')) item.label = "Version #{@version}" - # Public: Makes the download menu item visible if available. - # - # Note: The update menu item's must match 'Install update' exactly otherwise - # this function will fail to work. - # - # * newVersion: - # FIXME: Unused. - # * quitAndUpdateCallback: - # Function to call when the install menu item has been clicked. - showDownloadUpdateItem: (newVersion, quitAndUpdateCallback) -> - if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Install update')) - item.visible = true - item.click = quitAndUpdateCallback + showInstallUpdateItem: (visible=true) -> + if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Restart and Install Update')) + item.visible = visible + + showCheckForUpdateItem: (visible=true) -> + if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Check for Update')) + item.visible = visible # Private: Default list of menu items. # diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index bf773fdb0..d2e07f9ca 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -140,6 +140,30 @@ class AtomApplication autoUpdater.checkForUpdates() + checkForUpdate: -> + autoUpdater.once 'update-available', -> + dialog.showMessageBox + type: 'info' + buttons: ['OK'] + message: 'Update available.' + detail: 'A new update is being downloading.' + + 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 + + autoUpdater.checkForUpdates() + # Private: Registers basic application commands, non-idempotent. handleEvents: -> @on 'application:about', -> Menu.sendActionToFirstResponder('orderFrontStandardAboutPanel:') @@ -159,6 +183,8 @@ class AtomApplication @on 'application:inspect', ({x,y}) -> @focusedWindow().browserWindow.inspectElement(x, y) @on 'application:open-documentation', -> shell.openExternal('https://www.atom.io/docs/latest/?app') @on 'application:report-issue', -> shell.openExternal('https://github.com/atom/atom/issues/new') + @on 'application:install-update', -> autoUpdater.quitAndInstall() + @on 'application:check-for-update', => @checkForUpdate() @openPathOnEvent('application:show-settings', 'atom://config') @openPathOnEvent('application:open-your-config', 'atom://.atom/config')