Add option to auto-dismiss notifications after a timer

This commit is contained in:
James Babcock committed 2026-11-07 21:06:16 -08:00
1 parent 9ba5c1988d
commit 448a057d2d
15 files changed
+329 -30

No files matched your search

+1
View File
@@ -283,6 +283,7 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
'../notifications': {}, '../dashboard-settings': settings, './ambient-cards': {},
'./chrome-layer': { ShellChromeLayer: class {} }, './modal-layer': {}, './tool-debug-layer': {},
'./brightness-picker-layer': {}, './notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts', {}),
'./notification-popup-timeout': {},
'../../native/notification-icons': {}, '../../native/notification-sources': {},
'../../assistant/tool-registry': {}, './geometry': {
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
@@ -73,6 +73,7 @@ function settingsEnv(initialUrl = '', initialModel = 'openai-compatible') {
openSettingsSubMenu() {},
},
'../font-picker': { uiFontPickerMenuItem: () => ({ label: 'Font' }) },
'../notification-filter': { NotificationFilterLayer: class {} },
'../openai-compatible-model-picker': {
compatibleModelDiscoveryMenuItem: () => ({ label: 'Discover models' }),
},
+51 -2
View File
@@ -23,6 +23,41 @@ function store(settings = new Map()) {
}
const mail = { packageName: 'com.mail', appName: 'Mail' };
/** dashboard-settings.ts over the same in-memory store, with `prefs` as its notification-sources. */
function dashboardSettings(settings, prefs) {
return evaluate(source('app/ui/dashboard-settings.ts'), (id) => {
if (id.includes('settings-store')) return {
onSettingsStoreChanged() {}, getStringSetting: (key, fallback) => settings.get(key) ?? fallback,
setStringSetting: (key, value) => settings.set(key, value),
getBooleanSetting: (key, fallback) => settings.get(key) ?? fallback, setBooleanSetting: (key, value) => settings.set(key, value),
};
if (id.includes('notification-sources')) return prefs;
if (id.includes('brightness-curve')) return require('../.test-build/app/g2/brightness-curve.js');
if (id.includes('animation-speed')) return require('../.test-build/app/ui/animation-speed.js');
return { Layer: class {}, ASSISTANT_MODEL_CHOICES: [] };
}, { global: { isIOS: false } });
}
test('"Display new notifications" defaults to 15s; Off stops every popup, the filter still mutes single apps', () => {
const settings = new Map();
const prefs = store(settings);
const api = dashboardSettings(settings, prefs);
assert.equal(api.newNotificationDisplaySetting.get(), '15s');
// Array.from: the module's arrays come from its own VM realm.
const values = Array.from(api.newNotificationDisplaySetting.values);
assert.deepEqual(values.map((value) => api.newNotificationDisplaySetting.displayValue(value)),
['Off', 'Until dismissed', '5s', '15s', '1min']);
assert.deepEqual(values.map(api.newNotificationDisplayTimeoutMs), [null, null, 5_000, 15_000, 60_000]);
assert.equal(api.shouldPopUpNewNotification(mail.packageName), true);
prefs.setNotificationSourceEnabled(mail, false);
assert.equal(api.shouldPopUpNewNotification(mail.packageName), false);
assert.equal(api.shouldPopUpNewNotification('com.other'), true);
api.newNotificationDisplaySetting.set('off');
assert.equal(api.shouldPopUpNewNotification('com.other'), false);
api.newNotificationDisplaySetting.set('until-dismissed');
assert.equal(api.shouldPopUpNewNotification('com.other'), true);
});
test('sources default on and retain per-package choices and names across restart and rediscovery', () => {
const settings = new Map();
let prefs = store(settings);
@@ -194,14 +229,16 @@ test('controller filters before waking or opening a popup, and still refreshes t
const members = ['handleAndroidNotificationPosted', 'handleAndroidNotificationRemoved', 'popUpAndroidNotification']
.map((name) => controller.members.find((node) => node.name?.getText(file) === name).getText(file));
const { NotificationPopupDelay, notificationPopupDelayMs } = require('../.test-build/app/ui/shell/notification-popup-delay.js');
const prefs = store();
const settings = new Map();
const prefs = store(settings);
const { newNotificationDisplaySetting, shouldPopUpNewNotification } = dashboardSettings(settings, prefs);
let active = [{ ...mail, key: 'key' }];
let wakes = 0, popups = 0, renders = 0;
const removed = [];
const { Harness } = evaluate(`export class Harness { ${members.join('\n')} }`, null, {
ALL_NOTIFICATIONS: 0x7fffffff,
readActiveNotifications: () => active,
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
shouldPopUpNewNotification,
notificationPopupDelayMs,
shell: {
isScreenOn: () => false,
@@ -253,4 +290,16 @@ test('controller filters before waking or opening a popup, and still refreshes t
prefs.setNotificationSourceEnabled(mail, false);
elapse();
assert.equal(popups, 1);
// "Display new notifications: Off" holds back every app's popup, also once the delay is over.
prefs.setNotificationSourceEnabled(mail, true);
newNotificationDisplaySetting.set('off');
instance.handleAndroidNotificationPosted('key');
elapse();
newNotificationDisplaySetting.set('15s');
instance.handleAndroidNotificationPosted('key');
newNotificationDisplaySetting.set('off');
elapse();
assert.equal(wakes, 1);
assert.equal(popups, 1);
});
+94
View File
@@ -0,0 +1,94 @@
const test = require("node:test");
const assert = require("node:assert/strict");
const { NotificationPopupTimeout } = require("../.test-build/app/ui/shell/notification-popup-timeout.js");
/** A manual clock: schedule() queues timers that advance() fires when due. */
function makeClock() {
const clock = {
nowMs: 0,
timers: [],
schedule(run, delayMs) {
const timer = { dueAtMs: clock.nowMs + delayMs, run, cancelled: false };
clock.timers.push(timer);
return () => { timer.cancelled = true; };
},
advance(ms) {
const until = clock.nowMs + ms;
for (;;) {
const due = clock.timers.filter((timer) => !timer.cancelled && timer.dueAtMs <= until)
.sort((a, b) => a.dueAtMs - b.dueAtMs)[0];
if (!due) break;
clock.nowMs = due.dueAtMs;
due.cancelled = true;
due.run();
}
clock.nowMs = until;
},
};
return clock;
}
function makeTimeout(timeoutMs) {
const clock = makeClock();
let expiries = 0;
const timeout = new NotificationPopupTimeout(timeoutMs, () => { expiries++; }, clock.schedule);
return { clock, timeout, expiries: () => expiries };
}
test("an untouched popup expires once its timeout passes", () => {
const { clock, timeout, expiries } = makeTimeout(15_000);
timeout.restart();
clock.advance(14_999);
assert.equal(expiries(), 0);
clock.advance(1);
assert.equal(expiries(), 1);
assert.equal(timeout.isRunning(), false);
clock.advance(60_000);
assert.equal(expiries(), 1);
});
test("each interaction starts the countdown over", () => {
const { clock, timeout, expiries } = makeTimeout(5_000);
timeout.restart();
clock.advance(4_000);
timeout.restart(); // e.g. scrolling the action menu
clock.advance(4_000);
assert.equal(expiries(), 0);
clock.advance(1_000);
assert.equal(expiries(), 1);
});
test("a popup that goes away first never expires", () => {
const { clock, timeout, expiries } = makeTimeout(5_000);
timeout.restart();
clock.advance(2_000);
timeout.stop();
clock.advance(10_000);
assert.equal(expiries(), 0);
});
test("until-dismissed (no timeout) never schedules anything", () => {
const { clock, timeout, expiries } = makeTimeout(null);
timeout.restart();
assert.equal(timeout.isRunning(), false);
assert.equal(clock.timers.length, 0);
clock.advance(1_000_000);
assert.equal(expiries(), 0);
});
test("the expiry callback can restart the countdown (something was over the popup)", () => {
const clock = makeClock();
let expiries = 0;
const timeout = new NotificationPopupTimeout(5_000, () => {
expiries++;
if (expiries === 1) timeout.restart();
}, clock.schedule);
timeout.restart();
clock.advance(5_000);
assert.equal(expiries, 1);
assert.equal(timeout.isRunning(), true);
clock.advance(5_000);
assert.equal(expiries, 2);
assert.equal(timeout.isRunning(), false);
});
+1
View File
@@ -38,6 +38,7 @@
"../app/g2/glance-state.ts",
"../app/ui/shell/notification-modal-queue.ts",
"../app/ui/shell/notification-popup-delay.ts",
"../app/ui/shell/notification-popup-timeout.ts",
"../app/apps/glanceboard/layout.ts",
"../app/apps/files/video-layout.ts",
"../app/g2/pairing-candidates.ts",