[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

+16 -8
View File
@@ -26,7 +26,7 @@ let cachedAtMs = 0;
const keyedIconCache = new Map<string, { icon: GrayImage | null; atMs: number }>();
const KEYED_ICON_CACHE_MAX = 128;
let notificationListenerProxy: any = null;
const notificationPostedListeners = new Set<(notificationKey: string) => void>();
const notificationPostedListeners = new Set<(notificationKey: string, canWakeScreen?: boolean) => void>();
const notificationRemovedListeners = new Set<(notificationKey: string) => void>();
let listenerStateObserver: any = null;
const listenerStateListeners = new Set<() => void>();
@@ -358,7 +358,7 @@ export function dismissAllNotifications(): boolean {
return Boolean(com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissAllNotifications());
}
export function onAndroidNotificationPosted(listener: (notificationKey: string) => void): () => void {
export function onAndroidNotificationPosted(listener: (notificationKey: string, canWakeScreen?: boolean) => void): () => void {
return addNotificationListener(notificationPostedListeners, listener);
}
@@ -412,8 +412,8 @@ function onListenerStateChanged(listener: () => void): () => void {
}
function addNotificationListener(
listeners: Set<(notificationKey: string) => void>,
listener: (notificationKey: string) => void,
listeners: Set<(notificationKey: string, canWakeScreen?: boolean) => void>,
listener: (notificationKey: string, canWakeScreen?: boolean) => void,
): () => void {
listeners.add(listener);
ensureNativeNotificationListener();
@@ -458,8 +458,8 @@ function normalizeNotification(value: any): AndroidNotification | null {
function ensureNativeNotificationListener(): void {
if (!global.isAndroid || notificationListenerProxy) return;
notificationListenerProxy = new com.faceclaw.app.FaceclawNotificationListener({
onNotificationPosted: (notificationKey: string) => {
dispatchNotificationEvent(notificationPostedListeners, notificationKey);
onNotificationPosted: (notificationKey: string, canWakeScreen?: boolean) => {
dispatchNotificationEvent(notificationPostedListeners, notificationKey, canWakeScreen);
},
onNotificationRemoved: (notificationKey: string) => {
dispatchNotificationEvent(notificationRemovedListeners, notificationKey);
@@ -470,13 +470,21 @@ function ensureNativeNotificationListener(): void {
);
}
function dispatchNotificationEvent(listeners: Set<(notificationKey: string) => void>, notificationKey: string): void {
function dispatchNotificationEvent(
listeners: Set<(notificationKey: string, canWakeScreen?: boolean) => void>,
notificationKey: string,
canWakeScreen = true,
): void {
invalidateIconCaches();
const key = String(notificationKey);
const snapshot = Array.from(listeners);
setTimeout(() => {
for (const listener of snapshot) {
listener(key);
if (listeners === notificationPostedListeners) {
listener(key, canWakeScreen);
} else {
listener(key);
}
}
}, 0);
}
+15
View File
@@ -0,0 +1,15 @@
import { Utils } from "@nativescript/core";
declare const com: any;
/** Read the phone's current interruption filter; never change its DND policy. */
export function isPhoneDoNotDisturbEnabled(): boolean {
if (!global.isAndroid) return false;
try {
return Boolean(com.faceclaw.app.FaceclawMediaNotificationListenerService.isPhoneDoNotDisturbEnabled(
Utils.android.getApplicationContext(),
));
} catch {
return false;
}
}