From a9a6294323c0d6385e40c771adb0870024c16824 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 22 Mar 2015 10:39:14 +0000 Subject: Use chrome.notifications for upgrade notifications. --- background_scripts/main.coffee | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index f70cd8f3..4cb9465f 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -70,11 +70,6 @@ chrome.runtime.onConnect.addListener((port, name) -> delete tabLoadedHandlers[senderTabId] toCall.call() - # domReady is the appropriate time to show the "vimium has been upgraded" message. - # TODO: This might be broken on pages with frames. - if (shouldShowUpgradeMessage()) - chrome.tabs.sendMessage(senderTabId, { name: "showUpgradeNotification", version: currentVersion }) - if (portHandlers[port.name]) port.onMessage.addListener(portHandlers[port.name]) ) @@ -183,14 +178,6 @@ openUrlInNewTab = (request, callback) -> openUrlInIncognito = (request) -> chrome.windows.create({ url: Utils.convertToUrl(request.url), incognito: true}) -# -# Called when the user has clicked the close icon on the "Vimium has been updated" message. -# We should now dismiss that message in all tabs. -# -upgradeNotificationClosed = (request) -> - Settings.set("previousVersion", currentVersion) - sendRequestToAllTabs({ name: "hideUpgradeNotification" }) - # # Copies or pastes some data (request.data) to/from the clipboard. # We return null to avoid the return value from the copy operations being passed to sendResponse. @@ -662,7 +649,6 @@ sendRequestHandlers = unregisterFrame: unregisterFrame frameFocused: handleFrameFocused nextFrame: (request) -> BackgroundCommands.nextFrame 1, request.frameId - upgradeNotificationClosed: upgradeNotificationClosed updateScrollPosition: handleUpdateScrollPosition copyToClipboard: copyToClipboard pasteFromClipboard: pasteFromClipboard @@ -701,8 +687,22 @@ if Settings.has("keyMappings") populateValidFirstKeys() populateSingleKeyCommands() + +# Show notification on upgrade. if shouldShowUpgradeMessage() - sendRequestToAllTabs({ name: "showUpgradeNotification", version: currentVersion }) + 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) -> -- cgit v1.2.3 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 From 98d9432da933ed8be8f9946196ff43477304de72 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sun, 22 Mar 2015 11:09:09 +0000 Subject: Upgrade notification. Add full-stop to message. --- background_scripts/main.coffee | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 5dac2681..53d617a2 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -699,7 +699,7 @@ showUpgradeMessage = -> 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" + message: "Vimium has been upgraded to version #{currentVersion}. Click here for more information." isClickable: true chrome.notifications.create notificationId, notification, -> unless chrome.runtime.lastError -- cgit v1.2.3 From 96785e861791be89cd4cf98b90c76efa60eaf803 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Fri, 3 Apr 2015 10:12:39 +0100 Subject: Simplify upgrade notification. --- background_scripts/main.coffee | 35 ++++++++++++++--------------------- 1 file changed, 14 insertions(+), 21 deletions(-) (limited to 'background_scripts') diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index 53d617a2..72fe1092 100644 --- a/background_scripts/main.coffee +++ b/background_scripts/main.coffee @@ -73,10 +73,6 @@ 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]) sendResponse(sendRequestHandlers[request.handler](request, sender)) @@ -603,16 +599,6 @@ sendRequestToAllTabs = (args) -> for tab in window.tabs chrome.tabs.sendMessage(tab.id, args, null)) -# -# Returns true if the current extension version is greater than the previously recorded version in -# localStorage, and false otherwise. -# -shouldShowUpgradeMessage = -> - # Avoid showing the upgrade notification when previousVersion is undefined, which is the case for new - # installs. - Settings.set("previousVersion", currentVersion) unless Settings.get("previousVersion") - Utils.compareVersions(currentVersion, Settings.get("previousVersion")) == 1 - openOptionsPageInNewTab = -> chrome.tabs.getSelected(null, (tab) -> chrome.tabs.create({ url: chrome.runtime.getURL("pages/options.html"), index: tab.index + 1 })) @@ -693,7 +679,10 @@ populateSingleKeyCommands() # Show notification on upgrade. showUpgradeMessage = -> - if shouldShowUpgradeMessage() + # Avoid showing the upgrade notification when previousVersion is undefined, which is the case for new + # installs. + Settings.set "previousVersion", currentVersion unless Settings.get "previousVersion" + if Utils.compareVersions(currentVersion, Settings.get "previousVersion" ) == 1 notificationId = "VimiumUpgradeNotification" notification = type: "basic" @@ -701,12 +690,16 @@ showUpgradeMessage = -> 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" + if chrome.notifications?.create? + 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" + else + # We need to wait for the user to accept the "notifications" permission. + chrome.permissions.onAdded.addListener showUpgradeMessage # Ensure that tabInfoMap is populated when Vimium is installed. chrome.windows.getAll { populate: true }, (windows) -> -- cgit v1.2.3