From d43ad64aab701371056dc36e8b5004221c501e2b Mon Sep 17 00:00:00 2001 From: pomu0325 Date: Mon, 24 Aug 2020 12:22:17 +0900 Subject: [PATCH] support multiple windows --- assets/js/core/WakaTimeCore.js | 3 ++- assets/js/events.js | 17 ++++++++++++++++- 2 files changed, 18 insertions(+), 2 deletions(-) diff --git a/assets/js/core/WakaTimeCore.js b/assets/js/core/WakaTimeCore.js index 8391426..55b0b39 100644 --- a/assets/js/core/WakaTimeCore.js +++ b/assets/js/core/WakaTimeCore.js @@ -89,7 +89,8 @@ class WakaTimeCore { browser.idle.queryState(config.detectionIntervalInSeconds).then((newState) => { if (newState === 'active') { // Get current tab URL. - browser.tabs.query({active: true}).then((tabs) => { + browser.tabs.query({currentWindow: true, active: true}).then((tabs) => { + if (tabs.length == 0) return; var currentActiveTab = tabs[0]; var debug = false; diff --git a/assets/js/events.js b/assets/js/events.js index f500308..3652e7e 100644 --- a/assets/js/events.js +++ b/assets/js/events.js @@ -39,6 +39,21 @@ browser.tabs.onActivated.addListener(function (activeInfo) { }); +/** + * Whenever a active window is changed it records a heartbeat with the active tab url. + */ +browser.windows.onFocusChanged.addListener(function (windowId) { + + if (windowId != browser.windows.WINDOW_ID_NONE) { + console.log('recording a heartbeat - active window changed'); + + wakatime.recordHeartbeat(); + } else { + console.log('lost focus'); + } + +}); + /** * Whenever any tab is updated it checks if the updated tab is the tab that is * currently active and if it is, then it records a heartbeat. @@ -47,7 +62,7 @@ browser.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { if (changeInfo.status === 'complete') { // Get current tab URL. - browser.tabs.query({active: true}).then(function(tabs) { + browser.tabs.query({currentWindow: true, active: true}).then(function(tabs) { // If tab updated is the same as active tab if (tabId == tabs[0].id) { console.log('recording a heartbeat - tab updated');