Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 8 additions & 3 deletions src/helpers/notificationTimer.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@ const CALENDAR_TIMEOUT_MS = 2 * 60 * 1000;
const MIN_RESUME_MS = 5 * 1000;

function getNotificationTimeoutMs(source) {
return source === "calendar" ? CALENDAR_TIMEOUT_MS : DETECTION_TIMEOUT_MS;
const normSource = typeof source === "string" ? source.trim().toLowerCase() : "";
return normSource === "calendar" ? CALENDAR_TIMEOUT_MS : DETECTION_TIMEOUT_MS;
}

// Auto-dismiss countdown for the meeting notification overlay, pausable while
Expand All @@ -24,7 +25,9 @@ class NotificationDismissTimer {

start(durationMs) {
this.cancel();
this._arm(durationMs);
const validDuration =
Number.isFinite(durationMs) && durationMs > 0 ? durationMs : DETECTION_TIMEOUT_MS;
this._arm(validDuration);
}

pause() {
Expand Down Expand Up @@ -55,7 +58,9 @@ class NotificationDismissTimer {
this._timer = setTimeout(() => {
this._timer = null;
this._deadline = null;
this._onTimeout();
if (typeof this._onTimeout === "function") {
this._onTimeout();
}
}, durationMs);
}
}
Expand Down
23 changes: 23 additions & 0 deletions test/helpers/notificationTimer.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -111,3 +111,26 @@ test("start replaces a running countdown", (t) => {
t.mock.timers.tick(1);
assert.equal(fired, 1);
});

test("getNotificationTimeoutMs supports case-insensitive and trimmed source names", () => {
assert.equal(getNotificationTimeoutMs("Calendar"), 120 * 1000);
assert.equal(getNotificationTimeoutMs(" CALENDAR "), 120 * 1000);
assert.equal(getNotificationTimeoutMs("detection"), 30 * 1000);
assert.equal(getNotificationTimeoutMs(null), 30 * 1000);
assert.equal(getNotificationTimeoutMs(undefined), 30 * 1000);
});

test("NotificationDismissTimer handles invalid duration and missing callback safely", (t) => {
t.mock.timers.enable({ apis: ["setTimeout", "Date"], now: 10_000 });
const noopTimer = new NotificationDismissTimer(null);
noopTimer.start(NaN);
t.mock.timers.tick(35_000);

let fired = 0;
const timer = new NotificationDismissTimer(() => fired++);
timer.start(-100);
t.mock.timers.tick(29_999);
assert.equal(fired, 0);
t.mock.timers.tick(1);
assert.equal(fired, 1);
});
Loading