Skip to content

Commit 558099c

Browse files
committed
fix start timer
1 parent 11b92f6 commit 558099c

File tree

1 file changed

+15
-13
lines changed

1 file changed

+15
-13
lines changed

scripts/background.js

Lines changed: 15 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,22 +14,24 @@ function updateStorage() {
1414

1515
function backgroundCheck() {
1616
chrome.windows.getLastFocused({ populate: true }, function (currentWindow) {
17-
if (tabs.length > 0) {
18-
var activeTab = currentWindow.tabs.find(o => o.active === true);
19-
if (activeTab !== undefined) {
17+
if (currentWindow.focused) {
18+
var activeTab = currentWindow.tabs.find(t => t.active === true);
19+
if (activeTab !== undefined && activity.isValidPage(activeTab)) {
2020
var activeUrl = activity.extractHostname(activeTab.url);
2121
var tab = activity.getTab(activeUrl);
22-
if (tab !== undefined) {
23-
chrome.idle.queryState(SETTINGS_INTERVAL_INACTIVITY, function (state) {
24-
if (state === 'active') {
25-
tab.summaryTime += 1;
26-
chrome.browserAction.setBadgeText({
27-
tabId: activeTab.id,
28-
text: String(convertSummaryTimeToString(tab.summaryTime))
29-
});
30-
}
31-
});
22+
if (tab === undefined) {
23+
activity.addTab(activeTab);
3224
}
25+
26+
chrome.idle.queryState(SETTINGS_INTERVAL_INACTIVITY, function (state) {
27+
if (state === 'active') {
28+
tab.summaryTime += 1;
29+
chrome.browserAction.setBadgeText({
30+
tabId: activeTab.id,
31+
text: String(convertSummaryTimeToString(tab.summaryTime))
32+
});
33+
}
34+
});
3335
}
3436
}
3537
});

0 commit comments

Comments
 (0)