Port Transcribe to new UI; remove legacy dashboard

This commit is contained in:
James Babcock committed 2026-07-07 22:11:28 -07:00
1 parent 56d0f8c351
commit d0c30f9ca9
21 files changed
+392 -1291

No files matched your search

-71
View File
@@ -1,71 +0,0 @@
import takeRight from "lodash/takeRight";
import { getDefaultSmallFont } from "~/graphics/bdffont";
import { DashboardPlugin, type DashboardPluginCardRenderArgs, type DashboardPluginState } from "../dashboard-plugin";
import { Layer, LayerContext, type DashboardInputEvent } from "../layers";
import { GrayImage } from "~/graphics/image";
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;
const visibleLineCount = Math.max(1, Math.floor((bounds.height - 28) / lineHeight));
const visibleLines = takeRight(state.logLines, visibleLineCount);
for (let i = 0; i < visibleLines.length; i++) {
image.drawText(font, bounds.x + 8, bounds.y + 26 + i * lineHeight, visibleLines[i]!, 190);
}
}
override createFullscreenLayer(getState: () => DashboardPluginState): Layer {
return new DebugLogLayer(getState);
}
}
class DebugLogLayer implements Layer {
private scrollOffset = 0;
constructor(private readonly getState: () => DashboardPluginState) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(576, 288, 0);
image.drawRect(12, 12, 552, 264, 52);
image.drawText(font, 22, 16, "Input debug log", 220);
const logs = this.getState().logLines;
const lineHeight = 14;
const visibleCount = Math.max(1, Math.floor((288 - 64) / lineHeight));
const maxOffset = Math.max(0, logs.length - visibleCount);
this.scrollOffset = Math.max(0, Math.min(this.scrollOffset, maxOffset));
const start = Math.max(0, maxOffset - this.scrollOffset);
const visible = logs.slice(start, start + visibleCount);
for (let index = 0; index < visible.length; index++) {
image.drawText(font, 22, 42 + index * lineHeight, visible[index]!, 180);
}
image.drawText(font, 22, 252, "Scroll: browse Double-click: back", 110);
return image;
}
handleInput(event: DashboardInputEvent, ctx: LayerContext): void {
switch (event.type) {
case "scroll-up":
this.scrollOffset += 1;
return;
case "scroll-down":
this.scrollOffset = Math.max(0, this.scrollOffset - 1);
return;
case "double-click":
ctx.stack.pop();
return;
default:
return;
}
}
}
-59
View File
@@ -1,59 +0,0 @@
import { DashboardPlugin, type DashboardPluginCardRenderArgs, type DashboardPluginState } from "../dashboard-plugin";
import { getDefaultSmallFont } from "../../graphics/bdffont";
import { GrayImage } from "../../graphics/image";
import { wrapText } from "../../graphics/textwrap";
import { mediaControllerBridge, type MediaControllerState } from "../../native/media-controller";
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);
if (!media.accessEnabled) {
image.drawText(font, bounds.x + 10, bounds.y + 30, "Enable notification", 150);
image.drawText(font, bounds.x + 10, bounds.y + 44, "access for media", 150);
return;
}
if (!media.available) {
image.drawText(font, bounds.x + 10, bounds.y + 30, "No active session", 150);
return;
}
const titleLines = wrapText(font, media.title || "Unknown title", bounds.width - 20).slice(0, 2);
const artistLine = media.artist || media.album || media.packageName || "Unknown source";
image.drawText(font, bounds.x + 10, bounds.y + 30, titleLines[0] ?? "", 210);
if (titleLines[1]) {
image.drawText(font, bounds.x + 10, bounds.y + 44, titleLines[1], 210);
}
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);
}
}
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";
}
}
+3 -83
View File
@@ -1,8 +1,8 @@
import { BdfFont, getDefaultLargeFont, getDefaultSmallFont } from "../../graphics/bdffont";
import { GrayImage, imageFromAsciiArt } from "../../graphics/image";
import { DashboardPlugin, type DashboardPluginCardRenderArgs, type DashboardPluginState } from "../dashboard-plugin";
import { DashboardInputEvent, Layer, LayerContext } from "../layers";
import { nightscoutBridge, type NightscoutState } from "../../native/nightscout-bridge";
import { isNightscoutSettingsConfigured } from "../dashboard-settings";
import { formatAgeShortFromTimestamp, formatTimestamp } from "~/util/date-util";
const nightscoutLargeFont = getDefaultLargeFont();
@@ -10,84 +10,6 @@ const NIGHTSCOUT_STALE_MS = 15 * 60 * 1000;
const NIGHTSCOUT_GRAPH_WINDOW_MS = 2 * 60 * 60 * 1000;
const NIGHTSCOUT_GRAPH_TIME_QUANTUM_MS = 60 * 1000;
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();
image.drawText(font, bounds.x + 10, bounds.y + 10, "Nightscout", 180);
if (!state.nightscoutConfigured || nightscout.configurationMissing) {
image.drawText(font, bounds.x + 10, bounds.y + 30, "Needs setup", 170);
image.drawText(font, bounds.x + 10, bounds.y + 44, "Click to configure", 140);
return;
}
if (!nightscout.available || !nightscout.latest) {
image.drawText(font, bounds.x + 10, bounds.y + 30, "No glucose data", 150);
image.drawText(font, bounds.x + 10, bounds.y + 44, truncateLine(nightscout.status, 26), 120);
return;
}
const latest = nightscout.latest;
const deltaLabel = formatDelta(nightscout.delta);
const glucoseText = `${latest.sgv}`;
const glucoseX = bounds.x + bounds.width - 92;
image.drawText(nightscoutLargeFont, glucoseX, bounds.y + 10, glucoseText, 230);
if (isNightscoutPointStale(latest, nowMs)) {
drawNightscoutValueStrikeThrough(image, glucoseX, bounds.y + 22, nightscoutLargeFont.measureText(glucoseText));
}
drawNightscoutDelta(image, font, bounds.x + bounds.width - 92, bounds.y + 30, deltaLabel, nightscout.direction, 160);
image.drawText(
font,
bounds.x + 10,
bounds.y + 30,
`IOB ${nightscout.iob === null ? "--" : nightscout.iob.toFixed(1)} COB ${nightscout.cob === null ? "--" : formatWholeNumber(nightscout.cob)}`,
160,
);
image.drawText(
font,
bounds.x + 10,
bounds.y + 44,
`Loop ${nightscout.openapsStatusShort} CAGE ${formatAgeShortFromTimestamp(nightscout.cageTimestampMs, nowMs)}`,
138,
);
drawNightscoutGraph(
image,
{
x: bounds.x + 10,
y: bounds.y + 60,
width: bounds.width - 20,
height: Math.max(16, bounds.height - 82),
},
nightscout,
nowMs,
font,
);
}
}
function drawNightscoutDelta(
image: GrayImage,
font: BdfFont,
x: number,
y: number,
deltaLabel: string,
direction: string,
shade: number,
): void {
const text = direction ? `${deltaLabel} ` : deltaLabel;
image.drawText(font, x, y, text, shade);
drawDirectionIndicator(image, font, x + font.measureText(text), y, direction, shade);
}
function drawDirectionIndicator(
image: GrayImage,
font: BdfFont,
@@ -364,20 +286,18 @@ function drawNightscoutReferenceLine(
export class NightscoutLayer implements Layer {
constructor(private readonly getState: () => DashboardPluginState) {}
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
// Sized to the hosting stack (the Nightscout app viewport).
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const nightscout = this.getState().nightscout;
const nightscout = nightscoutBridge.snapshot();
const nowMs = Date.now();
const footerY = height - 26;
image.drawRect(12, 12, width - 24, height - 24, 52);
image.drawText(font, 22, 16, "Nightscout", 220);
if (!this.getState().nightscoutConfigured || nightscout.configurationMissing) {
if (!isNightscoutSettingsConfigured() || nightscout.configurationMissing) {
image.drawText(font, 22, 44, "Nightscout needs configuration.", 180);
image.drawText(font, 22, 62, "Use Settings > Integrations > Nightscout.", 140);
return image;
+52 -21
View File
@@ -1,50 +1,65 @@
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
import { GrayImage } from "../../graphics/image";
import { getDefaultSmallFont, type BdfFont } from "../../graphics/bdffont";
import { writeTextToDownloads } from "../../native/file-access";
import { voiceControlBridge, type VoiceTranscriptEvent } from "../../native/voice-control";
import { Layer, type DashboardInputEvent, type LayerActions, type LayerContext } from "../layers";
import { Layer, type DashboardInputEvent, type LayerContext } from "../layers";
/**
* Live transcription view. Continuous mic capture is owned by the app wrapper
* (createTranscribeAppWindow); this layer accumulates the transcript, shows
* it, and saves it to Downloads on click.
*/
export class TranscribeLayer implements Layer {
private status = "Starting transcription...";
private status = "Listening...";
// Finalized utterances, plus the live (replace-semantics) partial appended
// when painting.
private finalizedText = "";
private liveText = "";
private saveNotice = "";
private unsubscribeTranscript: (() => void) | null = null;
private unsubscribeStatus: (() => void) | null = null;
private actions: LayerActions | null = null;
start(ctx: LayerContext): void {
this.actions = ctx.actions;
this.unsubscribeTranscript = voiceControlBridge.onTranscript((event) => this.onTranscript(event));
this.unsubscribeTranscript = voiceControlBridge.onTranscript((event) => {
this.onTranscript(event);
ctx.actions.requestRender();
});
this.unsubscribeStatus = voiceControlBridge.onStatus((state) => {
this.status = state.status;
ctx.actions.requestRender();
});
void ctx.actions.setTranscribeRenderActive(true);
void Promise.resolve(ctx.actions.startVoiceCapture());
}
paint(): GrayImage {
paint(ctx: LayerContext): GrayImage {
const font = getDefaultSmallFont();
const image = new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
const { width, height } = ctx.stack.getBaseSize();
const image = new GrayImage(width, height, 0);
const text = this.displayText() || "Listening...";
const wrapped = wrapTranscribeText(font, text, G2_LENS_WIDTH - 64);
const wrapped = wrapTranscribeText(font, text, width - 64);
image.drawRect(12, 12, G2_LENS_WIDTH - 24, G2_LENS_HEIGHT - 24, 52);
image.drawText(font, 24, 24, "Transcribe", 200);
image.drawText(font, 24, 46, this.status, 110);
image.drawRect(12, 12, width - 24, height - 24, 52);
image.drawText(font, 24, 20, "Transcribe", 200);
image.drawText(font, 24, 40, this.saveNotice || this.status, 110);
const firstLine = Math.max(0, wrapped.length - 10);
const bodyTop = 62;
const footerY = height - 18;
const bodyLines = Math.max(1, Math.floor((footerY - bodyTop) / 16));
const firstLine = Math.max(0, wrapped.length - bodyLines);
for (let index = firstLine; index < wrapped.length; index++) {
const y = 72 + (index - firstLine) * 16;
const y = bodyTop + (index - firstLine) * 16;
image.drawText(font, 32, y, wrapped[index]!, 230);
}
image.drawText(font, 24, 252, "Double-click: back", 110);
image.drawText(font, 24, footerY, "Click: save Double-click: back", 110);
return image;
}
handleInput(event: DashboardInputEvent, ctx: LayerContext): void {
if (event.type === "click") {
this.saveTranscript();
ctx.actions.requestRender();
return;
}
if (event.type === "double-click") {
ctx.stack.pop();
}
@@ -55,9 +70,17 @@ export class TranscribeLayer implements Layer {
this.unsubscribeTranscript = null;
this.unsubscribeStatus?.();
this.unsubscribeStatus = null;
void this.actions?.setTranscribeRenderActive(false);
void this.actions?.stopVoiceCapture();
this.actions = null;
}
private saveTranscript(): void {
const text = this.displayText().trim();
if (!text) {
this.saveNotice = "Nothing to save yet.";
return;
}
const filename = `transcript-${transcriptTimestamp()}.txt`;
const path = writeTextToDownloads(filename, `${text}\n`);
this.saveNotice = path ? `Saved ${filename}` : "Save failed (check file access).";
}
private displayText(): string {
@@ -80,6 +103,15 @@ export class TranscribeLayer implements Layer {
}
}
function transcriptTimestamp(): string {
const now = new Date();
const pad = (value: number) => String(value).padStart(2, "0");
return (
`${now.getFullYear()}-${pad(now.getMonth() + 1)}-${pad(now.getDate())}` +
`-${pad(now.getHours())}${pad(now.getMinutes())}${pad(now.getSeconds())}`
);
}
function wrapTranscribeText(font: BdfFont, text: string, maxWidth: number): string[] {
const words = text.split(/\s+/).filter(Boolean);
const lines: string[] = [];
@@ -98,4 +130,3 @@ function wrapTranscribeText(font: BdfFont, text: string, maxWidth: number): stri
}
return lines.length ? lines : [""];
}