From 01e720e10400d208627b593d3d539b87d89902d0 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sun, 21 Feb 2016 01:05:47 +0800 Subject: 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. --- background_scripts/bg_utils.coffee | 7 +++++++ 1 file changed, 7 insertions(+) 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 -- cgit v1.2.3 From 2af20933795a1c9f6ff5d081822f9077d9183d50 Mon Sep 17 00:00:00 2001 From: gdh1995 Date: Sun, 21 Feb 2016 01:20:46 +0800 Subject: fix a crash of unit tests --- CREDITS | 1 + tests/unit_tests/test_chrome_stubs.coffee | 2 ++ 2 files changed, 3 insertions(+) diff --git a/CREDITS b/CREDITS index e05a1c6a..b11497ca 100644 --- a/CREDITS +++ b/CREDITS @@ -44,5 +44,6 @@ Contributors: Shiyong Chen (github: UncleBill) Utkarsh Upadhyay (github: PrestanceDesign) + Dahan Gong (github: gdh1995) Feel free to add real names in addition to GitHub usernames. diff --git a/tests/unit_tests/test_chrome_stubs.coffee b/tests/unit_tests/test_chrome_stubs.coffee index 8b816cd4..bbcd01e7 100644 --- a/tests/unit_tests/test_chrome_stubs.coffee +++ b/tests/unit_tests/test_chrome_stubs.coffee @@ -60,6 +60,8 @@ exports.chrome = onRemoved: addListener: () -> true getAll: () -> true + onFocusChanged: + addListener: () -> true browserAction: setBadgeBackgroundColor: -> -- cgit v1.2.3 From 041b441073be2a554af94b23ea16535391cc1f29 Mon Sep 17 00:00:00 2001 From: Stephen Blott Date: Sat, 20 Feb 2016 17:23:37 +0000 Subject: Tweak #2007. --- background_scripts/bg_utils.coffee | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/background_scripts/bg_utils.coffee b/background_scripts/bg_utils.coffee index 6ae1e9cb..ca042686 100644 --- a/background_scripts/bg_utils.coffee +++ b/background_scripts/bg_utils.coffee @@ -18,12 +18,10 @@ 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 + chrome.windows.onFocusChanged.addListener (wnd) => + if wnd != chrome.windows.WINDOW_ID_NONE + chrome.tabs.query {windowId: wnd, active: true}, (tabs) => + @register tabs[0].id if tabs[0] register: (tabId) -> currentTime = new Date() -- cgit v1.2.3