Merge pull request #91 from pomu0325/support-multiple-windows
support multiple browser windows
This commit is contained in:
@@ -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;
|
||||
|
||||
@@ -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');
|
||||
|
||||
Reference in New Issue
Block a user