Skip to content

Commit 74939f3

Browse files
Merge pull request #5 from Nyanraltotlapun/master
Fixing stop of time tracking in background problem.
2 parents 18a177d + a670eb5 commit 74939f3

File tree

3 files changed

+27
-4
lines changed

3 files changed

+27
-4
lines changed

src/extension/manifest_chrome.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Time Tracker",
4-
"version": "1.1",
4+
"version": "1.2",
55

66
"author": "Anna Molodtsova and Kirill Shakirov",
77

src/extension/manifest_firefox.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"manifest_version": 3,
33
"name": "Time Tracker",
4-
"version": "1.1",
4+
"version": "1.2",
55

66
"author": "Anna Molodtsova and Kirill Shakirov",
77

src/extension/window/window.js

Lines changed: 25 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,8 @@ function main() {
6969
}
7070
}
7171

72+
73+
7274
/*
7375
Params: db object
7476
Function initialises addNewTracker() function by clicking the add button (id="add-button")
@@ -142,10 +144,11 @@ function main() {
142144

143145

144146
function addCard(id, title, c_time, db) {
147+
145148
let card = document.getElementById("counter_tmpl").content.firstElementChild.cloneNode(true);
146-
console.debug("Calculated card ID ", ("db_id" + id));
149+
//console.debug("Calculated card ID ", ("db_id" + id));
147150
card.id = "db_id" + id;
148-
console.debug("Creating card ID ", card.id);
151+
//console.debug("Creating card ID ", card.id);
149152

150153
let counter = 0;
151154
let subtotal_time = c_time;
@@ -168,6 +171,25 @@ function main() {
168171
let timer_running = false;
169172
let intervalId = null;
170173

174+
let hide_time = 0;
175+
let hide_counter_state = 0;
176+
let hide_subtotal_time_state = 0;
177+
178+
let on_visibility_change = () => {
179+
if (document.hidden) {
180+
hide_time = Date.now();
181+
hide_counter_state = counter;
182+
hide_subtotal_time_state = subtotal_time;
183+
}
184+
else if (timer_running) {
185+
let elapsed_sec = Math.trunc((Date.now() - hide_time) / 1000);
186+
counter += elapsed_sec;
187+
subtotal_time += elapsed_sec;
188+
}
189+
}
190+
191+
document.addEventListener("visibilitychange", on_visibility_change);
192+
171193
cb_start_pause.onclick = () => {
172194
if (timer_running === false) {
173195
timer_running = true;
@@ -213,6 +235,7 @@ function main() {
213235
}
214236

215237
cb_remove.onclick = () => {
238+
document.removeEventListener("visibilitychange", on_visibility_change);
216239
clearInterval(intervalId);
217240
removeTracker(id, db);
218241
}

0 commit comments

Comments
 (0)