Merge branch 'main' of https://github.com/jimrandomh/faceclaw into ring-health-fixes

This commit is contained in:
James Babcock committed 2026-09-25 23:12:20 -07:00
commit a2166c6a6c
822 files changed
+79614 -30124

No files matched your search

@@ -1,8 +1,8 @@
import { type GrayImage, type UiFont } from "../../../graphics/image";
import { truncateText } from "../../../graphics/textwrap";
import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts";
import { hasCalendarPermission } from "../../../g2/android-permissions";
import { readUpcomingEvents, type CalendarEvent } from "../../../native/calendar";
import { hasCalendarPermission } from "../../../native/calendar-permissions";
import { getCalendarReadState, onCalendarChanged, readUpcomingEvents, type CalendarEvent } from "../../../native/calendar";
import { lineStep } from "../../../ui/metrics";
import { dayHeaderLabel, formatEventTime } from "../../calendar/calendar";
import { type GlanceWidget } from "../widget";
@@ -22,14 +22,19 @@ const HOUR_MS = 60 * MINUTE_MS;
*/
export class CalendarWidget implements GlanceWidget {
private tick: ReturnType<typeof setInterval> | null = null;
private unsubscribe: (() => void) | null = null;
start(requestRender: () => void): void {
this.stop();
this.unsubscribe = onCalendarChanged(requestRender);
this.tick = setInterval(requestRender, MINUTE_MS);
}
stop(): void {
if (this.tick !== null) clearInterval(this.tick);
this.tick = null;
this.unsubscribe?.();
this.unsubscribe = null;
}
paint(image: GrayImage): void {
@@ -50,7 +55,9 @@ export class CalendarWidget implements GlanceWidget {
const events = readUpcomingEvents().filter((event) => event.endMs > nowMs);
if (!events.length) {
image.drawText(small, PAD, PAD, "Calendar", 150);
image.drawText(small, PAD, PAD + step + 4, "No upcoming events", 140);
const state = getCalendarReadState();
image.drawText(small, PAD, PAD + step + 4, state === "loading" ? "Loading calendar..."
: state === "error" ? "Calendar unavailable" : "No upcoming events", 140);
return;
}
@@ -1,6 +1,6 @@
import { type GrayImage } from "../../../graphics/image";
import { getDefaultMediumFont, getDefaultSmallFont } from "../../../graphics/ui-fonts";
import { hasLocationPermission } from "../../../g2/android-permissions";
import { hasLocationPermission } from "../../../native/location-permissions";
import { addCompassListener, COMPASS_CHANGED, setCompassEnabled } from "../../../native/compass";
import { isCompassCalibrated, normalizeHeading } from "../../compass/calibration";
import { cardinalDirection, createCompassBackground, drawCompassRose, layoutCompassRose, TICK_HEIGHT } from "../../compass/compass-rose";
@@ -1,4 +1,4 @@
import { type GrayImage } from "../../../graphics/image";
import { GrayImage } from "../../../graphics/image";
import { getDefaultLargeFont, getDefaultSmallFont } from "../../../graphics/ui-fonts";
import { truncateText } from "../../../graphics/textwrap";
import { nightscoutBridge, type NightscoutState } from "../../../native/nightscout-bridge";
@@ -91,22 +91,6 @@ export class NightscoutWidget implements GlanceWidget {
image.drawText(small, PAD, y, `IOB ${state.iob === null ? "--" : state.iob.toFixed(2)}`, 160);
y += step;
// Breached limits only, one per line while they fit, inverted like the
// app's warning fields. Nothing here means nothing is out of range.
const alerts = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs);
const warnings: string[] = [];
if (alerts.cannula) warnings.push(`CAGE ${formatAgeShortFromTimestamp(state.cageTimestampMs, nowMs)}`);
if (alerts.cartridge) warnings.push(`Reservoir ${state.reservoirUnits === null ? "--" : Math.round(state.reservoirUnits)}U`);
if (alerts.battery) warnings.push(`Battery ${state.batteryVoltage === null ? "--" : state.batteryVoltage.toFixed(2)}V`);
if (alerts.loop) warnings.push(`Loop ${formatAgeShortFromTimestamp(state.loopTimestampMs, nowMs)}`);
for (const warning of warnings) {
if (y + small.lineHeight > image.height - 2) break;
const text = truncateText(small, warning, READOUT_WIDTH - 4);
image.fillRect(PAD - 2, y - 1, small.measureText(text) + 4, small.lineHeight + 2, 230);
image.drawText(small, PAD, y, text, 1);
y += step;
}
const graphX = PAD + READOUT_WIDTH + PAD;
drawNightscoutGraph(
image,
@@ -115,5 +99,32 @@ export class NightscoutWidget implements GlanceWidget {
nowMs,
small,
);
// Breached limits only, inverted like the app's warning fields. Continue
// at the top of a second column over the graph when the readout is full.
const alerts = evaluateNightscoutAlerts(state, loadNightscoutThresholds(), nowMs);
const warnings: string[] = [];
if (alerts.cannula) warnings.push(`CAGE ${formatAgeShortFromTimestamp(state.cageTimestampMs, nowMs)}`);
if (alerts.cartridge) warnings.push(`Reservoir ${state.reservoirUnits === null ? "--" : Math.round(state.reservoirUnits)}U`);
if (alerts.battery) warnings.push(`Battery ${state.batteryVoltage === null ? "--" : state.batteryVoltage.toFixed(2)}V`);
if (alerts.loop) warnings.push(`Loop ${formatAgeShortFromTimestamp(state.loopTimestampMs, nowMs)}`);
let warningX = PAD;
for (const warning of warnings) {
if (y + small.lineHeight > image.height - 2) {
warningX = graphX;
y = PAD;
}
const text = truncateText(small, warning, READOUT_WIDTH - 4);
const width = Math.ceil(small.measureText(text)) + 4;
if (warningX === PAD) {
image.fillRect(warningX - 2, y - 1, width, small.lineHeight + 2, 230);
} else {
// Graph labels are deferred glyphs: a deferred opaque background
// covers those as well as the graph's raster lines.
image.drawImage(new GrayImage(width, small.lineHeight + 2, 230), warningX - 2, y - 1);
}
image.drawText(small, warningX, y, text, 1);
y += step;
}
}
}