[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. */
+2
View File
@@ -75,6 +75,7 @@ import { ShellModalLayer } from "./modal-layer";
import { NotificationModalQueue } from "./notification-modal-queue";
import { NotificationPopupTimeout } from "./notification-popup-timeout";
import { ALL_NOTIFICATIONS, readActiveNotifications } from "../../native/notification-icons";
import { isPhoneDoNotDisturbEnabled } from "../../native/phone-do-not-disturb";
import { ToolDebugMenuLayer } from "./tool-debug-layer";
import type { InProcessWindow } from "./in-process-window";
import { BrightnessPickerLayer } from "./brightness-picker-layer";
@@ -939,6 +940,7 @@ class Shell {
* shown: in the notification modal, waking the screen for it if it was off.
*/
postAppNotification(notification: AppNotification): void {
if (!this.screenOn && isPhoneDoNotDisturbEnabled()) return;
this.appNotifications.set(notification.key, notification);
const wokeScreen = this.screenOn ? false : this.wake("sidebar");
this.openNotificationModal(notification.key, wokeScreen);