forked from Blendman974/faceclaw
Merge branch 'main' of https://github.com/jimrandomh/faceclaw into ring-health-fixes
This commit is contained in:
commit
a2166c6a6c
822 files changed
+79614
-30124
No files matched your search
@@ -0,0 +1,11 @@
|
||||
import { getStringSetting } from "../../native/settings-store";
|
||||
import { QUADRANT_LAYOUT, SIX_SLOT_LAYOUT } from "./layout";
|
||||
|
||||
/** Configuration-only query usable by workers without loading widget/UI modules. */
|
||||
export function isTerminalWidgetConfigured(): boolean {
|
||||
const layout = getStringSetting("glanceboard.layout", "2x2") === "2x3" ? SIX_SLOT_LAYOUT : QUADRANT_LAYOUT;
|
||||
// Both layouts store their slots under the original quadrants key. None
|
||||
// of the default slots needs a worker, so absent keys cannot retain one.
|
||||
return layout.slots.some((_, index) =>
|
||||
getStringSetting(`glanceboard.${QUADRANT_LAYOUT.id}.slot.${index}`, "none") === "terminal");
|
||||
}
|
||||
@@ -3,15 +3,17 @@ import { truncateText, wrapText } from "../../graphics/textwrap";
|
||||
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
|
||||
import { enumSettingMenuItem, onAnySettingChanged, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { type Layer, type LayerContext, type PaintBelow } from "../../ui/layers";
|
||||
import { drawSelectionHighlight, MenuLayer, openModalMenu, type MenuItem } from "../../ui/menu";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep } from "../../ui/metrics";
|
||||
import { type Layer, type LayerContext } from "../../ui/layers";
|
||||
import { drawSelectionHighlight, isMenuItemDisabled, MenuLayer, openModalMenu, type MenuItem } from "../../ui/menu";
|
||||
import { Menu } from "../../ui/menu-core";
|
||||
import { LIST_ROW_TEXT_INSET, lineStep, listRowHeight } from "../../ui/metrics";
|
||||
import { createInProcessWindow, type InProcessAppOptions, type InProcessWindow } from "../../ui/shell/in-process-window";
|
||||
import { shell } from "../../ui/shell/shell";
|
||||
import { GlanceBoard } from "./board";
|
||||
import {
|
||||
clearConflictingSlots,
|
||||
glanceboardEnabledSetting,
|
||||
glanceDepthSetting,
|
||||
glanceLayout,
|
||||
glanceLayoutSetting,
|
||||
glanceShowLinesSetting,
|
||||
@@ -35,6 +37,15 @@ const PARAGRAPH_X = 24;
|
||||
const PREVIEW_MARGIN = 8;
|
||||
const PREVIEW_MIN_LINE_VALUE = 20;
|
||||
const PREVIEW_LINE_VALUE = 100;
|
||||
/** The entry menu's row boxes: left inset, gap below the paragraph, and inset from the page's bottom. */
|
||||
const HOME_MENU_X = 20;
|
||||
const HOME_MENU_TOP_GAP = 12;
|
||||
const HOME_MENU_BOTTOM_MARGIN = 8;
|
||||
/** Horizontal inset of row text (and custom row content) from its selection box. */
|
||||
const HOME_ROW_TEXT_X = 10;
|
||||
// A throwaway menu to satisfy MenuItem.onSelect's second parameter; the
|
||||
// entry page's items never use it (they act via ctx only).
|
||||
const NO_MENU = new MenuLayer(null, []);
|
||||
|
||||
const INTRO =
|
||||
"Your Glanceboard is a display for things you want to look at quickly. Starting " +
|
||||
@@ -55,25 +66,21 @@ function pageMenuLayout(width: number) {
|
||||
* a double-tap returns focus to the menu.
|
||||
*/
|
||||
class GlanceboardHomeLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
private menuTop = 0;
|
||||
private menuHeight = 0;
|
||||
private readonly menu: Menu<MenuItem>;
|
||||
private focus: "menu" | "preview" = "menu";
|
||||
private selectedSlot = 0;
|
||||
/** The context of the paint in progress, handed to item render callbacks. */
|
||||
private paintCtx: LayerContext | null = null;
|
||||
|
||||
constructor(private readonly setPreviewVisible: (visible: boolean) => void) {}
|
||||
|
||||
private currentMenu(ctx: LayerContext, menuTop: number): MenuLayer {
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
if (!this.menu || this.menuTop !== menuTop || this.menuHeight !== height) {
|
||||
const half = (width / 2) | 0;
|
||||
const items: MenuItem[] = [
|
||||
constructor(private readonly setPreviewVisible: (visible: boolean) => void) {
|
||||
this.menu = new Menu<MenuItem>({
|
||||
items: [
|
||||
toggleSettingMenuItem(glanceboardEnabledSetting),
|
||||
{
|
||||
label: "Preview",
|
||||
onSelect: (menuCtx) => {
|
||||
menuCtx.stack.push(new GlancePreviewLayer(
|
||||
() => menuCtx.actions.requestRender(),
|
||||
onSelect: (ctx) => {
|
||||
ctx.stack.push(new GlancePreviewLayer(
|
||||
() => ctx.actions.requestRender(),
|
||||
() => this.setPreviewVisible(false),
|
||||
));
|
||||
this.setPreviewVisible(true);
|
||||
@@ -87,17 +94,32 @@ class GlanceboardHomeLayer implements Layer {
|
||||
},
|
||||
{
|
||||
label: "Settings",
|
||||
onSelect: (menuCtx) => menuCtx.stack.push(new GlanceSettingsLayer()),
|
||||
onSelect: openGlanceSettings,
|
||||
},
|
||||
];
|
||||
this.menuTop = menuTop;
|
||||
this.menuHeight = height;
|
||||
this.menu = new MenuLayer(null, items, {
|
||||
x: 8, y: menuTop, width: half - 16,
|
||||
showBorder: false, minHeight: 0, maxHeight: height - menuTop,
|
||||
});
|
||||
}
|
||||
return this.menu;
|
||||
],
|
||||
wrap: true,
|
||||
rowGap: 1,
|
||||
getHeight: () => listRowHeight(getDefaultSmallFont()),
|
||||
draw: ({ image, item, x, y, width, height, selected }) => {
|
||||
const disabled = isMenuItemDisabled(item);
|
||||
if (item.render) {
|
||||
item.render({
|
||||
image,
|
||||
x: x + HOME_ROW_TEXT_X,
|
||||
y,
|
||||
width: width - 2 * HOME_ROW_TEXT_X,
|
||||
height: height - 2,
|
||||
selected,
|
||||
disabled,
|
||||
text: item.label,
|
||||
ctx: this.paintCtx!,
|
||||
});
|
||||
} else {
|
||||
image.drawText(getDefaultSmallFont(), x + HOME_ROW_TEXT_X, y + LIST_ROW_TEXT_INSET, item.label,
|
||||
disabled ? 70 : selected ? 255 : 200);
|
||||
}
|
||||
},
|
||||
});
|
||||
}
|
||||
|
||||
/** Where the scaled board sits: the right half, board aspect, vertically centred. */
|
||||
@@ -128,13 +150,19 @@ class GlanceboardHomeLayer implements Layer {
|
||||
image.drawText(font, PARAGRAPH_X, y, line, 160);
|
||||
y += step;
|
||||
}
|
||||
// The menu paints onto this page below the paragraph (its fill is raster,
|
||||
// so the deferred paragraph glyphs above stay untouched either way).
|
||||
// While the preview has focus the menu keeps its outline-only selection.
|
||||
const menu = this.currentMenu(ctx, y + 4);
|
||||
const menuFocused = ctx.stack.isFocused() && this.focus === "menu";
|
||||
const menuCtx: LayerContext = { ...ctx, stack: Object.assign(Object.create(ctx.stack), { isFocused: () => menuFocused }) };
|
||||
menu.paint(menuCtx, () => image);
|
||||
// The menu sits below the paragraph in the left half. While the preview
|
||||
// has focus the menu keeps its outline-only selection.
|
||||
const menuTop = y + HOME_MENU_TOP_GAP;
|
||||
const menuWidth = half - 2 * HOME_MENU_X;
|
||||
const menuHeight = Math.max(0, height - menuTop - HOME_MENU_BOTTOM_MARGIN);
|
||||
this.paintCtx = ctx;
|
||||
try {
|
||||
this.menu.paint(image, { x: HOME_MENU_X, y: menuTop, width: menuWidth, height: menuHeight },
|
||||
ctx.stack.isFocused() && this.focus === "menu");
|
||||
} finally {
|
||||
this.paintCtx = null;
|
||||
}
|
||||
this.menu.drawScrollbar(image, HOME_MENU_X + menuWidth + 5, menuTop, menuHeight - 4);
|
||||
|
||||
this.selectedSlot = Math.min(this.selectedSlot, glanceLayout().slots.length - 1);
|
||||
const preview = this.previewRect(width, height);
|
||||
@@ -173,7 +201,12 @@ class GlanceboardHomeLayer implements Layer {
|
||||
shell.yieldFocusToSidebar();
|
||||
return;
|
||||
}
|
||||
await this.currentMenu(ctx, this.menuTop).handleInput(event, ctx);
|
||||
if (event.type === "click") {
|
||||
const item = this.menu.selectedItem;
|
||||
if (item && !isMenuItemDisabled(item)) await item.onSelect(ctx, NO_MENU);
|
||||
return;
|
||||
}
|
||||
await this.menu.handleInput(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -265,32 +298,17 @@ function openSlotPicker(ctx: LayerContext, slotIndex: number): void {
|
||||
openModalMenu(ctx, setting.label, items, Math.max(0, setting.values.indexOf(current)));
|
||||
}
|
||||
|
||||
/** Settings: layout, sleep gestures, duration, and slot lines. */
|
||||
class GlanceSettingsLayer implements Layer {
|
||||
private menu: MenuLayer | null = null;
|
||||
|
||||
private currentMenu(ctx: LayerContext): MenuLayer {
|
||||
if (!this.menu) {
|
||||
const { width } = ctx.stack.getBaseSize();
|
||||
const items: MenuItem[] = [
|
||||
enumSettingMenuItem(glanceLayoutSetting),
|
||||
enumSettingMenuItem(glanceTapDurationSetting),
|
||||
toggleSettingMenuItem(glanceShowOnLongPressSetting),
|
||||
toggleSettingMenuItem(glanceShowOnHeadTiltSetting),
|
||||
toggleSettingMenuItem(glanceShowLinesSetting),
|
||||
];
|
||||
this.menu = new MenuLayer("Glanceboard settings", items, pageMenuLayout(width));
|
||||
}
|
||||
return this.menu;
|
||||
}
|
||||
|
||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||
return this.currentMenu(ctx).paint(ctx, paintBelow);
|
||||
}
|
||||
|
||||
async handleInput(event: InputEvent, ctx: LayerContext): Promise<void> {
|
||||
await this.currentMenu(ctx).handleInput(event, ctx);
|
||||
}
|
||||
/** Settings: layout, sleep gestures, duration, slot lines, and stereo depth. */
|
||||
function openGlanceSettings(ctx: LayerContext): void {
|
||||
const items: MenuItem[] = [
|
||||
enumSettingMenuItem(glanceLayoutSetting),
|
||||
enumSettingMenuItem(glanceTapDurationSetting),
|
||||
toggleSettingMenuItem(glanceShowOnLongPressSetting),
|
||||
toggleSettingMenuItem(glanceShowOnHeadTiltSetting),
|
||||
toggleSettingMenuItem(glanceShowLinesSetting),
|
||||
enumSettingMenuItem(glanceDepthSetting),
|
||||
];
|
||||
ctx.stack.push(new MenuLayer("Glanceboard settings", items, pageMenuLayout(ctx.stack.getBaseSize().width)));
|
||||
}
|
||||
|
||||
/** The live board in the window; any click or double-click returns to the list. */
|
||||
|
||||
@@ -104,6 +104,31 @@ export const glanceShowOnHeadTiltSetting = new ConfigSettingBoolean({
|
||||
description: "Tilting your head up while asleep shows the Glanceboard instead of waking the regular UI.",
|
||||
});
|
||||
|
||||
const DEPTH_VALUES = ["-64", "-48", "-32", "-16", "0", "16", "32", "48", "64"] as const;
|
||||
export type GlanceDepth = (typeof DEPTH_VALUES)[number];
|
||||
|
||||
/**
|
||||
* Stereo depth of the board, in the firmware's depth units: the lenses shift
|
||||
* it by half this many pixels each, in opposite directions.
|
||||
*/
|
||||
export const glanceDepthSetting = new ConfigSettingEnum<GlanceDepth>({
|
||||
id: "glanceboard-depth",
|
||||
label: "Depth",
|
||||
storageKey: "glanceboard.depth",
|
||||
defaultValue: "0",
|
||||
values: DEPTH_VALUES,
|
||||
formatValue: (value) => {
|
||||
const depth = Number(value);
|
||||
return depth === 0 ? "0" : depth > 0 ? `+${depth} (nearer)` : `${depth} (farther)`;
|
||||
},
|
||||
description:
|
||||
"Moves the Glanceboard nearer (positive) or farther away (negative) by shifting it in opposite directions on the two lenses.",
|
||||
});
|
||||
|
||||
export function glanceDepth(): number {
|
||||
return Number(glanceDepthSetting.get());
|
||||
}
|
||||
|
||||
/** Hairlines between the board's slots. */
|
||||
export const glanceShowLinesSetting = new ConfigSettingBoolean({
|
||||
id: "glanceboard-show-lines",
|
||||
|
||||
@@ -3,6 +3,7 @@ import { GlanceBoard } from "./board";
|
||||
import { createGlanceboardAppWindow, GLANCEBOARD_SURFACE_ID, GLANCEBOARD_WINDOW_ID } from "./glanceboard-app";
|
||||
import {
|
||||
glanceboardEnabledSetting,
|
||||
glanceDepth,
|
||||
glanceLayout,
|
||||
glanceShowOnHeadTiltSetting,
|
||||
glanceShowOnLongPressSetting,
|
||||
@@ -25,6 +26,7 @@ const glanceboardApp: AppDefinition = {
|
||||
tapTimeoutMs: glanceTapTimeoutMs,
|
||||
showOnLongPress: () => glanceShowOnLongPressSetting.get(),
|
||||
showOnHeadTilt: () => glanceShowOnHeadTiltSetting.get(),
|
||||
depth: glanceDepth,
|
||||
createBoard: (requestRender) => new GlanceBoard(requestRender),
|
||||
},
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user