support multiple windows

This commit is contained in:
pomu0325
2020-08-24 12:22:17 +09:00
parent f0b8dd7a08
commit d43ad64aab
2 changed files with 18 additions and 2 deletions

View File

@@ -89,7 +89,8 @@ class WakaTimeCore {
browser.idle.queryState(config.detectionIntervalInSeconds).then((newState) => { browser.idle.queryState(config.detectionIntervalInSeconds).then((newState) => {
if (newState === 'active') { if (newState === 'active') {
// Get current tab URL. // 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 currentActiveTab = tabs[0];
var debug = false; var debug = false;

View File

@@ -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 * 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. * 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') { if (changeInfo.status === 'complete') {
// Get current tab URL. // 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 tab updated is the same as active tab
if (tabId == tabs[0].id) { if (tabId == tabs[0].id) {
console.log('recording a heartbeat - tab updated'); console.log('recording a heartbeat - tab updated');