Merge notification display filtering

This commit is contained in:
Blendman974 committed 2026-11-07 21:13:02 +01:00
commit 1eee926cbe
7 files changed
+86 -16

No files matched your search

+9 -1
View File
@@ -9,7 +9,7 @@ const generator = require('../scripts/generate-pebble-icons.cjs');
function setup(notifications) {
const load = loader({}, {
'../g2/ancs-client': { AncsClient: class {}, ANCS_CONNECT_MESSAGE: '' },
'./notification-sources': { rememberNotificationSources() {} },
'./notification-sources': { rememberNotificationSources() {}, shouldShowNotificationOnGlasses: packageName => packageName !== "muted" },
});
const icons = load('app/native/notification-icons.ios.ts');
icons.bindIosNotifications({ read: () => notifications });
@@ -106,3 +106,11 @@ test('the icon generator inverts Pebble art: black ink lights up, white fills hi
const decoded = loader({}, { './pebble-icons-data': loader({}, {})(dataFile) })('app/graphics/pebble-icons.ts').pebbleIcon('probe');
assert.deepEqual([...decoded.pixels], [...pixels]);
});
test('muted sources are hidden before list and icon limits without removing phone notifications', () => {
const notifications = [notification('hidden', 'muted', '0'), notification('shown', 'allowed', '0')];
const { icons } = setup(notifications);
assert.deepEqual([...icons.readVisibleNotifications(1)].map(n => n.key), ['shown']);
assert.deepEqual([...icons.readActiveNotificationIcons(1, false).keys], ['shown']);
assert.equal(icons.readActiveNotifications(10).length, 2);
});
+31
View File
@@ -70,6 +70,7 @@ function ui(fontSize = 12) {
const native = {
ALL_NOTIFICATIONS: 0x7fffffff,
readActiveNotifications: () => { prefs.rememberNotificationSources(active); return active; },
readVisibleNotifications: () => { prefs.rememberNotificationSources(active); return active.filter(n => prefs.shouldShowNotificationOnGlasses(n.packageName)); },
dismissNotification: () => { dismissals++; active = []; return true; },
readNotificationIconByKey: () => ({ icon: null, stale: false }),
};
@@ -317,3 +318,33 @@ test('controller filters before waking or opening a popup, and still refreshes t
elapse();
assert.equal(popups, 1);
});
test('Android display filters before limits and reapplies preferences to cached tray icons', () => {
const prefs = store();
const active = [{ ...mail, key: 'hidden' }, { packageName: 'allowed', appName: 'Allowed', key: 'shown' }];
const file = ts.createSourceFile('icons.ts', source('app/native/notification-icons.ts'), ts.ScriptTarget.Latest, true);
const functions = file.statements.filter(node => ts.isFunctionDeclaration(node) &&
['readVisibleNotifications', 'cachedIconsResult'].includes(node.name?.text)).map(node => node.getText(file));
const { readVisibleNotifications, cachedIconsResult } = evaluate(functions.join('\n') + '\nexport { cachedIconsResult };', null, {
ALL_NOTIFICATIONS: 0x7fffffff,
readActiveNotifications: () => { prefs.rememberNotificationSources(active); return active; },
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
cachedKeys: ['hidden', 'shown'],
cachedPackages: new Map(active.map(n => [n.key, n.packageName])),
cachedIcons: [{ clone: () => 'mail-icon' }, { clone: () => 'allowed-icon' }],
});
prefs.setNotificationSourceEnabled(mail, false);
assert.deepEqual(Array.from(readVisibleNotifications(1), n => n.key), ['shown']);
for (const stale of [false, true]) {
const result = cachedIconsResult(1, stale);
assert.deepEqual(Array.from(result.keys), ['shown']);
assert.deepEqual(Array.from(result.icons), ['allowed-icon']);
assert.equal(result.stale, stale);
}
prefs.setAllNotificationSourcesEnabled(false);
assert.equal(cachedIconsResult(10, false).keys.length, 0);
assert.equal(readVisibleNotifications(50).length, 0);
prefs.setNotificationSourceEnabled(mail, true);
assert.deepEqual(Array.from(cachedIconsResult(1, false).keys), ['hidden']);
assert.equal(active.length, 2);
});