diff options
| author | Stephen Blott | 2015-04-03 10:13:56 +0100 | 
|---|---|---|
| committer | Stephen Blott | 2015-04-03 10:13:56 +0100 | 
| commit | 58512fd855e41d80cdcd75b1261ee967c78391e4 (patch) | |
| tree | ec66666c6115b82fbb7bfebffa41c1c29e8774a5 | |
| parent | bfa8eb3ee2985064895e3bb7b92f135399c403af (diff) | |
| parent | 96785e861791be89cd4cf98b90c76efa60eaf803 (diff) | |
| download | vimium-58512fd855e41d80cdcd75b1261ee967c78391e4.tar.bz2 | |
Merge branch 'upgrade-notification'
| -rw-r--r-- | background_scripts/main.coffee | 54 | ||||
| -rw-r--r-- | content_scripts/vimium_frontend.coffee | 30 | ||||
| -rw-r--r-- | manifest.json | 1 | 
3 files changed, 27 insertions, 58 deletions
| diff --git a/background_scripts/main.coffee b/background_scripts/main.coffee index f70cd8f3..72fe1092 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 @@ -70,14 +70,8 @@ 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]) -)  chrome.runtime.onMessage.addListener((request, sender, sendResponse) ->    if (sendRequestHandlers[request.handler]) @@ -184,14 +178,6 @@ 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.  # @@ -613,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 })) @@ -662,7 +638,6 @@ sendRequestHandlers =    unregisterFrame: unregisterFrame    frameFocused: handleFrameFocused    nextFrame: (request) -> BackgroundCommands.nextFrame 1, request.frameId -  upgradeNotificationClosed: upgradeNotificationClosed    updateScrollPosition: handleUpdateScrollPosition    copyToClipboard: copyToClipboard    pasteFromClipboard: pasteFromClipboard @@ -701,8 +676,30 @@ if Settings.has("keyMappings")  populateValidFirstKeys()  populateSingleKeyCommands() -if shouldShowUpgradeMessage() -  sendRequestToAllTabs({ name: "showUpgradeNotification", version: currentVersion }) + +# Show notification on upgrade. +showUpgradeMessage = -> +  # 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" +      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 +    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) -> @@ -715,3 +712,4 @@ chrome.windows.getAll { populate: true }, (windows) ->  # Start pulling changes from synchronized storage.  Sync.init() +showUpgradeMessage() diff --git a/content_scripts/vimium_frontend.coffee b/content_scripts/vimium_frontend.coffee index 2c157978..dec34774 100644 --- a/content_scripts/vimium_frontend.coffee +++ b/content_scripts/vimium_frontend.coffee @@ -165,8 +165,6 @@ initializePreDomReady = ->      window.removeEventListener "focus", onFocus    requestHandlers = -    hideUpgradeNotification: -> HUD.hideUpgradeNotification() -    showUpgradeNotification: (request) -> HUD.showUpgradeNotification(request.version)      showHUDforDuration: (request) -> HUD.showForDuration request.text, request.duration      toggleHelpDialog: (request) -> toggleHelpDialog(request.dialogHtml, request.frameId)      focusFrame: (request) -> if (frameId == request.frameId) then focusThisFrame(request.highlight) @@ -1070,7 +1068,6 @@ toggleHelpDialog = (html, fid) ->  HUD =    _tweenId: -1    _displayElement: null -  _upgradeNotificationElement: null    # This HUD is styled to precisely mimick the chrome HUD on Mac. Use the "has_popup_and_link_hud.html"    # test harness to tweak these styles to match Chrome's. One limitation of our HUD display is that @@ -1088,26 +1085,6 @@ HUD =      HUD._tweenId = Tween.fade(HUD.displayElement(), 1.0, 150)      HUD.displayElement().style.display = "" -  showUpgradeNotification: (version) -> -    HUD.upgradeNotificationElement().innerHTML = "Vimium has been upgraded to #{version}. See -      <a class='vimiumReset' target='_blank' -      href='https://github.com/philc/vimium#release-notes'> -      what's new</a>.<a class='vimiumReset close-button' href='#'>×</a>" -    links = HUD.upgradeNotificationElement().getElementsByTagName("a") -    links[0].addEventListener("click", HUD.onUpdateLinkClicked, false) -    links[1].addEventListener "click", (event) -> -      event.preventDefault() -      HUD.onUpdateLinkClicked() -    Tween.fade(HUD.upgradeNotificationElement(), 1.0, 150) - -  onUpdateLinkClicked: (event) -> -    HUD.hideUpgradeNotification() -    chrome.runtime.sendMessage({ handler: "upgradeNotificationClosed" }) - -  hideUpgradeNotification: (clickEvent) -> -    Tween.fade(HUD.upgradeNotificationElement(), 0, 150, -      -> HUD.upgradeNotificationElement().style.display = "none") -    #    # Retrieves the HUD HTML element.    # @@ -1118,13 +1095,6 @@ HUD =        HUD._displayElement.style.right = "150px"      HUD._displayElement -  upgradeNotificationElement: -> -    if (!HUD._upgradeNotificationElement) -      HUD._upgradeNotificationElement = HUD.createHudElement() -      # Position this just to the left of our normal HUD. -      HUD._upgradeNotificationElement.style.right = "315px" -    HUD._upgradeNotificationElement -    createHudElement: ->      element = document.createElement("div")      element.className = "vimiumReset vimiumHUD" diff --git a/manifest.json b/manifest.json index beb68530..4ba222fb 100644 --- a/manifest.json +++ b/manifest.json @@ -27,6 +27,7 @@      "clipboardRead",      "storage",      "sessions", +    "notifications",      "<all_urls>"    ],    "content_scripts": [ | 
