From f0ea21bf380de602376ee0934de1c3760e0a4316 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 22 Mar 2015 11:06:13 +0000 Subject: Upgrade message; show after permission accepted. We're asking for the "notifications" permission. I'm not sure what happens. If the user is asked to accept the permission, then we wouldn't show the notification until the next time Vimium starts. Instead, we check more frequently. So the notification will show the next time a tab is created (or changes page). --- background_scripts/main.coffee | 37 +++++++++++++++++++++---------------- 1 file changed, 21 insertions(+), 16 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 4cb9465f..5dac2681 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -58,7 +58,7 @@ completers = bookmarks: new MultiCompleter([completionSources.bookmarks]) tabs: new MultiCompleter([completionSources.tabs]) -chrome.runtime.onConnect.addListener((port, name) -> +chrome.runtime.onConnect.addListener (port, name) -> senderTabId = if port.sender.tab then port.sender.tab.id else null # If this is a tab we've been waiting to open, execute any "tab loaded" handlers, e.g. to restore # the tab's scroll position. Wait until domReady before doing this; otherwise operations like restoring @@ -72,7 +72,10 @@ chrome.runtime.onConnect.addListener((port, name) -> if (portHandlers[port.name]) port.onMessage.addListener(portHandlers[port.name]) -) + + # If the user has accepted the "notifications" permission since we started, then we should try showing the + # upgrade massge again. + showUpgradeMessage() chrome.runtime.onMessage.addListener((request, sender, sendResponse) -> if (sendRequestHandlers[request.handler]) @@ -689,20 +692,21 @@ populateValidFirstKeys() populateSingleKeyCommands() # Show notification on upgrade. -if shouldShowUpgradeMessage() - notificationId = "VimiumUpgradeNotification" - notification = - type: "basic" - iconUrl: chrome.runtime.getURL "icons/vimium.png" - title: "Vimium Upgrade" - message: "Vimium has been upgraded to version #{currentVersion}. Click here for more information" - isClickable: true - chrome.notifications.create notificationId, notification, -> - unless chrome.runtime.lastError - Settings.set "previousVersion", currentVersion - chrome.notifications.onClicked.addListener (id) -> - if id == notificationId - openUrlInNewTab url: "https://github.com/philc/vimium#release-notes" +showUpgradeMessage = -> + if shouldShowUpgradeMessage() + notificationId = "VimiumUpgradeNotification" + notification = + type: "basic" + iconUrl: chrome.runtime.getURL "icons/vimium.png" + title: "Vimium Upgrade" + message: "Vimium has been upgraded to version #{currentVersion}. Click here for more information" + isClickable: true + chrome.notifications.create notificationId, notification, -> + unless chrome.runtime.lastError + Settings.set "previousVersion", currentVersion + chrome.notifications.onClicked.addListener (id) -> + if id == notificationId + openUrlInNewTab url: "https://github.com/philc/vimium#release-notes" # Ensure that tabInfoMap is populated when Vimium is installed. chrome.windows.getAll { populate: true }, (windows) -> @@ -715,3 +719,4 @@ chrome.windows.getAll { populate: true }, (windows) -> # Start pulling changes from synchronized storage. Sync.init() +showUpgradeMessage() -- cgit v1.2.3