From 084b41e33b656eeaca12089986ec7b808bfea67c Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 4 Mar 2014 10:17:55 -0800 Subject: [PATCH 1/5] Remove listeners after `check for update` is run. --- src/browser/atom-application.coffee | 36 ++++++++++++++--------------- 1 file changed, 18 insertions(+), 18 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 02c67140b..793b4130c 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -154,27 +154,27 @@ class AtomApplication 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.' + removeListeners = => + autoUpdater.removeListener 'update-available', @onUpdateAvailable + autoUpdater.removeListener 'update-not-available', @onUpdateNotAvailable + autoUpdater.removeListener 'error', @onUpdateError - autoUpdater.once 'update-not-available', => - dialog.showMessageBox - type: 'info' - buttons: ['OK'] - message: 'No update available.' - detail: "Version #{@version} is the latest version." + @onUpdateAvailable ?= => + removeListeners() + dialog.showMessageBox type: 'info', buttons: ['OK'], message: 'Update available.', detail: 'A new update is being downloaded.' - autoUpdater.once 'error', (event, message)-> - dialog.showMessageBox - type: 'warning' - buttons: ['OK'] - message: 'There was an error checking for updates.' - detail: message + @onUpdateNotAvailable ?= => + removeListeners() + dialog.showMessageBox type: 'info', buttons: ['OK'], message: 'No update available.', detail: "Version #{@version} is the latest version." + @onUpdateError ?= (event, message) => + removeListeners() + dialog.showMessageBox type: 'warning', buttons: ['OK'], message: 'There was an error checking for updates.', detail: message + + autoUpdater.on 'update-available', @onUpdateAvailable + autoUpdater.on 'update-not-available', @onUpdateNotAvailable + autoUpdater.on 'error', @onUpdateError + @applicationMenu.showCheckForUpdateItem(false) autoUpdater.checkForUpdates() # Registers basic application commands, non-idempotent. From e8136853db36d7dc239d9b9f554fba46b08834d9 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 4 Mar 2014 12:05:23 -0800 Subject: [PATCH 2/5] Add 'downloading update' menu item Fixes #1689, gets around the crashing bug when displaying a dialog when update is found. --- menus/darwin.cson | 1 + src/browser/application-menu.coffee | 5 +++++ src/browser/atom-application.coffee | 15 +++++++++------ 3 files changed, 15 insertions(+), 6 deletions(-) diff --git a/menus/darwin.cson b/menus/darwin.cson index f72552fac..e3681951c 100644 --- a/menus/darwin.cson +++ b/menus/darwin.cson @@ -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' } diff --git a/src/browser/application-menu.coffee b/src/browser/application-menu.coffee index 905655ac8..665f83b6a 100644 --- a/src/browser/application-menu.coffee +++ b/src/browser/application-menu.coffee @@ -74,6 +74,11 @@ class ApplicationMenu if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Restart and Install Update')) item.visible = visible + # Toggles Downloading Update Item + showDownloadingUpdateItem: (visible=true) -> + if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Downloading Update')) + item.visible = visible + # Toggles Check For Update Item showCheckForUpdateItem: (visible=true) -> if (item = _.find(@flattenMenuItems(@menu), (i) -> i.label == 'Check for Update')) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 793b4130c..bdb13b7d3 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -133,20 +133,29 @@ 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.showDownloadingUpdateItem(false) @applicationMenu.showInstallUpdateItem(false) @applicationMenu.showCheckForUpdateItem(true) + autoUpdater.on 'update-available', => + @applicationMenu.showDownloadingUpdateItem(true) + @applicationMenu.showInstallUpdateItem(false) + @applicationMenu.showCheckForUpdateItem(false) + autoUpdater.on 'update-downloaded', (event, releaseNotes, releaseName, releaseDate, releaseURL) => atomWindow.sendCommand('window:update-available', [releaseName, releaseNotes]) for atomWindow in @windows + @applicationMenu.showDownloadingUpdateItem(false) @applicationMenu.showInstallUpdateItem(true) @applicationMenu.showCheckForUpdateItem(false) @updateVersion = releaseName autoUpdater.on 'error', (event, message) => + @applicationMenu.showDownloadingUpdateItem(false) @applicationMenu.showInstallUpdateItem(false) @applicationMenu.showCheckForUpdateItem(true) @@ -155,14 +164,9 @@ class AtomApplication checkForUpdate: -> removeListeners = => - autoUpdater.removeListener 'update-available', @onUpdateAvailable autoUpdater.removeListener 'update-not-available', @onUpdateNotAvailable autoUpdater.removeListener 'error', @onUpdateError - @onUpdateAvailable ?= => - removeListeners() - dialog.showMessageBox type: 'info', buttons: ['OK'], message: 'Update available.', detail: 'A new update is being downloaded.' - @onUpdateNotAvailable ?= => removeListeners() dialog.showMessageBox type: 'info', buttons: ['OK'], message: 'No update available.', detail: "Version #{@version} is the latest version." @@ -171,7 +175,6 @@ class AtomApplication removeListeners() dialog.showMessageBox type: 'warning', buttons: ['OK'], message: 'There was an error checking for updates.', detail: message - autoUpdater.on 'update-available', @onUpdateAvailable autoUpdater.on 'update-not-available', @onUpdateNotAvailable autoUpdater.on 'error', @onUpdateError @applicationMenu.showCheckForUpdateItem(false) From def6b67c8f095f4bd9bd101ae93f0b3344c8b2ae Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 4 Mar 2014 12:11:33 -0800 Subject: [PATCH 3/5] Menu items hide conflicting items when made visible. --- src/browser/application-menu.coffee | 12 ++++++++++++ src/browser/atom-application.coffee | 8 -------- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/browser/application-menu.coffee b/src/browser/application-menu.coffee index 665f83b6a..b411551c4 100644 --- a/src/browser/application-menu.coffee +++ b/src/browser/application-menu.coffee @@ -71,16 +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 diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index bdb13b7d3..b4ac6b55a 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -138,25 +138,17 @@ class AtomApplication @applicationMenu.showCheckForUpdateItem(false) autoUpdater.on 'update-not-available', => - @applicationMenu.showDownloadingUpdateItem(false) - @applicationMenu.showInstallUpdateItem(false) @applicationMenu.showCheckForUpdateItem(true) autoUpdater.on 'update-available', => @applicationMenu.showDownloadingUpdateItem(true) - @applicationMenu.showInstallUpdateItem(false) - @applicationMenu.showCheckForUpdateItem(false) autoUpdater.on 'update-downloaded', (event, releaseNotes, releaseName, releaseDate, releaseURL) => atomWindow.sendCommand('window:update-available', [releaseName, releaseNotes]) for atomWindow in @windows - @applicationMenu.showDownloadingUpdateItem(false) @applicationMenu.showInstallUpdateItem(true) - @applicationMenu.showCheckForUpdateItem(false) @updateVersion = releaseName autoUpdater.on 'error', (event, message) => - @applicationMenu.showDownloadingUpdateItem(false) - @applicationMenu.showInstallUpdateItem(false) @applicationMenu.showCheckForUpdateItem(true) # Check for update after Atom has fully started and the menus are created From 8b45f89a75e5518f24c210f160504714768a9ace Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 4 Mar 2014 12:30:15 -0800 Subject: [PATCH 4/5] Remove unnecessary method --- src/browser/atom-application.coffee | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index b4ac6b55a..40bb4fd18 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -155,16 +155,12 @@ class AtomApplication setTimeout((-> autoUpdater.checkForUpdates()), 5000) checkForUpdate: -> - removeListeners = => - autoUpdater.removeListener 'update-not-available', @onUpdateNotAvailable - autoUpdater.removeListener 'error', @onUpdateError - @onUpdateNotAvailable ?= => - removeListeners() + autoUpdater.removeListener 'error', @onUpdateError dialog.showMessageBox type: 'info', buttons: ['OK'], message: 'No update available.', detail: "Version #{@version} is the latest version." @onUpdateError ?= (event, message) => - removeListeners() + 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 From 956d4bd5bfec447279196bc32fc1ed5eeb904f63 Mon Sep 17 00:00:00 2001 From: probablycorey Date: Tue, 4 Mar 2014 12:31:32 -0800 Subject: [PATCH 5/5] Rely on events to hide the "Check for update" menu item --- src/browser/atom-application.coffee | 1 - 1 file changed, 1 deletion(-) diff --git a/src/browser/atom-application.coffee b/src/browser/atom-application.coffee index 40bb4fd18..ac0d13f4e 100644 --- a/src/browser/atom-application.coffee +++ b/src/browser/atom-application.coffee @@ -165,7 +165,6 @@ class AtomApplication autoUpdater.on 'update-not-available', @onUpdateNotAvailable autoUpdater.on 'error', @onUpdateError - @applicationMenu.showCheckForUpdateItem(false) autoUpdater.checkForUpdates() # Registers basic application commands, non-idempotent.