forked from Blendman974/faceclaw
[verified] merge upstream c162c8e6 into all-features
This commit is contained in:
commit
5790e98d27
176 files changed
+5311
-2307
No files matched your search
@@ -9,11 +9,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, textSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
||||
import { enumSettingMenuItem, saveRecordingSetting, textSettingMenuItem, toggleSettingMenuItem } from "../../ui/dashboard-settings";
|
||||
import {
|
||||
createInProcessWindow,
|
||||
YieldAtRootLayer,
|
||||
@@ -46,6 +47,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.
|
||||
@@ -53,15 +59,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,
|
||||
@@ -79,6 +88,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) => {
|
||||
@@ -98,6 +109,7 @@ export function createTranslateAppWindow(options: TranslateAppOptions): InProces
|
||||
removeSurface: options.removeSurface,
|
||||
onClosed: () => {
|
||||
layer.onRemoved();
|
||||
unsubscribeRecording();
|
||||
options.stopContinuousVoiceCapture();
|
||||
shell.setTrayIcon(TRAY_ICON_ID, null);
|
||||
options.onClosed();
|
||||
@@ -106,6 +118,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;
|
||||
}
|
||||
@@ -1,13 +1,13 @@
|
||||
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";
|
||||
import { type InputEvent } from "../../ui/gestures";
|
||||
import { type LlmStreamHandle } from "../../assistant/llm-protocol";
|
||||
import { TranscriptScroll, wrapTranscribeText } from "../transcribe/transcript-model";
|
||||
import { TranscriptScroll, transcriptLayout, wrapTranscribeText } from "../transcribe/transcript-model";
|
||||
import { TranslationModel, type TranslationJob, type TranslationLine } from "./translation-model";
|
||||
import { resolveTranslationModel, streamTranslation } from "./translate-llm";
|
||||
import { resolveTranslateLanguage, spokenLanguageName, translateShowOriginalSetting } from "./translate-settings";
|
||||
@@ -72,14 +72,20 @@ export class TranslateLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
const font = getDefaultSmallFont();
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(width, height, 0);
|
||||
const viewport = ctx.stack.getBaseSize();
|
||||
const image = new GrayImage(viewport.width, viewport.height, 0);
|
||||
const measure = (line: string) => font.measureText(line);
|
||||
const maxWidth = width - 64;
|
||||
|
||||
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);
|
||||
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;
|
||||
|
||||
let lines: TranslationLine[];
|
||||
if (this.problem) {
|
||||
@@ -92,20 +98,18 @@ export class TranslateLayer implements Layer {
|
||||
}
|
||||
}
|
||||
|
||||
const step = lineStep(font) + 2;
|
||||
const bodyLines = Math.max(1, Math.floor((height - 6 - bodyTop - font.lineHeight) / step) + 1);
|
||||
const firstLine = this.scroll.layout(lines.length, bodyLines);
|
||||
for (let index = firstLine; index < Math.min(lines.length, firstLine + bodyLines); index++) {
|
||||
const firstLine = this.scroll.layout(lines.length, layout.pageLines);
|
||||
for (let index = firstLine; index < Math.min(lines.length, firstLine + layout.drawnLines); index++) {
|
||||
const y = bodyTop + (index - firstLine) * step;
|
||||
image.drawText(font, 32, y, lines[index]!.text, lines[index]!.gray);
|
||||
image.drawText(font, layout.textX, y, lines[index]!.text, lines[index]!.gray);
|
||||
}
|
||||
|
||||
if (lines.length > bodyLines) {
|
||||
const trackHeight = height - bodyTop - 6;
|
||||
const thumbHeight = Math.max(8, Math.round(trackHeight * bodyLines / lines.length));
|
||||
const thumbY = bodyTop + Math.round((trackHeight - thumbHeight) * firstLine / (lines.length - bodyLines));
|
||||
image.fillRect(width - 14, bodyTop, 2, trackHeight, 45);
|
||||
image.fillRect(width - 14, thumbY, 2, thumbHeight, 140);
|
||||
if (lines.length > layout.pageLines) {
|
||||
const track = layout.scrollbar;
|
||||
const thumbHeight = Math.max(8, Math.round(track.height * layout.pageLines / lines.length));
|
||||
const thumbY = track.y + Math.round((track.height - thumbHeight) * firstLine / (lines.length - layout.pageLines));
|
||||
image.fillRect(track.x, track.y, track.width, track.height, 45);
|
||||
image.fillRect(track.x, thumbY, track.width, thumbHeight, 140);
|
||||
}
|
||||
return image;
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user