forked from Blendman974/faceclaw
Fix several bugs that could lead to reconnect-looping
Fix misinterpretation of EvenHub event type 5. Notification modals stacked, in a way that's O(n) in device resource memory; replace with a queue.
This commit is contained in:
1 parent
e5303e7b3e
commit
38da8e6168
15 files changed
+396
-52
No files matched your search
@@ -260,7 +260,8 @@ function shellEnv({ wakeAction = 'voice-input', skipConfirmation = false } = {})
|
||||
'../../assistant/conversations': {}, '../../assistant/models': {}, '../../native/settings-store': {},
|
||||
'../notifications': {}, '../dashboard-settings': settings, './ambient-cards': {},
|
||||
'./chrome-layer': { ShellChromeLayer: class {} }, './modal-layer': {}, './tool-debug-layer': {},
|
||||
'./brightness-picker-layer': {},
|
||||
'./brightness-picker-layer': {}, './notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts', {}),
|
||||
'../../native/notification-icons': {}, '../../native/notification-sources': {},
|
||||
'../../assistant/tool-registry': {}, './geometry': {
|
||||
sidebarWidth: () => 64, minWindowTop: () => 96, switcherPosition: () => 'left', uiDepth: () => 0,
|
||||
appViewportRect: () => ({ x: 64, y: 124, width: 576, height: 260 }),
|
||||
|
||||
@@ -114,6 +114,7 @@ test('system menu hides brightness in Auto and opens its picker between Voice in
|
||||
'../../graphics/image': graphics, '../layers': layers, '../menu': menu, '../gestures': gestures,
|
||||
'../dashboard-settings': f.settings, './geometry': f.geometry, './brightness-picker-layer': f.picker,
|
||||
'./chrome-layer': { ShellChromeLayer: class {} },
|
||||
'./notification-modal-queue': load('app/ui/shell/notification-modal-queue.ts'),
|
||||
});
|
||||
shell.registerWindow({ windowId: 'test', appId: 'test', closeable: true, handleInput() {} });
|
||||
shell.openSystemMenu('test');
|
||||
|
||||
@@ -341,6 +341,37 @@ class DisplayListTest {
|
||||
c.setSurfaceDepth("glance", -16)
|
||||
assertEquals(-16, c.composite().shellScene.screenDepth)
|
||||
}
|
||||
/** #42: stacked modal-sized layers overflow the cache, so the frame bakes the bottom ones instead of throwing. */
|
||||
@Test fun shellOverTheResourceBudgetBakesBottomLayersAndRecovers() {
|
||||
val cache = ResourceCacheState(); val planner = ScenePlanner(cache)
|
||||
val gray = ByteArray(640 * 480) { 48 }; val app = BmpUtil.pack4bppFromGray8(gray, 640, 480)
|
||||
fun layer(key: Int, y: Int, h: Int, nibble: Int, depth: Int = 0) =
|
||||
ShellScene.Layer(key, 14, y, 612, h, 256, ByteArray(306 * h) { (nibble * 17).toByte() }, depth = depth)
|
||||
// Each 612x214 layer is just under the 64 KiB resource cap; three exceed the arena on their own.
|
||||
fun chrome(depth: Int) = layer(1, 444, 36, 7, depth)
|
||||
val modals = listOf(layer(2, 10, 214, 9), layer(3, 120, 214, 11), layer(4, 230, 214, 13, depth = 4))
|
||||
val overflow = ShellScene(listOf(chrome(6)) + modals)
|
||||
val plan = planner.plan(app, 640, 480, null, overflow, 1)
|
||||
assertEquals(2, plan.bakedLayers); assertFalse(plan.bakedSelections)
|
||||
assertTrue(plan.commands.all { it.size <= 65535 })
|
||||
assertTrue(cache.usedBytes() <= ResourceCacheState.CACHE_SIZE)
|
||||
// Baked layers lose their stereo depth; the live ones keep it.
|
||||
val expected = ShellScene(listOf(chrome(0)) + modals)
|
||||
val lenses = listOf(Glasses(), Glasses(true))
|
||||
for (glasses in lenses) {
|
||||
glasses.apply(plan.commands)
|
||||
assertContentEquals(BmpUtil.pack4bppFromGray8(expected.preview(gray, 640, 480, glasses.right), 640, 480), glasses.composition)
|
||||
}
|
||||
// Once the shell fits again, the next frame is fully live and the screen is the app's again.
|
||||
val fits = ShellScene(listOf(chrome(0), modals[2]))
|
||||
val next = planner.plan(app, 640, 480, null, fits, plan.nextFid)
|
||||
assertEquals(0, next.bakedLayers)
|
||||
for (glasses in lenses) {
|
||||
glasses.apply(next.commands)
|
||||
assertContentEquals(app, glasses.screen)
|
||||
assertContentEquals(BmpUtil.pack4bppFromGray8(fits.preview(gray, 640, 480, glasses.right), 640, 480), glasses.composition)
|
||||
}
|
||||
}
|
||||
@Test fun noisyFramesRemainBoundedAndResourceBudgetIs192KiB() {
|
||||
val cache=ResourceCacheState();val planner=ScenePlanner(cache);val glasses=Glasses()
|
||||
val app=ByteArray(640*480/2){(it*37).toByte()}
|
||||
|
||||
@@ -0,0 +1,104 @@
|
||||
const test = require("node:test");
|
||||
const assert = require("node:assert/strict");
|
||||
|
||||
const { NotificationModalQueue } = require("../.test-build/app/ui/shell/notification-modal-queue.js");
|
||||
|
||||
/** A host that records opened modals (one handle object each) and sleeps. */
|
||||
function makeHost(unavailable = new Set()) {
|
||||
const host = {
|
||||
opened: [],
|
||||
sleeps: 0,
|
||||
open(notificationKey) {
|
||||
const modal = { notificationKey };
|
||||
host.opened.push(modal);
|
||||
return modal;
|
||||
},
|
||||
isAvailable: (notificationKey) => !unavailable.has(notificationKey),
|
||||
sleep() { host.sleeps++; },
|
||||
};
|
||||
return host;
|
||||
}
|
||||
|
||||
test("only one modal is open; later notifications wait and open as each closes", () => {
|
||||
const host = makeHost();
|
||||
const queue = new NotificationModalQueue(host);
|
||||
queue.post("a", false);
|
||||
queue.post("b", false);
|
||||
queue.post("c", false);
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a"]);
|
||||
assert.deepEqual(queue.queuedKeys(), ["b", "c"]);
|
||||
queue.closed(host.opened[0]);
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "b"]);
|
||||
queue.closed(host.opened[1]);
|
||||
queue.closed(host.opened[2]);
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "b", "c"]);
|
||||
assert.equal(host.sleeps, 0);
|
||||
// With nothing open, the next notification opens at once.
|
||||
queue.post("d", false);
|
||||
assert.equal(host.opened.length, 4);
|
||||
});
|
||||
|
||||
test("reposts of the open or a queued notification are not duplicated", () => {
|
||||
const host = makeHost();
|
||||
const queue = new NotificationModalQueue(host);
|
||||
queue.post("a", false);
|
||||
queue.post("a", false);
|
||||
queue.post("b", false);
|
||||
queue.post("b", false);
|
||||
assert.equal(host.opened.length, 1);
|
||||
assert.deepEqual(queue.queuedKeys(), ["b"]);
|
||||
});
|
||||
|
||||
test("queued notifications that went away are skipped", () => {
|
||||
const unavailable = new Set(["b"]);
|
||||
const host = makeHost(unavailable);
|
||||
const queue = new NotificationModalQueue(host);
|
||||
queue.post("a", false);
|
||||
queue.post("b", false);
|
||||
queue.post("c", false);
|
||||
queue.closed(host.opened[0]);
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "c"]);
|
||||
});
|
||||
|
||||
test("a screen woken by a notification sleeps again once the last modal closes", () => {
|
||||
const host = makeHost();
|
||||
const queue = new NotificationModalQueue(host);
|
||||
queue.post("a", true);
|
||||
queue.post("b", false);
|
||||
queue.closed(host.opened[0]);
|
||||
assert.equal(host.sleeps, 0, "the next notification opens instead of sleeping");
|
||||
queue.closed(host.opened[1]);
|
||||
assert.equal(host.sleeps, 1);
|
||||
// A modal opened with the screen already on doesn't sleep when closed.
|
||||
queue.post("c", false);
|
||||
queue.closed(host.opened[2]);
|
||||
assert.equal(host.sleeps, 1);
|
||||
});
|
||||
|
||||
test("sleep drops the queue; another removal opens the next without sleeping", () => {
|
||||
const host = makeHost();
|
||||
const queue = new NotificationModalQueue(host);
|
||||
queue.post("a", true);
|
||||
queue.post("b", false);
|
||||
queue.removed(host.opened[0], false);
|
||||
assert.deepEqual(queue.queuedKeys(), []);
|
||||
assert.equal(host.opened.length, 1);
|
||||
queue.post("c", false);
|
||||
queue.post("d", false);
|
||||
queue.removed(host.opened[1], true);
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "c", "d"]);
|
||||
assert.equal(host.sleeps, 0);
|
||||
});
|
||||
|
||||
test("the removal reported after a close is ignored, as are stale modals", () => {
|
||||
const host = makeHost();
|
||||
const queue = new NotificationModalQueue(host);
|
||||
queue.post("a", false);
|
||||
queue.post("b", false);
|
||||
const first = host.opened[0];
|
||||
queue.closed(first);
|
||||
queue.removed(first, true);
|
||||
queue.closed(first);
|
||||
assert.deepEqual(host.opened.map((modal) => modal.notificationKey), ["a", "b"]);
|
||||
assert.deepEqual(queue.queuedKeys(), []);
|
||||
});
|
||||
@@ -34,6 +34,7 @@
|
||||
"../app/g2/glasses-artwork.ts",
|
||||
"../app/g2/glasses-display-state.ts",
|
||||
"../app/g2/glance-state.ts",
|
||||
"../app/ui/shell/notification-modal-queue.ts",
|
||||
"../app/apps/glanceboard/layout.ts",
|
||||
"../app/apps/files/video-layout.ts",
|
||||
"../app/g2/pairing-candidates.ts",
|
||||
|
||||
Reference in new issue
Block a user