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

@@ -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');