mirror of
https://git.undefined-dev.fr/Blendman974/faceclaw.git
synced 2026-11-19 21:03:09 +00:00
Merge notification bulk dismissal
This commit is contained in:
6 files changed
+128
-1
No files matched your search
+12
@@ -504,6 +504,18 @@ class FaceclawMediaNotificationListenerService : NotificationListenerService() {
|
||||
}
|
||||
}
|
||||
|
||||
@JvmStatic
|
||||
fun dismissAllNotifications(): Boolean {
|
||||
val service = activeService ?: return false
|
||||
return try {
|
||||
service.cancelAllNotifications()
|
||||
true
|
||||
} catch (t: Throwable) {
|
||||
Log.w(TAG, "failed to dismiss all notifications", t)
|
||||
false
|
||||
}
|
||||
}
|
||||
|
||||
private fun emitNotificationPosted(key: String?) {
|
||||
emitNotificationEvent(key) { listener, eventKey -> listener.onNotificationPosted(eventKey) }
|
||||
}
|
||||
|
||||
@@ -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()),
|
||||
|
||||
@@ -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) }
|
||||
}
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
# Dismiss all notifications
|
||||
|
||||
The Notifications app menu offers Dismiss all notifications, disabled when the
|
||||
list is empty. This explicit action dismisses notifications on the phone too;
|
||||
popup filtering and source/default preferences remain independent.
|
||||
|
||||
Android uses NotificationListenerService.cancelAllNotifications, so dismissal
|
||||
is not limited to the 50 items displayed by the list and Android controls which
|
||||
notifications are removable. The normal removal callbacks update the list and
|
||||
popups. Missing listener access returns false without changing preferences.
|
||||
iOS uses the existing ANCS dismissal operation on a snapshot of all known keys;
|
||||
notifications without a negative action may remain.
|
||||
|
||||
Software tests cover menu action/disabled state, more than 50 notifications,
|
||||
native bridge dispatch, disconnected access and ANCS bulk dismissal.
|
||||
On a device, verify the permission-granted/revoked cases, protected or ongoing
|
||||
notifications, notification groups, and consistency with the phone's tray.
|
||||
Hardware validation remains pending.
|
||||
|
||||
Reference: https://developer.android.com/reference/android/service/notification/NotificationListenerService#cancelAllNotifications()
|
||||
@@ -0,0 +1,69 @@
|
||||
const test = require('node:test');
|
||||
const assert = require('node:assert/strict');
|
||||
const { loader } = require('./helpers/load-typescript.cjs');
|
||||
|
||||
test('Notifications menu dismisses all, including beyond the visible list, and leaves filters untouched', () => {
|
||||
let options, active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) }));
|
||||
let dismissals = 0, renders = 0, pops = 0;
|
||||
const load = loader({}, {
|
||||
'../../ui/notifications': { NotificationsListLayer: class {} },
|
||||
'../../ui/notification-filter': { NotificationFilterLayer: class {} },
|
||||
'../../native/notification-icons': {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications(max) { assert.equal(max, 0x7fffffff); return active; },
|
||||
dismissAllNotifications() { dismissals++; active = []; return true; },
|
||||
onAndroidNotificationsChanged: () => () => {},
|
||||
},
|
||||
'../../ui/shell/in-process-window': {
|
||||
YieldAtRootLayer: class {},
|
||||
createInProcessWindow(value) { options = value; return { requestRender() { renders++; } }; },
|
||||
},
|
||||
});
|
||||
load('app/apps/notifications/notifications-app.ts').createNotificationsAppWindow({});
|
||||
const items = options.menuItems();
|
||||
assert.equal(items[0].label, 'Notification filter');
|
||||
const action = items.find(x => x.label === 'Dismiss all notifications');
|
||||
assert.equal(action.disabled(), false);
|
||||
assert.equal(dismissals, 0);
|
||||
action.onSelect({ stack: { pop() { pops++; } } });
|
||||
assert.equal(dismissals, 1);
|
||||
assert.equal(pops, 1);
|
||||
assert.equal(renders, 1);
|
||||
assert.equal(action.disabled(), true);
|
||||
});
|
||||
|
||||
test('Android bulk action uses the native listener and propagates unavailable access', () => {
|
||||
let calls = 0, allowed = false;
|
||||
const load = loader({ global: { isAndroid: true }, com: { faceclaw: { app: {
|
||||
FaceclawMediaNotificationListenerService: { dismissAllNotifications() { calls++; return allowed; } },
|
||||
} } } }, {
|
||||
'../graphics/image': {}, './frame-timings': {}, '../util/array-util': {},
|
||||
'./notification-sources': {}, './image-files': {}, './notification-types': { NOTIFICATION_ICON_SIZE: 24 },
|
||||
});
|
||||
const api = load('app/native/notification-icons.ts');
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
allowed = true;
|
||||
assert.equal(api.dismissAllNotifications(), true);
|
||||
assert.equal(calls, 2);
|
||||
});
|
||||
|
||||
test('iOS snapshots all ANCS keys and continues when a notification cannot be dismissed', () => {
|
||||
const load = loader({}, {
|
||||
'../graphics/pebble-icons': {}, '../g2/ancs-client': {}, './notification-app-icons': {}, './notification-sources': {},
|
||||
});
|
||||
const api = load('app/native/notification-icons.ios.ts');
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
const active = Array.from({ length: 80 }, (_, i) => ({ key: String(i) })), attempted = [];
|
||||
api.bindIosNotifications({
|
||||
read(max) { assert.equal(max, api.ALL_NOTIFICATIONS); return active; },
|
||||
dismiss(key) {
|
||||
attempted.push(key);
|
||||
if (key === '1') return false;
|
||||
active.splice(active.findIndex(x => x.key === key), 1);
|
||||
return true;
|
||||
},
|
||||
});
|
||||
assert.equal(api.dismissAllNotifications(), false);
|
||||
assert.equal(attempted.length, 80);
|
||||
assert.deepEqual(active, [{ key: '1' }]);
|
||||
});
|
||||
Reference in new issue
Block a user