From d9a2b6f8cd2b3992a92d3eaf372e129c9cef408f Mon Sep 17 00:00:00 2001 From: Daniel MacDougall Date: Sun, 1 Apr 2012 12:50:40 -0700 Subject: Fix buggy icon update states This requires not depending on the openTabs array, since the onUpdated event is not always fired when a new page is loaded (from a new tab, for example). --- background_page.html | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/background_page.html b/background_page.html index 8467672e..06662cf7 100644 --- a/background_page.html +++ b/background_page.html @@ -352,13 +352,15 @@ * 3. Active tab is enabled but should be disabled -> disable icon and disable vimium */ function updateActiveState(tabId) { - if (openTabs[tabId]) { + var enabledIcon = "icons/icon48.png"; + var disabledIcon = "icons/icon48disabled.png"; + chrome.tabs.get(tabId, function(tab) { + // Default to disabled state in case we can't connect to Vimium, primarily for the "New Tab" page. + chrome.browserAction.setIcon({ path: disabledIcon }); var returnPort = chrome.tabs.connect(tabId, { name: "getActiveState" }); returnPort.onMessage.addListener(function(response) { var isCurrentlyEnabled = response.enabled; - var shouldBeEnabled = isEnabledForUrl({url: openTabs[tabId].url}).isEnabledForUrl; - var enabledIcon = "icons/icon48.png"; - var disabledIcon = "icons/icon48disabled.png"; + var shouldBeEnabled = isEnabledForUrl({url: tab.url}).isEnabledForUrl; if (isCurrentlyEnabled) { if (shouldBeEnabled) { @@ -372,7 +374,7 @@ } }); returnPort.postMessage(); - } + }); } function handleUpdateScrollPosition(request, sender) { -- cgit v1.2.3