Add a prototype nightscout "missed bolus" detector

This commit is contained in:
James Babcock committed 2026-10-12 17:06:38 -07:00
1 parent f6201d8e41
commit 00c36602d6
13 files changed
+997 -61

No files matched your search

+36 -6
View File
@@ -248,6 +248,18 @@ export type AssistantActivityEvent = {
export type FocusKind = "sidebar" | "window";
/**
* A notification an app posts itself, rather than one Android posted. It
* opens in the same modal (and waits in the same queue) as Android
* notifications, but is not listed in the Notifications app.
*/
export type AppNotification = {
/** Unique per notification; must not collide with Android notification keys. */
key: string;
/** The modal's content; `close` takes the modal down. */
createLayer: (close: () => void) => Layer;
};
const noopActions: LayerActions = noopLayerActions;
/**
@@ -403,9 +415,12 @@ class Shell {
private readonly trayIcons = new Map<string, GrayImage>();
private activeVoiceLayer: VoiceInputLayer | null = null;
private activeKeyboardLayer: KeyboardInputLayer | null = null;
// App-posted notifications that are open or queued, by key.
private readonly appNotifications = new Map<string, AppNotification>();
private readonly notificationModals = new NotificationModalQueue<ShellModalLayer>({
open: (notificationKey) => this.pushNotificationModal(notificationKey),
isAvailable: (notificationKey) => {
if (this.appNotifications.has(notificationKey)) return true;
const notification = readActiveNotifications(ALL_NOTIFICATIONS).find((item) => item.key === notificationKey);
return !!notification && shouldShowNotificationOnGlasses(notification.packageName);
},
@@ -797,20 +812,35 @@ class Shell {
this.config.requestShellRender();
}
/**
* Show an app's own notification the way new Android notifications are
* shown: in the notification modal, waking the screen for it if it was off.
*/
postAppNotification(notification: AppNotification): void {
this.appNotifications.set(notification.key, notification);
const wokeScreen = this.screenOn ? false : this.wake("sidebar");
this.openNotificationModal(notification.key, wokeScreen);
}
private pushNotificationModal(notificationKey: string): ShellModalLayer {
const appNotification = this.appNotifications.get(notificationKey);
const close = () => this.closeNotificationModal(modal, notificationKey);
const modal: ShellModalLayer = new ShellModalLayer(
new SingleNotificationLayer(notificationKey, {
origin: "new-notification-modal",
onClose: () => this.closeNotificationModal(modal),
}),
appNotification
? appNotification.createLayer(close)
: new SingleNotificationLayer(notificationKey, { origin: "new-notification-modal", onClose: close }),
this.config.actions,
() => this.notificationModals.removed(modal, this.screenOn),
() => {
this.appNotifications.delete(notificationKey);
this.notificationModals.removed(modal, this.screenOn);
},
);
this.stack.push(modal);
return modal;
}
private closeNotificationModal(modal: ShellModalLayer): void {
private closeNotificationModal(modal: ShellModalLayer, notificationKey: string): void {
this.appNotifications.delete(notificationKey);
// The queue first: it opens the next notification or puts the screen back
// to sleep, and then ignores the removal below. remove() rather than a
// pop, so a menu opened over the modal doesn't leave it stuck.