Skip to content

Commit 94bce57

Browse files
authored
Merge pull request Stigmatoz#54 from tschettler/fix-current-tab
Fix race condition with setting current tab
2 parents 8131561 + 630730a commit 94bce57

File tree

4 files changed

+16
-17
lines changed

4 files changed

+16
-17
lines changed

src/scripts/activity.js

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -114,11 +114,6 @@ class Activity {
114114
this.addTimeInterval(domain);
115115
}
116116

117-
clearCurrentActiveTab() {
118-
this.closeIntervalForCurrentTab();
119-
currentTab = null;
120-
}
121-
122117
addTimeInterval(domain) {
123118
var item = timeIntervalList.find(o => o.url.isMatch(domain) && o.day == todayLocalDate());
124119
if (item != undefined) {
@@ -136,13 +131,16 @@ class Activity {
136131
}
137132
}
138133

139-
closeIntervalForCurrentTab() {
134+
closeIntervalForCurrentTab(preserveCurrentTab) {
140135
if (currentTab && timeIntervalList != undefined) {
141136
var item = timeIntervalList.find(o => o.url.isMatch(currentTab) && o.day == todayLocalDate());
142137
if (item != undefined)
143138
item.closeInterval();
144139
}
145-
currentTab = null;
140+
141+
if (!preserveCurrentTab) {
142+
currentTab = null;
143+
}
146144
}
147145

148146
isNeedNotifyView(domain, tab){

src/scripts/background.js

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ function backgroundCheck() {
4949
});
5050
} else {
5151
if (tab !== undefined) {
52-
if (currentTab == null || !tab.url.isHostMatch(currentTab.host)) {
52+
if (!tab.url.isMatch(currentTab)) {
5353
activity.setCurrentActiveTab(tab.url);
5454
}
5555
chrome.idle.queryState(parseInt(setting_interval_inactivity), function(state) {
@@ -60,7 +60,7 @@ function backgroundCheck() {
6060
}
6161
}
6262
}
63-
} else activity.closeIntervalForCurrentTab();
63+
} else activity.closeIntervalForCurrentTab(true);
6464
});
6565
}
6666

src/scripts/ui.js

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -98,12 +98,13 @@ class UI {
9898
this.getTableOfSite().appendChild(document.createElement('hr'));
9999
}
100100

101-
setActiveTooltipe(currentTab) {
102-
if (currentTab !== '') {
103-
var element = document.getElementById(currentTab);
101+
setActiveTooltip(currentTab) {
102+
if (!!currentTab) {
103+
const host = currentTab.host;
104+
var element = document.getElementById(host);
104105
if (element !== null) {
105106
var event = new Event("mouseenter");
106-
document.getElementById(currentTab).dispatchEvent(event);
107+
document.getElementById(host).dispatchEvent(event);
107108
}
108109
}
109110
}
@@ -197,7 +198,7 @@ class UI {
197198
var spanUrl = this.createElement('span', ['span-url'], tabUrlString);
198199
spanUrl.setAttribute('href', 'https://' + tabUrlString);
199200

200-
if (currentTab != null && tab.url.isHostMatch(currentTab.host)) {
201+
if (tab.url.isMatch(currentTab)) {
201202
var divForImage = document.createElement('div');
202203
div.classList.add('span-active-url');
203204
var imgCurrentDomain = document.createElement('img');

src/scripts/webact.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -249,7 +249,7 @@ function getTabsFromStorage(tabs) {
249249

250250
summaryCounter += counter;
251251

252-
const targetTab = tabGroup.tabs[0];
252+
const targetTab = tabGroup.tabs.find(t => t.url.isMatch(currentTab)) || tabGroup.tabs[0];
253253

254254
if (
255255
currentTypeOfList === TypeListEnum.ToDay ||
@@ -271,7 +271,7 @@ function getTabsFromStorage(tabs) {
271271
ui.addHrAfterTableOfSite();
272272
ui.createTotalBlock(totalTime, currentTypeOfList, summaryCounter);
273273
ui.drawChart(tabsForChart);
274-
ui.setActiveTooltipe(currentTab);
274+
ui.setActiveTooltip(currentTab);
275275

276276
ui.removePreloader();
277277
}
@@ -576,7 +576,7 @@ function getTabsFromStorageByDay(day, blockName) {
576576
for (const tabGroup of tabGroups){
577577
var summaryTime = tabGroup.summaryTime;
578578
var counter = tabGroup.counter;
579-
const targetTab = tabGroup.tabs[0];
579+
const targetTab = tabGroup.tabs.find(t => t.url.isMatch(currentTab)) || tabGroup.tabs[0];
580580

581581
ui.addLineToTableOfSite(targetTab, currentTab, summaryTime, TypeListEnum.ByDays, counter, blockName + '_content');
582582
}

0 commit comments

Comments
 (0)