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

-86
View File
@@ -1,86 +0,0 @@
import { getDefaultSmallFont } from "~/graphics/bdffont";
import { getPluginIdForSlot, getPluginState, TOP_LEFT_MENU_LAYOUT } from "../dashboard";
import { getDashboardPlugin, isBlankDashboardPlugin } from "../dashboard-plugins";
import { DashboardSlotId, dashboardSlotIds, isNightscoutSettingsConfigured } from "../dashboard-settings";
import { DashboardInputEvent, LayerContext } from "../layers";
import { MenuLayer } from "../menu";
import { createNightscoutSettingsMenuLayer } from "./settings-menus";
import { TranscribeLayer } from "../apps/transcribe";
import { GrayImage } from "~/graphics/image";
import { shell } from "../shell/shell";
const rootMenuFont = getDefaultSmallFont();
class RootMenuLayer extends MenuLayer {
async handleInput(event: DashboardInputEvent, ctx: LayerContext): Promise<void> {
if (event.type === "double-click") {
// Backing out of the window's root returns focus to the shell sidebar.
shell.yieldFocusToSidebar();
return;
}
await super.handleInput(event, ctx);
}
}
export function createRootMenuLayer(): MenuLayer {
return new RootMenuLayer(
null,
[
{
label: "Apps",
onSelect: (ctx) => {
ctx.stack.push(createAppsMenuLayer());
},
},
...dashboardSlotIds
.filter((slot) => !isBlankDashboardPlugin(getPluginIdForSlot(slot)))
.map((slot) => ({
label: pluginLabelForSlot(slot),
onSelect: (ctx: LayerContext) => {
openDashboardSlot(slot, ctx);
},
render: ({ image, x, y }: { image: GrayImage; x: number; y: number }) => {
image.drawText(rootMenuFont, x, y + 3, pluginLabelForSlot(slot), 200);
},
})),
],
TOP_LEFT_MENU_LAYOUT,
);
}
function createAppsMenuLayer(): MenuLayer {
return new MenuLayer(
"Apps",
[
{
label: "Transcribe",
onSelect: (ctx) => {
const layer = new TranscribeLayer();
ctx.stack.push(layer);
layer.start(ctx);
},
},
],
TOP_LEFT_MENU_LAYOUT,
);
}
function openDashboardSlot(slot: DashboardSlotId, ctx: LayerContext): void {
const pluginId = getPluginIdForSlot(slot);
if (isBlankDashboardPlugin(pluginId)) {
return;
}
if (pluginId === "nightscout" && !isNightscoutSettingsConfigured()) {
ctx.stack.push(createNightscoutSettingsMenuLayer());
return;
}
const layer = getDashboardPlugin(pluginId).createFullscreenLayer?.(getPluginState);
if (layer) {
ctx.stack.push(layer);
}
}
function pluginLabelForSlot(slot: DashboardSlotId): string {
return getDashboardPlugin(getPluginIdForSlot(slot)).label;
}
+8 -47
View File
@@ -1,14 +1,12 @@
import { APP_VIEWPORT } from "../shell/geometry";
import { type MenuLayout } from "../menu";
// Settings menus render in both the dashboard window (full lens) and the
// Settings app window (viewport-sized); cap heights to the smaller of the two.
const SETTINGS_MENU_LAYOUT: MenuLayout = { x: 8, y: 8, width: 272, maxHeight: APP_VIEWPORT.height - 16 };
import { MenuLayer, type MenuLayout } from "../menu";
import { shell } from "../shell/shell";
import { batteryDisplayModeSetting, dashboardSlotIds, elevenLabsApiKeySetting, enumSettingMenuItem, firmwareDebugFlagsSetting, rawScreenshotsEnabledSetting, saveVoiceRecordingsSetting, showSignalStrengthSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, systemCardNameSetting, terminalAuthTokenSetting, terminalHostSetting, terminalPortSetting, textSettingMenuItem, toggleSettingMenuItem, voiceProviderSetting, dashboardSlotSettings, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
import { MenuLayer } from "../menu";
import { batteryDisplayModeSetting, elevenLabsApiKeySetting, enumSettingMenuItem, firmwareDebugFlagsSetting, rawScreenshotsEnabledSetting, saveVoiceRecordingsSetting, terminalAuthTokenSetting, terminalHostSetting, terminalPortSetting, textSettingMenuItem, toggleSettingMenuItem, voiceProviderSetting, nightscoutSiteUrlSetting, nightscoutApiTokenSetting, screenTimeoutSetting } from "../dashboard-settings";
import { AboutPage } from "./about-page";
// Rendered in the Settings app window (viewport-sized); cap height to it.
const SETTINGS_MENU_LAYOUT: MenuLayout = { x: 8, y: 8, width: 272, maxHeight: APP_VIEWPORT.height - 16 };
export function createSettingsMenuLayer(): MenuLayer {
return new MenuLayer(
"Settings",
@@ -19,12 +17,6 @@ export function createSettingsMenuLayer(): MenuLayer {
ctx.stack.push(createDisplaySettingsMenuLayer());
},
},
{
label: "Dashboard",
onSelect: (ctx) => {
ctx.stack.push(createDashboardSettingsMenuLayer());
},
},
{
label: "Voice",
onSelect: (ctx) => {
@@ -96,10 +88,12 @@ function createDisplaySettingsMenuLayer(): MenuLayer {
"Settings > Display",
[
enumSettingMenuItem(screenTimeoutSetting, {
onChange: (ctx, newValue, oldValue) => {
onChange: () => {
shell.noteUserActivity();
},
}),
// Controls the top-bar battery indicators (icon vs percentage).
enumSettingMenuItem(batteryDisplayModeSetting),
],
SETTINGS_MENU_LAYOUT,
);
@@ -116,39 +110,6 @@ function createVoiceSettingsMenuLayer(): MenuLayer {
);
}
function createDashboardSettingsMenuLayer(): MenuLayer {
return new MenuLayer(
"Settings > Dashboard",
[
{
label: "System Card",
onSelect: (ctx) => {
ctx.stack.push(createSystemCardSettingsMenuLayer());
},
},
...dashboardSlotIds.map((slot) => enumSettingMenuItem(dashboardSlotSettings[slot], {
style: "submenu",
})),
],
SETTINGS_MENU_LAYOUT,
);
}
function createSystemCardSettingsMenuLayer(): MenuLayer {
return new MenuLayer(
"Settings > Dashboard > System Card",
[
textSettingMenuItem(systemCardNameSetting),
toggleSettingMenuItem(showFaceclawLogoSetting),
toggleSettingMenuItem(showBatteryIndicatorsSetting),
enumSettingMenuItem(batteryDisplayModeSetting),
toggleSettingMenuItem(showAndroidNotificationsSetting),
toggleSettingMenuItem(showSignalStrengthSetting),
],
SETTINGS_MENU_LAYOUT,
);
}
function createIntegrationsMenuLayer(): MenuLayer {
return new MenuLayer(
"Settings > Integrations",
-171
View File
@@ -1,171 +0,0 @@
import { GrayImage } from "../../graphics/image";
import { spanCurrent } from "../../native/frame-timings";
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../util/render-freshness";
import { BATTERY_ICON_WIDTH, drawBattery } from "../../graphics/battery";
import { readActiveNotificationIcons } from "../../native/notification-icons";
import { readPhoneBatteryState } from "../../native/phone-battery";
import { readSystemStatusIcons } from "../../native/system-status-icons";
import { type DashboardPluginCardBounds } from "../dashboard-plugins";
import { dashboardState } from "../dashboard";
import { getDefaultMediumFont, getDefaultSmallFont } from "~/graphics/bdffont";
import { getDashboardLogo } from "~/graphics/logo";
import { batteryDisplayModeSetting, showAndroidNotificationsSetting, showBatteryIndicatorsSetting, showFaceclawLogoSetting, showSignalStrengthSetting, systemCardNameSetting } from "../dashboard-settings";
const NOTIFICATION_ICON_SIZE = 24;
const SYSTEM_CARD_ITEM_HEIGHT = 38;
const SYSTEM_CARD_ITEM_GAP = 2;
const BATTERY_ITEM_Y_OFFSET = 4;
const MONTHS = ["Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"];
const WEEKDAYS = ["Sun", "Mon", "Tue", "Wed", "Thu", "Fri", "Sat"];
type SystemCardFlowItem =
| { type: "battery"; label: string; percentCharge: number; isCharging: boolean }
| { type: "notification"; icon: GrayImage };
const smallFont = getDefaultSmallFont();
const mediumFont = getDefaultMediumFont();
function drawSystemCardFlowItems(image: GrayImage, bounds: DashboardPluginCardBounds): void {
const left = bounds.x + 10;
const top = bounds.y + 84;
const right = bounds.x + bounds.width - 10;
const bottom = bounds.y + bounds.height - 6;
const items: SystemCardFlowItem[] = [];
if (showAndroidNotificationsSetting.get()) {
const maxNotificationIcons = Math.max(0, ((right - left) / Math.max(1, NOTIFICATION_ICON_SIZE + SYSTEM_CARD_ITEM_GAP)) | 0) * 2;
const { icons, stale } = readActiveNotificationIcons(maxNotificationIcons, renderPassAllowsStaleData());
if (stale) {
noteStaleDataUsed();
}
for (const icon of icons) {
items.push({ type: "notification", icon });
}
}
items.push(...collectBatteryItems());
if (showSignalStrengthSetting.get()) {
for (const icon of readSystemStatusIcons()) {
items.push({ type: "notification", icon });
}
}
let itemX = left;
let itemY = top;
for (const item of items) {
const itemWidth = systemCardFlowItemWidth(item);
if (itemX > left && itemX + itemWidth > right) {
itemX = left;
itemY += SYSTEM_CARD_ITEM_HEIGHT + SYSTEM_CARD_ITEM_GAP;
}
if (itemY + SYSTEM_CARD_ITEM_HEIGHT > bottom) {
break;
}
if (item.type === "battery") {
drawBatteryFlowItem(image, itemX, itemY, item);
} else {
image.bitBlt(
item.icon,
itemX,
itemY + ((SYSTEM_CARD_ITEM_HEIGHT - NOTIFICATION_ICON_SIZE) / 2) | 0,
);
}
itemX += itemWidth + SYSTEM_CARD_ITEM_GAP;
}
}
function systemCardFlowItemWidth(item: SystemCardFlowItem): number {
if (item.type === "notification") {
return NOTIFICATION_ICON_SIZE;
}
if (batteryDisplayModeSetting.get() === "percentage") {
const percentText = formatBatteryPercent(item.percentCharge);
return Math.max(smallFont.measureText(percentText), smallFont.measureText(item.label));
}
return Math.max(BATTERY_ICON_WIDTH, smallFont.measureText(item.label));
}
function collectBatteryItems(): SystemCardFlowItem[] {
if (!showBatteryIndicatorsSetting.get()) return [];
const phone = readPhoneBatteryState();
const items: SystemCardFlowItem[] = [];
addBatteryItem(items, "Phone", phone.battery, phone.charging);
addBatteryItem(items, "G2", dashboardState.battery.headset, dashboardState.battery.headsetCharging);
addBatteryItem(items, "R1", dashboardState.battery.ring, null);
return items;
}
function addBatteryItem(
items: SystemCardFlowItem[],
label: string,
percentCharge: number | null,
isCharging: boolean | null,
): void {
if (percentCharge === null || !Number.isFinite(percentCharge)) return;
items.push({
type: "battery",
label,
percentCharge,
isCharging: Boolean(isCharging),
});
}
function formatBatteryPercent(percentCharge: number): string {
const clamped = Math.max(0, Math.min(100, Math.round(percentCharge)));
return `${clamped}%`;
}
function drawBatteryFlowItem(image: GrayImage, x: number, y: number, item: Extract<SystemCardFlowItem, { type: "battery" }>): void {
const itemWidth = systemCardFlowItemWidth(item);
const labelX = x + Math.max(0, ((itemWidth - smallFont.measureText(item.label)) / 2) | 0);
image.drawText(smallFont, labelX, y + BATTERY_ITEM_Y_OFFSET, item.label, 150);
if (batteryDisplayModeSetting.get() === "percentage") {
drawBatteryPercentFlowItem(image, x, y, item, itemWidth);
return;
}
const battery = drawBattery(item.percentCharge, item.isCharging);
image.bitBlt(battery, x + ((itemWidth - battery.width) / 2) | 0, y + 16 + BATTERY_ITEM_Y_OFFSET);
}
function drawBatteryPercentFlowItem(
image: GrayImage,
x: number,
y: number,
item: Extract<SystemCardFlowItem, { type: "battery" }>,
itemWidth: number,
): void {
const percentText = formatBatteryPercent(item.percentCharge);
const textWidth = smallFont.measureText(percentText);
const textX = x + Math.max(0, ((itemWidth - textWidth) / 2) | 0);
const textY = y + 16 + BATTERY_ITEM_Y_OFFSET;
if (item.isCharging) {
const padX = 2;
const padY = 1;
image.fillRect(textX - padX, textY - padY, textWidth + padX * 2, smallFont.lineHeight + padY * 2, 255);
image.drawText(smallFont, textX, textY, percentText, 0);
return;
}
image.drawText(smallFont, textX, textY, percentText, 200);
}
function formatDashboardDate(now: Date): string {
return `${WEEKDAYS[now.getDay()]} ${MONTHS[now.getMonth()]} ${now.getDate()} ${pad2(now.getHours())}:${pad2(now.getMinutes())}`;
}
function pad2(value: number): string {
return String(value).padStart(2, "0");
}
export function drawSystemCard(image: GrayImage, bounds: DashboardPluginCardBounds): void {
spanCurrent("draw-system-card", () => {
const now = new Date();
const logo = getDashboardLogo();
if (logo && showFaceclawLogoSetting.get()) {
image.bitBlt(logo, bounds.x + 10, bounds.y + 10);
}
const infoX = logo && showFaceclawLogoSetting.get() ? bounds.x + 92 : bounds.x + 10;
image.drawText(mediumFont, infoX, bounds.y + 10, systemCardNameSetting.get(), 200);
image.drawText(mediumFont, infoX, bounds.y + 32, formatDashboardDate(now), 200);
drawSystemCardFlowItems(image, bounds);
});
}