feat: dismiss all notifications from the app menu

This commit is contained in:
Blendman974 committed 2026-11-06 03:19:58 +01:00
1 parent 62ae01a4f1
commit 3124ae852a
6 files changed
+128 -1

No files matched your search

+10 -1
View File
@@ -1,6 +1,6 @@
import { NotificationsListLayer } from "../../ui/notifications";
import { NotificationFilterLayer } from "../../ui/notification-filter";
import { onAndroidNotificationsChanged } from "../../native/notification-icons";
import { ALL_NOTIFICATIONS, dismissAllNotifications, onAndroidNotificationsChanged, readActiveNotifications } from "../../native/notification-icons";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -32,6 +32,15 @@ export function createNotificationsAppWindow(options: InProcessAppOptions): InPr
ctx.stack.pop();
ctx.stack.push(new NotificationFilterLayer());
},
}, {
label: "Dismiss all notifications",
description: "Dismiss notifications on the phone and glasses. System-protected notifications may remain.",
disabled: () => readActiveNotifications(ALL_NOTIFICATIONS).length === 0,
onSelect: (ctx) => {
ctx.stack.pop();
dismissAllNotifications();
created.requestRender();
},
}],
actions: options.actions,
baseLayer: new YieldAtRootLayer(new NotificationsListLayer()),
+10
View File
@@ -26,6 +26,16 @@ export function iosNotificationState(): AncsState { return active?.state ?? 'dis
export function readActiveNotifications(maxNotifications = 50) { return active?.read(maxNotifications) ?? [] }
export function invokeNotificationAction(key: string, index: number): boolean { return active?.action(key,index) ?? false }
export function dismissNotification(key: string): boolean { return active?.dismiss(key) ?? false }
export function dismissAllNotifications(): boolean {
const client = active
if (!client) return false
// Snapshot: removals may arrive while dismissal requests are being sent.
let accepted = true
for (const notification of [...client.read(ALL_NOTIFICATIONS)]) {
if (!client.dismiss(notification.key)) accepted = false
}
return accepted
}
export function onAndroidNotificationPosted(listener: (key: string) => void): () => void {
listeners.add(listener); return () => { listeners.delete(listener) }
}
+7
View File
@@ -337,6 +337,13 @@ export function dismissNotification(notificationKey: string): boolean {
);
}
/** Explicit user action: dismiss on the phone as well as on the glasses. */
export function dismissAllNotifications(): boolean {
if (!global.isAndroid) return false;
invalidateIconCaches();
return Boolean(com.faceclaw.app.FaceclawMediaNotificationListenerService.dismissAllNotifications());
}
export function onAndroidNotificationPosted(listener: (notificationKey: string) => void): () => void {
return addNotificationListener(notificationPostedListeners, listener);
}