This commit is contained in:
James Babcock committed 2026-06-01 13:35:58 -07:00
1 parent 8d99ea97b5
commit d67afcbfdb
7 files changed
+128 -94

No files matched your search

+16 -8
View File
@@ -1,13 +1,18 @@
import takeRight from "lodash/takeRight";
import { getDefaultSmallFont } from "~/graphics/bdffont";
import { DashboardPlugin, DashboardPluginState } from "../dashboard-plugins";
import { DashboardPlugin, DashboardPluginCardRenderArgs, DashboardPluginState } from "../dashboard-plugins";
import { Layer, LayerContext, type DashboardInputEvent } from "../layers";
import { GrayImage } from "~/graphics/image";
export const debugLogDashboardPlugin: DashboardPlugin = {
id: "input-debug-log",
label: "Input debug log",
renderCard: ({ image, bounds, state }) => {
export class DebugLogDashboardPlugin extends DashboardPlugin {
constructor() {
super({
id: "input-debug-log",
label: "Input debug log",
});
}
override renderCard({ image, bounds, state }: DashboardPluginCardRenderArgs): void {
const font = getDefaultSmallFont();
image.drawText(font, bounds.x + 10, bounds.y + 14, "Input log", 180);
const lineHeight = 14;
@@ -16,9 +21,12 @@ export const debugLogDashboardPlugin: DashboardPlugin = {
for (let i = 0; i < visibleLines.length; i++) {
image.drawText(font, bounds.x + 8, bounds.y + 26 + i * lineHeight, visibleLines[i]!, 190);
}
},
createFullscreenLayer: (getState) => new DebugLogLayer(getState),
};
}
override createFullscreenLayer(getState: () => DashboardPluginState): Layer {
return new DebugLogLayer(getState);
}
}
class DebugLogLayer implements Layer {
private scrollOffset = 0;
+33 -23
View File
@@ -1,14 +1,20 @@
import { DashboardPlugin, DashboardPluginState } from "../dashboard-plugins";
import { DashboardPlugin, DashboardPluginCardRenderArgs, DashboardPluginState } from "../dashboard-plugins";
import { getDefaultSmallFont } from "../../graphics/bdffont";
import { GrayImage } from "../../graphics/image";
import { wrapText } from "../../graphics/textwrap";
import { mediaControllerBridge, type MediaControllerState } from "../../native/media-controller";
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
export const musicControllerDashboardPlugin: DashboardPlugin = {
id: "music-controller",
label: "Music controller",
renderCard: ({ image, bounds, state }) => {
export class MusicControllerDashboardPlugin extends DashboardPlugin {
constructor() {
super({
id: "music-controller",
label: "Music controller",
});
}
override renderCard({ image, bounds, state }: DashboardPluginCardRenderArgs): void {
const font = getDefaultSmallFont();
const media = state.media;
image.drawText(font, bounds.x + 10, bounds.y + 14, "Now playing", 180);
@@ -30,24 +36,10 @@ export const musicControllerDashboardPlugin: DashboardPlugin = {
}
image.drawText(font, bounds.x + 10, bounds.y + 62, artistLine, 160);
image.drawText(font, bounds.x + 10, bounds.y + bounds.height - 18, playbackLabel(media), 130);
},
createFullscreenLayer: (getState) => new MusicControllerLayer(getState),
};
}
function playbackLabel(media: MediaControllerState): string {
switch (media.playbackState) {
case "playing":
return "Playing";
case "paused":
return "Paused";
case "buffering":
return "Buffering";
case "stopped":
return "Stopped";
case "notification-access-required":
return "Access required";
default:
return media.status || "Idle";
override createFullscreenLayer(getState: () => DashboardPluginState): Layer {
return new MusicControllerLayer(getState);
}
}
@@ -120,4 +112,22 @@ class MusicControllerLayer implements Layer {
return;
}
}
}
}
function playbackLabel(media: MediaControllerState): string {
switch (media.playbackState) {
case "playing":
return "Playing";
case "paused":
return "Paused";
case "buffering":
return "Buffering";
case "stopped":
return "Stopped";
case "notification-access-required":
return "Access required";
default:
return media.status || "Idle";
}
}
+18 -28
View File
@@ -1,8 +1,9 @@
import { BdfFont, getDefaultLargeFont, getDefaultSmallFont } from "../../graphics/bdffont";
import { GrayImage, imageFromAsciiArt } from "../../graphics/image";
import { DashboardPlugin, DashboardPluginState } from "../dashboard-plugins";
import { DashboardPlugin, DashboardPluginCardRenderArgs, DashboardPluginState } from "../dashboard-plugins";
import { DashboardInputEvent, Layer, LayerContext } from "../layers";
import { nightscoutBridge, type NightscoutState } from "../../native/nightscout-bridge";
import { formatAgeShortFromTimestamp, formatTimestamp } from "~/util/date-util";
const nightscoutLargeFont = getDefaultLargeFont();
const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
@@ -10,10 +11,15 @@ const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
export const nightscoutDashboardPlugin: DashboardPlugin = {
id: "nightscout",
label: "Nightscout",
renderCard: ({ image, bounds, state }) => {
export class NightscoutDashboardPlugin extends DashboardPlugin {
constructor() {
super({
id: "nightscout",
label: "Nightscout",
});
}
override renderCard({ image, bounds, state }: DashboardPluginCardRenderArgs): void {
const font = getDefaultSmallFont();
const nightscout = state.nightscout;
const nowMs = Date.now();
@@ -64,8 +70,11 @@ export const nightscoutDashboardPlugin: DashboardPlugin = {
nowMs,
font,
);
},
createFullscreenLayer: (getState) => new NightscoutLayer(getState),
}
override createFullscreenLayer(getState: () => DashboardPluginState): Layer {
return new NightscoutLayer(getState);
}
}
function drawNightscoutDelta(
@@ -157,21 +166,6 @@ function formatBolusLabel(value: number): string {
return Number.isInteger(value) ? `${value}` : value.toFixed(1);
}
function formatAgeShortFromTimestamp(timestampMs: number | null, nowMs: number): string {
if (!timestampMs) {
return "--";
}
const elapsedMinutes = Math.max(0, Math.round((nowMs - timestampMs) / 60_000));
if (elapsedMinutes < 60) {
return `${elapsedMinutes}m`;
}
const elapsedHours = Math.round(elapsedMinutes / 60);
if (elapsedHours < 48) {
return `${elapsedHours}h`;
}
return `${Math.round(elapsedHours / 24)}d`;
}
function drawNightscoutGraph(
image: GrayImage,
bounds: { x: number; y: number; width: number; height: number },
@@ -371,6 +365,7 @@ function drawNightscoutReferenceLine(
image.drawLine(bounds.x + 1, y, bounds.x + bounds.width - 2, y, shade);
}
class NightscoutLayer implements Layer {
constructor(private readonly getState: () => DashboardPluginState) {}
@@ -443,15 +438,10 @@ class NightscoutLayer implements Layer {
}
}
function formatTimestamp(timestampMs: number): string {
const date = new Date(timestampMs);
return `${String(date.getHours()).padStart(2, "0")}:${String(date.getMinutes()).padStart(2, "0")}`;
}
function isNightscoutPointStale(point: NightscoutState["latest"], nowMs: number): boolean {
return point !== null && nowMs - point.timestampMs > NIGHTSCOUT_STALE_MS;
}
function drawNightscoutValueStrikeThrough(image: GrayImage, x: number, y: number, width: number): void {
image.drawLine(x, y, x + width, y, 180);
}
}