From ec924f79098f359f4ac8ef1c71cc7b9ee6b9a91b Mon Sep 17 00:00:00 2001 From: James Babcock Date: Sun, 7 Jun 2026 11:57:13 -0700 Subject: [PATCH] Handle dismissed notifications --- app/ui/dashboard.ts | 11 ++++++++++- app/ui/notifications.ts | 44 ++++++++++++++++++++++++++++++++--------- 2 files changed, 45 insertions(+), 10 deletions(-) diff --git a/app/ui/dashboard.ts b/app/ui/dashboard.ts index 8dca3416..37f1e34f 100644 --- a/app/ui/dashboard.ts +++ b/app/ui/dashboard.ts @@ -178,10 +178,19 @@ export function openAndroidNotificationFromSleep(notificationKey: string, nowMs dashboardState.tiledWakePaintPending = wakeModeSetting.get() === "tiled"; dashboardLayers.clearToBase(); dashboardLayers.push(createRootMenuLayer()); - dashboardLayers.push(new SingleNotificationLayer(notificationKey)); + dashboardLayers.push(new SingleNotificationLayer(notificationKey, { + origin: "new-notification-trigger", + closeNewNotificationTrigger: closeNewNotificationTrigger, + })); return true; } +function closeNewNotificationTrigger(ctx: LayerContext): void { + dashboardState.screenOn = false; + dashboardState.tiledWakePaintPending = false; + ctx.stack.clearToBase(); +} + export function resetDashboardSleepTimerAndWake(nowMs = Date.now()): boolean { dashboardState.lastInputAtMs = nowMs; if (dashboardState.screenOn) return false; diff --git a/app/ui/notifications.ts b/app/ui/notifications.ts index d4c0a3eb..00902079 100644 --- a/app/ui/notifications.ts +++ b/app/ui/notifications.ts @@ -34,6 +34,13 @@ type DetailMenuItem = | { kind: "action"; label: string; action: AndroidNotificationAction } | { kind: "dismiss"; label: string }; +export type SingleNotificationLayerOrigin = "notifications-dashboard" | "new-notification-trigger"; + +type SingleNotificationLayerOptions = { + origin: SingleNotificationLayerOrigin; + closeNewNotificationTrigger?: (ctx: LayerContext) => void; +}; + export class NotificationsListLayer implements Layer { private selectedKey = ""; @@ -93,7 +100,9 @@ export class NotificationsListLayer implements Layer { return; } if (event.type === "click") { - ctx.stack.push(new SingleNotificationLayer(notifications[selectedIndex]!.key)); + ctx.stack.push(new SingleNotificationLayer(notifications[selectedIndex]!.key, { + origin: "notifications-dashboard", + })); } } @@ -114,18 +123,18 @@ export class NotificationsListLayer implements Layer { export class SingleNotificationLayer implements Layer { private selectedMenuIndex = 0; - constructor(private readonly notificationKey: string) {} + constructor( + private readonly notificationKey: string, + private readonly options: SingleNotificationLayerOptions, + ) {} - paint(ctx: LayerContext, _paintBelow: PaintBelow): GrayImage { + paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage { const font = getDefaultSmallFont(); const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); const notification = readActiveNotifications(MAX_NOTIFICATIONS).find((item) => item.key === this.notificationKey); if (!notification) { - image.drawText(font, PAGE_X + 12, PAGE_Y + 9, "Notification", 220); - image.drawText(font, 24, 72, "This notification is no longer active.", 190); - image.drawText(font, 24, 252, "Double-click to go back", 110); - return image; + return this.closeUnavailableNotification(ctx, paintBelow); } const menu = buildDetailMenu(notification); @@ -137,7 +146,11 @@ export class SingleNotificationLayer implements Layer { handleInput(event: DashboardInputEvent, ctx: LayerContext): void { const notification = readActiveNotifications(MAX_NOTIFICATIONS).find((item) => item.key === this.notificationKey); - const menu = notification ? buildDetailMenu(notification) : [{ kind: "back", label: "Back" } as DetailMenuItem]; + if (!notification) { + this.closeUnavailableNotification(ctx); + return; + } + const menu = buildDetailMenu(notification); if (event.type === "double-click") { ctx.stack.pop(); @@ -158,11 +171,24 @@ export class SingleNotificationLayer implements Layer { ctx.stack.pop(); } else if (item.kind === "action") { invokeNotificationAction(this.notificationKey, item.action.index); + if (!readActiveNotifications(MAX_NOTIFICATIONS).some((item) => item.key === this.notificationKey)) { + this.closeUnavailableNotification(ctx); + } } else if (item.kind === "dismiss") { dismissNotification(this.notificationKey); - ctx.stack.pop(); + this.closeUnavailableNotification(ctx); } } + + private closeUnavailableNotification(ctx: LayerContext, paintBelow?: PaintBelow): GrayImage { + if (this.options.origin === "new-notification-trigger") { + this.options.closeNewNotificationTrigger?.(ctx); + return new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); + } + + ctx.stack.pop(); + return paintBelow ? paintBelow() : new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0); + } }