[verified] feat: follow phone Do Not Disturb for notification wake

This commit is contained in:
MasterControl committed 2026-11-11 17:43:35 +00:00
1 parent 54ba6b4f10
commit 9ca3574ae7
14 files changed
+574 -20

No files matched your search

+9 -5
View File
@@ -33,11 +33,11 @@ export const scheduleTimeout: ScheduleFn = (run, delayMs) => {
};
export class NotificationPopupDelay {
private readonly pending = new Map<string, { dueAtMs: number; cancel: () => void }>();
private readonly pending = new Map<string, { dueAtMs: number; cancel: () => void; wakePolicy: { canWakeScreen: boolean } }>();
/** `ready` receives each notification that survived its delay, to re-check and pop up. */
constructor(
private readonly ready: (notificationKey: string) => void,
private readonly ready: (notificationKey: string, canWakeScreen: boolean) => void,
private readonly schedule: ScheduleFn = scheduleTimeout,
private readonly now: () => number = Date.now,
) {}
@@ -49,18 +49,22 @@ export class NotificationPopupDelay {
* foreground-service placeholder into a real message (same key) gets the
* shorter delay.
*/
post(notificationKey: string, delayMs: number): void {
post(notificationKey: string, delayMs: number, canWakeScreen = true): void {
const dueAtMs = this.now() + delayMs;
const existing = this.pending.get(notificationKey);
// Share this object with an existing timer: a repost may restrict wake,
// but cannot turn a DND-silenced pending notification into a fresh alert.
const wakePolicy = existing?.wakePolicy ?? { canWakeScreen: true };
wakePolicy.canWakeScreen = wakePolicy.canWakeScreen && canWakeScreen;
if (existing) {
if (existing.dueAtMs <= dueAtMs) return;
existing.cancel();
}
const cancel = this.schedule(() => {
this.pending.delete(notificationKey);
this.ready(notificationKey);
this.ready(notificationKey, wakePolicy.canWakeScreen);
}, delayMs);
this.pending.set(notificationKey, { dueAtMs, cancel });
this.pending.set(notificationKey, { dueAtMs, cancel, wakePolicy });
}
/** The notification went away before popping up; returns whether it was waiting. */