forked from Blendman974/faceclaw
Clear notification popups when they're dismissed on the phone, and avoid showing some notifications that are spurious
This commit is contained in:
1 parent
42c2d5cd55
commit
bf92a5a2ce
17 files changed
+422
-70
No files matched your search
@@ -187,29 +187,69 @@ test('popup action wraps fully and stays visible with small and large fonts', as
|
||||
}
|
||||
});
|
||||
|
||||
test('controller filters before waking or opening a popup, and still refreshes the tray', async () => {
|
||||
test('controller filters before waking or opening a popup, and still refreshes the tray', () => {
|
||||
const file = ts.createSourceFile('controller.ts', source('app/g2/dashboard-controller.ts'), ts.ScriptTarget.Latest, true);
|
||||
const controller = file.statements.find((node) => ts.isClassDeclaration(node) && node.name.text === 'DashboardController');
|
||||
const handler = controller.members.find((node) => node.name?.getText(file) === 'handleAndroidNotificationPosted');
|
||||
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();
|
||||
let active = [{ ...mail, key: 'key' }];
|
||||
let wakes = 0, popups = 0, renders = 0;
|
||||
const { Harness } = evaluate(`export class Harness { ${handler.getText(file)} }`, null, {
|
||||
const removed = [];
|
||||
const { Harness } = evaluate(`export class Harness { ${members.join('\n')} }`, null, {
|
||||
ALL_NOTIFICATIONS: 0x7fffffff,
|
||||
readActiveNotifications: () => [{ ...mail, key: 'key' }],
|
||||
readActiveNotifications: () => active,
|
||||
shouldShowNotificationOnGlasses: prefs.shouldShowNotificationOnGlasses,
|
||||
shell: { isScreenOn: () => false, wake: () => { wakes++; return true; }, openNotificationModal: () => popups++ },
|
||||
notificationPopupDelayMs,
|
||||
shell: {
|
||||
isScreenOn: () => false,
|
||||
wake: () => { wakes++; return true; },
|
||||
openNotificationModal: () => popups++,
|
||||
notificationRemoved: (key) => removed.push(key),
|
||||
},
|
||||
});
|
||||
// Popup delays run when the test says so.
|
||||
let timers = [];
|
||||
const elapse = () => { const due = timers; timers = []; for (const timer of due) if (!timer.cancelled) timer.run(); };
|
||||
const instance = new Harness();
|
||||
instance.notificationPopups = new NotificationPopupDelay((key) => instance.popUpAndroidNotification(key), (run) => {
|
||||
const timer = { run, cancelled: false };
|
||||
timers.push(timer);
|
||||
return () => { timer.cancelled = true; };
|
||||
});
|
||||
instance.requestShellRender = () => renders++;
|
||||
instance.appendLog = () => {};
|
||||
|
||||
prefs.setNotificationSourceEnabled(mail, false);
|
||||
await instance.handleAndroidNotificationPosted('key');
|
||||
await instance.handleAndroidNotificationPosted('gone');
|
||||
instance.handleAndroidNotificationPosted('key');
|
||||
instance.handleAndroidNotificationPosted('gone');
|
||||
elapse();
|
||||
assert.equal(wakes, 0);
|
||||
assert.equal(popups, 0);
|
||||
assert.equal(renders, 2);
|
||||
|
||||
prefs.setNotificationSourceEnabled(mail, true);
|
||||
await instance.handleAndroidNotificationPosted('key');
|
||||
instance.handleAndroidNotificationPosted('key');
|
||||
assert.equal(popups, 0, 'the popup waits out its delay');
|
||||
elapse();
|
||||
assert.equal(wakes, 1);
|
||||
assert.equal(popups, 1);
|
||||
|
||||
// Withdrawn by its source during the delay: no wake, no popup, and the shell hears of it.
|
||||
active = [{ ...mail, key: 'working', foregroundService: true }];
|
||||
instance.handleAndroidNotificationPosted('working');
|
||||
active = [];
|
||||
instance.handleAndroidNotificationRemoved('working');
|
||||
elapse();
|
||||
assert.equal(wakes, 1);
|
||||
assert.equal(popups, 1);
|
||||
assert.deepEqual(removed, ['working']);
|
||||
|
||||
// The filter is checked again once the delay is over.
|
||||
active = [{ ...mail, key: 'key' }];
|
||||
instance.handleAndroidNotificationPosted('key');
|
||||
prefs.setNotificationSourceEnabled(mail, false);
|
||||
elapse();
|
||||
assert.equal(popups, 1);
|
||||
});
|
||||
@@ -102,3 +102,21 @@ test("the removal reported after a close is ignored, as are stale modals", () =>
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "b"]);
|
||||
assert.deepEqual(queue.queuedKeys(), []);
|
||||
});
|
||||
|
||||
test("a withdrawn notification leaves the queue; the open one is handed back to close", () => {
|
||||
const host = makeHost();
|
||||
const queue = new NotificationModalQueue(host);
|
||||
queue.post("a", true);
|
||||
queue.post("b", false);
|
||||
queue.post("c", false);
|
||||
assert.equal(queue.withdrawn("b"), null);
|
||||
assert.deepEqual(queue.queuedKeys(), ["c"]);
|
||||
assert.equal(queue.withdrawn("unknown"), null);
|
||||
const open = queue.withdrawn("a");
|
||||
assert.equal(open, host.opened[0]);
|
||||
// The host closes it, which moves on to the next as a user close would.
|
||||
queue.closed(open);
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "c"]);
|
||||
queue.closed(queue.withdrawn("c"));
|
||||
assert.equal(host.sleeps, 1, "the screen the withdrawn notification woke sleeps again");
|
||||
});
|
||||
@@ -0,0 +1,93 @@
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const {
|
||||
FOREGROUND_SERVICE_POPUP_DELAY_MS,
|
||||
NOTIFICATION_POPUP_DELAY_MS,
|
||||
NotificationPopupDelay,
|
||||
notificationPopupDelayMs,
|
||||
} = require("../.test-build/app/ui/shell/notification-popup-delay.js");
|
||||
|
||||
/** A manual clock: schedule() queues timers that advance() fires in due order. */
|
||||
function makeClock() {
|
||||
const clock = {
|
||||
nowMs: 0,
|
||||
timers: [],
|
||||
now: () => clock.nowMs,
|
||||
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 makeDelay() {
|
||||
const clock = makeClock();
|
||||
const ready = [];
|
||||
const delay = new NotificationPopupDelay((key) => ready.push(key), clock.schedule, clock.now);
|
||||
return { clock, ready, delay };
|
||||
}
|
||||
|
||||
test("a notification pops up once its delay passes", () => {
|
||||
const { clock, ready, delay } = makeDelay();
|
||||
delay.post("a", 500);
|
||||
clock.advance(499);
|
||||
assert.deepEqual(ready, []);
|
||||
assert.deepEqual(delay.pendingKeys(), ["a"]);
|
||||
clock.advance(1);
|
||||
assert.deepEqual(ready, ["a"]);
|
||||
assert.deepEqual(delay.pendingKeys(), []);
|
||||
});
|
||||
|
||||
test("one withdrawn while waiting never pops up; the replacement still does", () => {
|
||||
const { clock, ready, delay } = makeDelay();
|
||||
// Messages: a foreground-service placeholder, the message under another key, then the placeholder goes.
|
||||
delay.post("working", 5000);
|
||||
clock.advance(2000);
|
||||
delay.post("message", 500);
|
||||
assert.equal(delay.withdraw("working"), true);
|
||||
clock.advance(10000);
|
||||
assert.deepEqual(ready, ["message"]);
|
||||
assert.equal(delay.withdraw("working"), false);
|
||||
assert.equal(delay.withdraw("message"), false, "already popped up");
|
||||
});
|
||||
|
||||
test("reposts can bring a popup forward but never push it back", () => {
|
||||
const { clock, ready, delay } = makeDelay();
|
||||
delay.post("a", 500);
|
||||
clock.advance(400);
|
||||
delay.post("a", 500);
|
||||
clock.advance(100);
|
||||
assert.deepEqual(ready, ["a"], "an update does not restart the delay");
|
||||
|
||||
// Rewritten from a foreground-service placeholder into the real notification, same key.
|
||||
delay.post("b", 5000);
|
||||
clock.advance(1000);
|
||||
delay.post("b", 500);
|
||||
clock.advance(500);
|
||||
assert.deepEqual(ready, ["a", "b"]);
|
||||
clock.advance(10000);
|
||||
assert.deepEqual(ready, ["a", "b"], "the earlier timer was cancelled");
|
||||
});
|
||||
|
||||
test("foreground-service notifications wait longer, unless urgent", () => {
|
||||
assert.equal(notificationPopupDelayMs({ category: "msg" }), NOTIFICATION_POPUP_DELAY_MS);
|
||||
assert.equal(notificationPopupDelayMs({ category: "", foregroundService: true }), FOREGROUND_SERVICE_POPUP_DELAY_MS);
|
||||
assert.equal(notificationPopupDelayMs({ category: "call", foregroundService: true }), NOTIFICATION_POPUP_DELAY_MS);
|
||||
assert.equal(notificationPopupDelayMs({ category: "alarm", foregroundService: true }), NOTIFICATION_POPUP_DELAY_MS);
|
||||
assert.ok(FOREGROUND_SERVICE_POPUP_DELAY_MS > NOTIFICATION_POPUP_DELAY_MS);
|
||||
});
|
||||
@@ -35,6 +35,7 @@
|
||||
"../app/g2/glasses-display-state.ts",
|
||||
"../app/g2/glance-state.ts",
|
||||
"../app/ui/shell/notification-modal-queue.ts",
|
||||
"../app/ui/shell/notification-popup-delay.ts",
|
||||
"../app/apps/glanceboard/layout.ts",
|
||||
"../app/apps/files/video-layout.ts",
|
||||
"../app/g2/pairing-candidates.ts",
|
||||
|
||||
Reference in new issue
Block a user