This commit is contained in:
James Babcock committed 2026-11-12 12:20:29 -08:00
commit c162c8e633
24 files changed
+486 -154

No files matched your search

+18 -1
View File
@@ -11,6 +11,7 @@ import { ensureLocationPermission, hasLocationPermission } from "../../../native
import { onAndroidNotificationsChanged, readActiveNotificationIcons } from "../../../native/notification-icons";
import { NOTIFICATION_ICON_SIZE } from "../../../native/notification-types";
import { readPhoneBatteryState } from "../../../native/phone-battery";
import { voiceControlBridge } from "../../../native/voice-control";
import { weatherBridge } from "../../../native/weather";
import { formatClockDate, formatClockTime } from "../../../ui/clock-format";
import {
@@ -26,6 +27,7 @@ import {
watchBatteryVisibilitySetting,
type BatteryIndicatorVisibility,
} from "../../../ui/dashboard-settings";
import { RECORDING_ICON } from "../../../ui/listening-header";
import { type MenuItem } from "../../../ui/menu";
import { shell } from "../../../ui/shell/shell";
import { noteStaleDataUsed, renderPassAllowsStaleData } from "../../../util/render-freshness";
@@ -149,13 +151,16 @@ function requestWeatherLocationAccess(): void {
* off, and the layout mirrored either way, in the card's submenu of
* Glanceboard > Settings. Battery style and per-device visibility follow
* Settings > Customization > Battery indicators, so the card agrees with
* the bar. Countdowns tick once a second only while one is running.
* the bar. Countdowns tick once a second only while one is running. While
* Transcribe or Translate is saving the mic's audio (their Save Recording),
* the recording circle sits under the batteries and weather.
*/
export class SystemCardWidget implements GlanceWidget {
private requestRender: (() => void) | null = null;
private minuteTimer: ReturnType<typeof setTimeout> | null = null;
private secondTimer: ReturnType<typeof setInterval> | null = null;
private unsubscribeNotifications: (() => void) | null = null;
private unsubscribeRecording: (() => void) | null = null;
private unsubscribeSettings: (() => void) | null = null;
private unsubscribeTimers: (() => void) | null = null;
private unsubscribeWeather: (() => void) | null = null;
@@ -164,6 +169,7 @@ export class SystemCardWidget implements GlanceWidget {
this.requestRender = requestRender;
this.scheduleMinuteTick();
this.unsubscribeNotifications = onAndroidNotificationsChanged(() => this.requestRender?.());
this.unsubscribeRecording = voiceControlBridge.onRecordingChange(() => this.requestRender?.());
this.unsubscribeSettings = onAnySettingChanged(() => this.requestRender?.());
this.unsubscribeTimers = timerEngine.onChange(() => {
this.syncSecondTick();
@@ -182,6 +188,8 @@ export class SystemCardWidget implements GlanceWidget {
this.secondTimer = null;
this.unsubscribeNotifications?.();
this.unsubscribeNotifications = null;
this.unsubscribeRecording?.();
this.unsubscribeRecording = null;
this.unsubscribeSettings?.();
this.unsubscribeSettings = null;
this.unsubscribeTimers?.();
@@ -237,6 +245,8 @@ export class SystemCardWidget implements GlanceWidget {
if (batteryItems.length) sideBlocks.push(batteryBlock(small, batteryItems));
const weather = weatherShowOnSystemCardSetting.get() ? weatherBlock(medium, now.getTime()) : null;
if (weather) sideBlocks.push(weather);
// Last, so it comes and goes without moving the others.
if (voiceControlBridge.recording) sideBlocks.push(RECORDING_BLOCK);
const side: Rect[] = [];
let sideOffset = PAD;
for (const block of sideBlocks) {
@@ -382,6 +392,13 @@ function batteryBlock(font: UiFont, items: readonly BatteryItem[]): SideBlock {
};
}
/** The recording circle: the mic's audio is being saved (see RECORDING_ICON). */
const RECORDING_BLOCK: SideBlock = {
width: RECORDING_ICON.width,
height: RECORDING_ICON.height,
draw: (image, left, top) => image.drawImage(RECORDING_ICON, left, top),
};
/** The current weather's condition icon and temperature, or null without a fresh reading. */
function weatherBlock(font: UiFont, nowMs: number): SideBlock | null {
const reading = weatherReading(weatherBridge.snapshot(), nowMs);
+28 -10
View File
@@ -1,4 +1,7 @@
import { imageFromAsciiArt } from "../../graphics/image";
import { imageFromAsciiArt, type GrayImage } from "../../graphics/image";
import { voiceControlBridge } from "../../native/voice-control";
import { saveRecordingSetting, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import { withRecordingIcon } from "../../ui/listening-header";
import { TranscribeLayer, transcriptTimestamp } from "./transcribe";
import {
createInProcessWindow,
@@ -13,8 +16,8 @@ export const TRANSCRIBE_SURFACE_ID = "window:transcribe";
const TRAY_ICON_ID = "transcribe";
// 16x18 microphone glyph for the top-bar tray (also Translate's).
export const MIC_ICON = imageFromAsciiArt(
// 14x15 microphone glyph for the top-bar tray (also Translate's).
const MIC_ICON = imageFromAsciiArt(
[
" #### ",
" ###### ",
@@ -34,6 +37,12 @@ export const MIC_ICON = imageFromAsciiArt(
],
{ "#": 220 },
);
const MIC_RECORDING_ICON = withRecordingIcon(MIC_ICON);
/** The listening apps' tray icon: a microphone, with the recording circle while their audio is saved. */
export function micTrayIcon(recording: boolean): GrayImage {
return recording ? MIC_RECORDING_ICON : MIC_ICON;
}
export type TranscribeAppOptions = InProcessAppOptions & {
/** Begin continuous mic capture (kept on while the window is open). */
@@ -59,18 +68,23 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
closeable: true,
actions: options.actions,
baseLayer: new YieldAtRootLayer(layer),
menuItems: () => [{
label: "Save",
onSelect: (ctx) => {
ctx.stack.pop();
layer.saveTranscript();
menuItems: () => [
{
label: "Save",
onSelect: (ctx) => {
ctx.stack.pop();
layer.saveTranscript();
},
},
}],
// The controller starts and stops the recording as the setting changes.
toggleSettingMenuItem(saveRecordingSetting),
],
submitFrame: options.submitFrame,
setSurfaceVisible: options.setSurfaceVisible,
removeSurface: options.removeSurface,
onClosed: () => {
layer.onRemoved();
unsubscribeRecording();
options.stopContinuousVoiceCapture();
shell.setTrayIcon(TRAY_ICON_ID, null);
options.onClosed();
@@ -79,7 +93,11 @@ export function createTranscribeAppWindow(options: TranscribeAppOptions): InProc
// Wire async state changes to this window's renderer, rather than the
// controller action from which the window-specific actions were derived.
layer.start(app.requestRender, () => shell.isWindowVisible(TRANSCRIBE_WINDOW_ID));
const unsubscribeRecording = voiceControlBridge.onRecordingChange(() => {
shell.setTrayIcon(TRAY_ICON_ID, micTrayIcon(voiceControlBridge.recording));
app.requestRender();
});
options.startContinuousVoiceCapture({ recordAs: `transcribe-${stamp}` });
shell.setTrayIcon(TRAY_ICON_ID, MIC_ICON);
shell.setTrayIcon(TRAY_ICON_ID, micTrayIcon(voiceControlBridge.recording));
return app;
}
+6 -3
View File
@@ -1,7 +1,7 @@
import { GrayImage } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { lineStep } from "../../ui/metrics";
import { MicLevelMeter, paintListeningHeader } from "../../ui/listening-header";
import { MicLevelMeter, paintListeningHeader, RECORDING_FAILED_NOTICE } from "../../ui/listening-header";
import { writeTextToDownloads } from "../../native/file-access";
import { voiceControlBridge } from "../../native/voice-control";
import { Layer, type LayerContext } from "../../ui/layers";
@@ -50,8 +50,11 @@ export class TranscribeLayer implements Layer {
const viewport = ctx.stack.getBaseSize();
const image = new GrayImage(viewport.width, viewport.height, 0);
const bodyTop = paintListeningHeader(image, font, "Transcribe", this.saveNotice || this.status, this.listening ? this.meter : null,
viewport.padding);
const status = voiceControlBridge.recordingFailed ? RECORDING_FAILED_NOTICE : this.status;
const bodyTop = paintListeningHeader(
image, font, "Transcribe", this.saveNotice || status, this.listening ? this.meter : null, viewport.padding,
voiceControlBridge.recording,
);
const step = lineStep(font) + 2;
const layout = transcriptLayout(viewport, bodyTop, font.lineHeight, step);
const text = this.transcript.text || (this.listening ? "Listening..." : this.detail);
+24 -8
View File
@@ -7,11 +7,12 @@ import {
translateProviderSetting,
translateShowOriginalSetting,
} from "./translate-settings";
import { MIC_ICON } from "../transcribe/transcribe-app";
import { micTrayIcon } from "../transcribe/transcribe-app";
import { transcriptTimestamp } from "../transcribe/transcribe";
import { voiceControlBridge } from "../../native/voice-control";
import { type ContinuousCaptureOptions } from "../../ui/layers";
import { openSettingsSubMenu } from "../../ui/dashboard/settings-panel";
import { enumSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import { enumSettingMenuItem, saveRecordingSetting, toggleSettingMenuItem } from "../../ui/dashboard-settings";
import {
createInProcessWindow,
YieldAtRootLayer,
@@ -44,6 +45,11 @@ export type TranslateAppOptions = InProcessAppOptions & {
* provider (Translate settings), which a shared capture switches to.
*/
export function createTranslateAppWindow(options: TranslateAppOptions): InProcessWindow {
// One timestamp per session names both the audio recording and a saved transcript.
const stamp = transcriptTimestamp();
// Whether the mic tray icon is up (capture was asked for).
let trayIconShown = false;
const syncTrayIcon = () => shell.setTrayIcon(TRAY_ICON_ID, trayIconShown ? micTrayIcon(voiceControlBridge.recording) : null);
// Checks the setup and (re)starts capture with the chosen provider and
// language: at launch, when either setting changes, and on a tap after a
// problem.
@@ -51,15 +57,18 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
const provider = resolveTranslateProvider();
const problem = !provider ? NO_PROVIDER_PROBLEM : !resolveTranslationModel() ? NO_MODEL_PROBLEM : null;
layer.setProblem(problem);
if (!provider || problem) {
trayIconShown = Boolean(provider) && !problem;
if (provider && !problem) {
options.startContinuousVoiceCapture({
recordAs: `translate-${stamp}`,
transcription: { provider, language: resolveTranslateLanguage() },
});
} else {
options.stopContinuousVoiceCapture();
shell.setTrayIcon(TRAY_ICON_ID, null);
return;
}
options.startContinuousVoiceCapture({ transcription: { provider, language: resolveTranslateLanguage() } });
shell.setTrayIcon(TRAY_ICON_ID, MIC_ICON);
syncTrayIcon();
};
const layer = new TranslateLayer(transcriptTimestamp(), startCapture);
const layer = new TranslateLayer(stamp, startCapture);
const app = createInProcessWindow({
appId: "translate",
windowId: TRANSLATE_WINDOW_ID,
@@ -77,6 +86,8 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
layer.saveTranscript();
},
},
// The controller starts and stops the recording as the setting changes.
toggleSettingMenuItem(saveRecordingSetting),
{
label: "Translate settings",
onSelect: (ctx) => {
@@ -94,6 +105,7 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
removeSurface: options.removeSurface,
onClosed: () => {
layer.onRemoved();
unsubscribeRecording();
options.stopContinuousVoiceCapture();
shell.setTrayIcon(TRAY_ICON_ID, null);
options.onClosed();
@@ -102,6 +114,10 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
// Wire async state changes to this window's renderer, rather than the
// controller action from which the window-specific actions were derived.
layer.start(app.requestRender, () => shell.isWindowVisible(TRANSLATE_WINDOW_ID));
const unsubscribeRecording = voiceControlBridge.onRecordingChange(() => {
syncTrayIcon();
app.requestRender();
});
startCapture();
return app;
}
+7 -3
View File
@@ -1,7 +1,7 @@
import { GrayImage } from "../../graphics/image";
import { getDefaultSmallFont } from "../../graphics/ui-fonts";
import { lineStep } from "../../ui/metrics";
import { MicLevelMeter, paintListeningHeader } from "../../ui/listening-header";
import { MicLevelMeter, paintListeningHeader, RECORDING_FAILED_NOTICE } from "../../ui/listening-header";
import { writeTextToDownloads } from "../../native/file-access";
import { voiceControlBridge } from "../../native/voice-control";
import { Layer, type LayerContext } from "../../ui/layers";
@@ -76,9 +76,13 @@ export class TranslateLayer implements Layer {
const image = new GrayImage(viewport.width, viewport.height, 0);
const measure = (line: string) => font.measureText(line);
const status = this.problem ? "Setup needed" : this.translationError || this.status;
const status = this.problem
? "Setup needed"
: voiceControlBridge.recordingFailed ? RECORDING_FAILED_NOTICE : this.translationError || this.status;
const meter = this.listening && !this.problem ? this.meter : null;
const bodyTop = paintListeningHeader(image, font, "Translate", this.saveNotice || status, meter, viewport.padding);
const bodyTop = paintListeningHeader(
image, font, "Translate", this.saveNotice || status, meter, viewport.padding, voiceControlBridge.recording,
);
const step = lineStep(font) + 2;
const layout = transcriptLayout(viewport, bodyTop, font.lineHeight, step);
const maxWidth = layout.textWidth;