diff options
| author | Daniel MacDougall | 2012-03-31 21:43:28 -0700 |
|---|---|---|
| committer | Daniel MacDougall | 2012-03-31 21:56:33 -0700 |
| commit | 1e98a59c4954ac73e770da2a8843c2a19f6f252f (patch) | |
| tree | 3a03a1daf34389f05e4d3e578529a345b2f40a42 /background_page.html | |
| parent | c5dfef538d267861a6cfe4f1144823449fbe73b8 (diff) | |
| download | vimium-1e98a59c4954ac73e770da2a8843c2a19f6f252f.tar.bz2 | |
Correctly synchronize icon and active state
Three situations are considered:
1. Active tab is disabled -> disable icon
2. Active tab is enabled and should be enabled -> enable icon
3. Active tab is enabled but should be disabled -> disable icon and disable vimium
Diffstat (limited to 'background_page.html')
| -rw-r--r-- | background_page.html | 35 |
1 files changed, 28 insertions, 7 deletions
diff --git a/background_page.html b/background_page.html index 94389436..8467672e 100644 --- a/background_page.html +++ b/background_page.html @@ -342,15 +342,36 @@ delete framesForTab[tab.id]; } + /* Updates the browserAction icon to indicated whether Vimium is enabled or disabled on the current page. + * Also disables Vimium if it is currently enabled but should be disabled according to the url blacklist. + * This lets you disable Vimium on a page without needing to reload. + * + * Three situations are considered: + * 1. Active tab is disabled -> disable icon + * 2. Active tab is enabled and should be enabled -> enable icon + * 3. Active tab is enabled but should be disabled -> disable icon and disable vimium + */ function updateActiveState(tabId) { if (openTabs[tabId]) { - var isEnabled = isEnabledForUrl({url: openTabs[tabId].url}).isEnabledForUrl; - var iconPath = isEnabled ? "icons/icon48.png" : "icons/icon48disabled.png"; - chrome.browserAction.setIcon({path: iconPath}); - - if (!isEnabled) { - chrome.tabs.connect(tabId, { name: "disableVimium" }).postMessage(); - } + 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"; + + if (isCurrentlyEnabled) { + if (shouldBeEnabled) { + chrome.browserAction.setIcon({ path: enabledIcon }); + } else { + chrome.browserAction.setIcon({ path: disabledIcon }); + chrome.tabs.connect(tabId, { name: "disableVimium" }).postMessage(); + } + } else { + chrome.browserAction.setIcon({ path: disabledIcon }); + } + }); + returnPort.postMessage(); } } |
