Skip to content

Build your personal knowledge base with Trilium Notes

fix(transcription): create the recordings folder only once recordings are kept

Elian Doran2abbdc646c12
diff --git a/.claude/skills/working-with-transcription/SKILL.md b/.claude/skills/working-with-transcription/SKILL.md
index 5c91479140..84de52c1d1 100644
--- a/.claude/skills/working-with-transcription/SKILL.md
+++ b/.claude/skills/working-with-transcription/SKILL.md
@@ -76,7 +76,7 @@ Without either directory, starting fails with `transcription.model-not-downloade
## Recordings for troubleshooting
-While the non-synced option `transcriptionKeepRecordings` is on (Options → Transcription → "Keep recordings for troubleshooting", off by default, its switch tinted red), every transcription is kept in `<data dir>/transcription-recordings/<created>_<noteId>/`; for `pnpm desktop:start` that is `apps/desktop/data/transcription-recordings/`, so turn the switch on there once to get recordings for the scripts below. Development builds follow the switch like any other. The settings link to the folder through `electronApi.transcription.getRecordingsDirectory()`, which creates it.
+While the non-synced option `transcriptionKeepRecordings` is on (Options → Transcription → "Keep recordings for troubleshooting", off by default, its switch tinted red), every transcription is kept in `<data dir>/transcription-recordings/<created>_<noteId>/`; for `pnpm desktop:start` that is `apps/desktop/data/transcription-recordings/`, so turn the switch on there once to get recordings for the scripts below. Development builds follow the switch like any other. While the switch is on, the settings link to the folder through `electronApi.transcription.getRecordingsDirectory()`, which creates it; with the switch off, they never ask, so nothing creates the folder.
| File | Holds |
|---|---|
diff --git a/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx b/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx
index 5bc69fef25..1733881034 100644
--- a/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/transcription.spec.tsx
@@ -7,6 +7,7 @@ const mocks = vi.hoisted(() => ({
stored: "" as string,
saved: [] as string[],
bools: {} as Record<string, boolean>,
+ getRecordingsDirectory: vi.fn(),
savedBools: [] as [ string, boolean ][]
}));
@@ -42,8 +43,9 @@ beforeEach(() => {
mocks.saved = [];
mocks.bools = { transcriptionSpeakersEnabled: true, transcriptionKeepRecordings: false };
mocks.savedBools = [];
+ mocks.getRecordingsDirectory.mockReset().mockResolvedValue("/data/transcription-recordings");
window.electronApi = {
- transcription: { getRecordingsDirectory: async () => "/data/transcription-recordings" }
+ transcription: { getRecordingsDirectory: mocks.getRecordingsDirectory }
} as unknown as typeof window.electronApi;
host = document.body.appendChild(document.createElement("div"));
});
@@ -98,9 +100,6 @@ describe("TranscriptionSettings", () => {
expect(toggle.checked).toBe(false);
expect(toggle.closest(".transcription-keep-recordings")).not.toBeNull();
- await act(async () => {});
- expect(host.querySelector(".directory-location-path")?.textContent).toBe("/data/transcription-recordings");
-
act(() => {
toggle.checked = true;
toggle.dispatchEvent(new Event("input", { bubbles: true }));
@@ -108,6 +107,20 @@ describe("TranscriptionSettings", () => {
expect(mocks.savedBools).toEqual([ [ "transcriptionKeepRecordings", true ] ]);
});
+ it("asks for the recordings folder, which creates it, only while recordings are kept", async () => {
+ open();
+ await act(async () => {});
+ expect(mocks.getRecordingsDirectory).not.toHaveBeenCalled();
+ expect(host.querySelector(".directory-location")).toBeNull();
+
+ act(() => render(null, host));
+ mocks.bools.transcriptionKeepRecordings = true;
+ open();
+ await act(async () => {});
+ expect(mocks.getRecordingsDirectory).toHaveBeenCalledOnce();
+ expect(host.querySelector(".directory-location-path")?.textContent).toBe("/data/transcription-recordings");
+ });
+
it("shows the default model for a value it does not know", () => {
mocks.stored = "whisper";
expect(open()?.value).toBe("parakeet-int8");
diff --git a/apps/client/src/widgets/type_widgets/options/transcription.tsx b/apps/client/src/widgets/type_widgets/options/transcription.tsx
index fea517558e..1dded592bf 100644
--- a/apps/client/src/widgets/type_widgets/options/transcription.tsx
+++ b/apps/client/src/widgets/type_widgets/options/transcription.tsx
@@ -72,7 +72,11 @@ function TroubleshootingSettings() {
const [ keepRecordings, setKeepRecordings ] = useTriliumOptionBool("transcriptionKeepRecordings");
const [ directory, setDirectory ] = useState<string>();
+ // Asking for the folder creates it, so it is asked for only once recordings are to be kept.
useEffect(() => {
+ if (!keepRecordings) {
+ return;
+ }
let isCurrent = true;
void window.electronApi?.transcription.getRecordingsDirectory().then((result) => {
if (isCurrent) {
@@ -82,7 +86,7 @@ function TroubleshootingSettings() {
return () => {
isCurrent = false;
};
- }, []);
+ }, [ keepRecordings ]);
return (
<Card heading={t("transcription_options.troubleshooting_title")}>
@@ -95,7 +99,7 @@ function TroubleshootingSettings() {
<FormToggle currentValue={keepRecordings} onChange={setKeepRecordings} />
</OptionCardSection>
- {directory && (
+ {keepRecordings && directory && (
<DirectoryLocation label={t("transcription_options.saved_in")} directory={directory} />
)}
</Card>