Skip to content

Commit 026ae5b

Browse files
committed
fix(core): prevent time tracking when limit is zero and apply live time settings
1 parent 1f3be38 commit 026ae5b

2 files changed

Lines changed: 24 additions & 6 deletions

File tree

src/app/orchestrator.ts

Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,10 @@ export class AppOrchestrator {
4141
let limit = await storage.getLimit(pId);
4242
const initialCount = await storage.getCount(pId);
4343
let isLimitEnabled = await storage.getEnableLimit(pId);
44-
const timeLimitMins = await storage.getTimeLimit(pId);
45-
const timeSpentMs = await storage.getTimeSpent(pId);
46-
const isTimeEnabled = await storage.getEnableTime(pId);
44+
45+
let timeLimitMins = await storage.getTimeLimit(pId);
46+
let timeSpentMs = await storage.getTimeSpent(pId);
47+
let isTimeEnabled = await storage.getEnableTime(pId);
4748

4849
const limiter = new Limiter(
4950
{ limit: isLimitEnabled ? limit : 0 },
@@ -67,16 +68,31 @@ export class AppOrchestrator {
6768
}
6869
limiter.setLimit(isLimitEnabled ? limit : 0);
6970
}
71+
7072
if (changes[`limitra_${pId}_count`]) {
7173
const newVal = Number(changes[`limitra_${pId}_count`].newValue) || 0;
7274
limiter.setInitialCount(newVal);
7375
if (isLimitEnabled && limit > 0 && newVal >= limit) {
7476
void safeBlock('count');
7577
}
7678
}
79+
80+
if (changes[`limitra_${pId}_time_limit`] || changes[`limitra_${pId}_enable_time`]) {
81+
if (changes[`limitra_${pId}_time_limit`]) {
82+
timeLimitMins = Number(changes[`limitra_${pId}_time_limit`].newValue) || 0;
83+
}
84+
if (changes[`limitra_${pId}_enable_time`]) {
85+
isTimeEnabled = Boolean(changes[`limitra_${pId}_enable_time`].newValue);
86+
}
87+
88+
if (isTimeEnabled && timeLimitMins > 0 && timeSpentMs >= timeLimitMins * 60 * 1000) {
89+
void safeBlock('time');
90+
}
91+
}
92+
7793
if (changes[`limitra_${pId}_time_spent`]) {
78-
const newTime = Number(changes[`limitra_${pId}_time_spent`].newValue) || 0;
79-
if (isTimeEnabled && timeLimitMins > 0 && newTime >= timeLimitMins * 60 * 1000) {
94+
timeSpentMs = Number(changes[`limitra_${pId}_time_spent`].newValue) || 0;
95+
if (isTimeEnabled && timeLimitMins > 0 && timeSpentMs >= timeLimitMins * 60 * 1000) {
8096
void safeBlock('time');
8197
}
8298
}

src/core/session.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,9 @@ export class SessionManager {
8989
if (document.hidden) return;
9090

9191
const isTimeEnabled = await storage.getEnableTime(this.adapter.id);
92-
if (!isTimeEnabled) {
92+
const timeLimit = await storage.getTimeLimit(this.adapter.id);
93+
94+
if (!isTimeEnabled || timeLimit <= 0) {
9395
await this.stopTracking();
9496
return;
9597
}

0 commit comments

Comments
 (0)