aboutsummaryrefslogtreecommitdiffstats
path: root/background_scripts
diff options
context:
space:
mode:
authorgdh19952016-02-21 01:05:47 +0800
committergdh19952016-02-21 01:05:48 +0800
commit01e720e10400d208627b593d3d539b87d89902d0 (patch)
tree04cd85df9f26f7a13faaafe555887c81938e751b /background_scripts
parent4244dc029540e941b8ab999365b9851dfdf0f32a (diff)
downloadvimium-01e720e10400d208627b593d3d539b87d89902d0.tar.bz2
use chrome.windows.onFocusChanged to listen window switching
This fix the problem that `chrome.tabs.onActivated` won't be triggered when we switch Chrome windows.
Diffstat (limited to 'background_scripts')
-rw-r--r--background_scripts/bg_utils.coffee7
1 files changed, 7 insertions, 0 deletions
diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee
index 96c1282a..6ae1e9cb 100644
--- a/background_scripts/bg_utils.coffee
+++ b/background_scripts/bg_utils.coffee
@@ -18,6 +18,13 @@ class TabRecency
@deregister removedTabId
@register addedTabId
+ self = @
+ chrome.windows.onFocusChanged.addListener (wnd) ->
+ return if wnd == chrome.windows.WINDOW_ID_NONE
+ chrome.tabs.query {windowId: wnd, active: true}, (tabs) ->
+ self.register tabs[0].id if tabs[0]
+ chrome.runtime.lastError
+
register: (tabId) ->
currentTime = new Date()
# Register tabId if it has been visited for at least @timeDelta ms. Tabs which are visited only for a