Build your personal knowledge base with Trilium Notes
TypeScript electronelectron-appknowledge-baseknowledge-graphknowledge-managementknowledge-management-graphlocal-firstnote-managmentnote-takernote-takingnotebooknotesnotes-apppersonal-knowledge-basepersonal-wikiscriptableself-hostedself-hostingwiki
feat(transcription): show how long the meeting has been recording
Elian Dorancd240f19137b
diff --git a/apps/client/src/widgets/launch_bar/RecordMeetingButton.css b/apps/client/src/widgets/launch_bar/RecordMeetingButton.cssindex 1b4b7d9c2c..7003636d41 100644--- a/apps/client/src/widgets/launch_bar/RecordMeetingButton.css+++ b/apps/client/src/widgets/launch_bar/RecordMeetingButton.css@@ -1,12 +1,12 @@-.launcher-button.record-meeting-active {+#launcher-pane .launcher-button.record-meeting-active,+#launcher-pane .launcher-button.record-meeting-active:hover {color: var(--danger-color, #dc3545);}.record-meeting-launcher {position: relative;- .record-meeting-beta-badge {- --color: var(--link-color, var(--main-text-color));+ .ext-badge {--badge-radius: 4px;position: absolute;inset-inline-end: var(--launcher-pane-button-margin, 0);@@ -17,4 +17,18 @@line-height: 1.4;pointer-events: none;}++ .record-meeting-beta-badge {+ --color: var(--link-color, var(--main-text-color));+ }++ .record-meeting-time-badge {+ --color: var(--left-pane-item-selected-background, var(--main-background-color));+ background:+ linear-gradient(var(--color), var(--color)),+ var(--launcher-pane-background-color, var(--main-background-color));+ color: var(--left-pane-item-selected-color, var(--main-text-color));+ box-shadow: var(--left-pane-item-selected-shadow);+ font-variant-numeric: tabular-nums;+ }}diff --git a/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsx b/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsxindex 35a00c98af..c1196f5285 100644--- a/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsx+++ b/apps/client/src/widgets/launch_bar/RecordMeetingButton.spec.tsx@@ -51,7 +51,9 @@ vi.mock("./launch_bar_widgets", () => ({useLauncherIconAndTitle: () => ({ icon: "bx bx-microphone", title: "Record meeting" })}));-import RecordMeetingButton, { createMeetingNote, toggleRecording } from "./RecordMeetingButton";+import RecordMeetingButton, {+ createMeetingNote, formatElapsed, toggleRecording+} from "./RecordMeetingButton";beforeEach(() => {vi.clearAllMocks();@@ -158,7 +160,60 @@ describe("toggleRecording", () => {});});+describe("formatElapsed", () => {+ it("counts minutes and seconds within the first hour, then hours and minutes", () => {+ expect(formatElapsed(0)).toBe("0:00");+ expect(formatElapsed(65_000)).toBe("1:05");+ expect(formatElapsed(3_599_999)).toBe("59:59");+ expect(formatElapsed(3_600_000)).toBe("1:00");+ expect(formatElapsed(3_727_000)).toBe("1:02");+ expect(formatElapsed(-5_000)).toBe("0:00");+ });+});+describe("RecordMeetingButton", () => {+ async function renderWithState(state: Partial<TranscriptionState>) {+ window.electronApi = {+ transcription: {+ getState: async () => ({+ status: "idle", noteId: null, pendingSources: [], ...state+ }),+ onStateChanged: () => () => {}+ }+ } as unknown as typeof window.electronApi;+ let container: HTMLElement | undefined;+ await act(async () => {+ container = renderInto(<RecordMeetingButton launcherNote={{} as FNote} />);+ });+ return container;+ }++ it("shows how long it has been recording in place of the beta badge", async () => {+ vi.useFakeTimers({ now: new Date(2026, 9, 13, 14, 30) });+ const container = await renderWithState({+ status: "recording", noteId: "meeting", startedAt: Date.now() - 65_000+ });+ const badge = () => container?.querySelector(".record-meeting-launcher .ext-badge");+ // Preact runs effects after paint, which the fake clock schedules.+ await act(async () => {+ await vi.advanceTimersByTimeAsync(50);+ });++ expect(badge()?.className).toContain("record-meeting-time-badge");+ expect(badge()?.textContent).toBe("1:05");+ await act(async () => {+ await vi.advanceTimersByTimeAsync(1000);+ });+ expect(badge()?.textContent).toBe("1:06");+ window.electronApi = undefined;+ });++ it("shows no badge while the recording starts", async () => {+ const container = await renderWithState({ status: "starting", noteId: "meeting" });+ expect(container?.querySelector(".record-meeting-launcher .ext-badge")).toBeNull();+ window.electronApi = undefined;+ });+it("shows nothing while transcription is turned off in the settings", () => {mocks.transcriptionEnabled = false;const container = renderInto(<RecordMeetingButton launcherNote={{} as FNote} />);diff --git a/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsx b/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsxindex 58c27c9dd2..4e5dd8b631 100644--- a/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsx+++ b/apps/client/src/widgets/launch_bar/RecordMeetingButton.tsx@@ -23,12 +23,14 @@ import {/*** Launcher button that records a meeting: the first click creates the meeting note and starts the* recording, the second stops it. Desktop only, since the main process does the recording, and- * shown only while `transcriptionEnabled` is on.+ * shown only while `transcriptionEnabled` is on. Its corner badge reads "Beta" while idle and the+ * time elapsed while recording.*/export default function RecordMeetingButton({ launcherNote }: LauncherNoteProps) {const { icon, title } = useLauncherIconAndTitle(launcherNote);- const { status, error } = useTranscriptionState();+ const { status, error, startedAt } = useTranscriptionState();const [ isEnabled ] = useTriliumOptionBool("transcriptionEnabled");+ const [ now, setNow ] = useState(Date.now);const handleClick = useCallback(() => {void toggleRecording(status);}, [ status ]);@@ -39,6 +41,15 @@ export default function RecordMeetingButton({ launcherNote }: LauncherNoteProps)}}, [ error ]);+ useEffect(() => {+ if (status !== "recording") {+ return;+ }+ setNow(Date.now());+ const interval = setInterval(() => setNow(Date.now()), 1000);+ return () => clearInterval(interval);+ }, [ status ]);+if (!isEnabled) {return null;}@@ -50,7 +61,15 @@ export default function RecordMeetingButton({ launcherNote }: LauncherNoteProps)onClick={handleClick}{...getAppearance(status, icon, title)}/>- <Badge text={t("common.beta")} className="record-meeting-beta-badge" />+ {status === "idle" && (+ <Badge text={t("common.beta")} className="record-meeting-beta-badge" />+ )}+ {status === "recording" && startedAt !== undefined && (+ <Badge+ text={formatElapsed(now - startedAt)}+ className="record-meeting-time-badge"+ />+ )}</div>);}@@ -148,3 +167,14 @@ export async function createMeetingNote() {attributes: [ { type: "label", name: MEETING_RECORDING_LABEL, value: "" } ]});}++/** Formats a recording's length as `m:ss` within its first hour and as `h:mm` from then on. */+export function formatElapsed(elapsedMs: number) {+ const totalSeconds = Math.max(0, Math.floor(elapsedMs / 1000));+ const hours = Math.floor(totalSeconds / 3600);+ const minutes = Math.floor(totalSeconds / 60) % 60;+ if (hours) {+ return `${hours}:${String(minutes).padStart(2, "0")}`;+ }+ return `${minutes}:${String(totalSeconds % 60).padStart(2, "0")}`;+}diff --git a/apps/desktop/src/services/transcription/index.spec.ts b/apps/desktop/src/services/transcription/index.spec.tsindex 25a8595a5f..7ce35f2ba8 100644--- a/apps/desktop/src/services/transcription/index.spec.ts+++ b/apps/desktop/src/services/transcription/index.spec.ts@@ -160,8 +160,9 @@ describe("transcription IPC", () => {expect(await invoke("transcription-start", "meeting")).toBe("");expect(await invoke("transcription-start", "meeting")).toBe("transcription.already-recording");- expect(await invoke("transcription-get-state"))- .toEqual({ status: "recording", noteId: "meeting", pendingSources: [] });+ expect(await invoke("transcription-get-state")).toEqual({+ status: "recording", noteId: "meeting", pendingSources: [], startedAt: STARTED_AT+ });await invoke("transcription-stop");expect(h.capture.stop.mock.invocationCallOrder[0])@@ -226,7 +227,7 @@ describe("transcription IPC", () => {h.listeners?.onPendingChanged([ "system" ]);expect(h.broadcast.at(-1)).toEqual({- status: "recording", noteId: "meeting", pendingSources: [ "system" ]+ status: "recording", noteId: "meeting", pendingSources: [ "system" ], startedAt: STARTED_AT});expect(await invoke("transcription-get-state")).toEqual(h.broadcast.at(-1));@@ -249,7 +250,7 @@ describe("transcription IPC", () => {h.listeners?.onUtterance(utterance);const errors = h.broadcast.filter((state) => state.error);expect(errors).toEqual([ 1, 2 ].map(() => ({- status: "recording", noteId: "meeting", pendingSources: [],+ status: "recording", noteId: "meeting", pendingSources: [], startedAt: STARTED_AT,error: "transcription.save-locked"})));expect(await invoke("transcription-get-state")).not.toHaveProperty("error");diff --git a/apps/desktop/src/services/transcription/index.ts b/apps/desktop/src/services/transcription/index.tsindex 5f0b1faba5..e917c17dba 100644--- a/apps/desktop/src/services/transcription/index.ts+++ b/apps/desktop/src/services/transcription/index.ts@@ -103,7 +103,7 @@ export async function startRecording(noteId: unknown): Promise<string> {recording.worker.connectCapture(port2);const sources = await recording.capture.start(port1);getLog().info(`Transcription: recording ${sources.join(" and ")} for note ${noteId}.`);- setState({ ...state, status: "recording" });+ setState({ ...state, status: "recording", startedAt });return "";} catch (e) {activeRecording = null;diff --git a/packages/commons/src/lib/electron_api_interface.ts b/packages/commons/src/lib/electron_api_interface.tsindex 3e455d31bd..b3a5ec8b85 100644--- a/packages/commons/src/lib/electron_api_interface.ts+++ b/packages/commons/src/lib/electron_api_interface.ts@@ -724,6 +724,11 @@ export interface TranscriptionState {noteId: string | null;/** The sources heard speaking, or whose speech is still being transcribed. */pendingSources: TranscriptSource[];+ /**+ * When the recording started, in milliseconds since the epoch: set once it records, kept while+ * it stops, absent otherwise.+ */+ startedAt?: number;/*** A problem to tell the user about, sent once with the state it concerns: the recording ended* without being stopped, or its transcript cannot be saved. `getState()` never returns it.