Skip to content

Build your personal knowledge base with Trilium Notes

fix(transcription): keep recording when the frontend reloads

Elian Doran7d5cc0a37ee1
diff --git a/apps/desktop/src/services/transcription/capture.spec.ts b/apps/desktop/src/services/transcription/capture.spec.ts
index 2e98dc8084..c91355b9bc 100644
--- a/apps/desktop/src/services/transcription/capture.spec.ts
+++ b/apps/desktop/src/services/transcription/capture.spec.ts
@@ -136,6 +136,19 @@ describe("CaptureWindow", () => {
expect(onLost).toHaveBeenCalledExactlyOnceWith("the capture page ended (oom)");
});
+ it("reports the capture lost when its page reloads", async () => {
+ const { onLost, window } = await startCapture();
+ const url = "file:///tmp/trilium-transcription.html";
+ window.webContents.emit("did-start-navigation",
+ { url: `${url}#x`, isMainFrame: true, isSameDocument: true });
+ window.webContents.emit("did-start-navigation",
+ { url, isMainFrame: false, isSameDocument: false });
+ expect(onLost).not.toHaveBeenCalled();
+ window.webContents.emit("did-start-navigation",
+ { url, isMainFrame: true, isSameDocument: false });
+ expect(onLost).toHaveBeenCalledExactlyOnceWith("the capture page reloaded");
+ });
+
it("reports the capture lost once every source has ended", async () => {
const { onLost, window } = await startCapture();
window.webContents.ipc.emit("transcription-source-ended", {}, "microphone");
diff --git a/apps/desktop/src/services/transcription/capture.ts b/apps/desktop/src/services/transcription/capture.ts
index 8e3f83998f..403886b8ca 100644
--- a/apps/desktop/src/services/transcription/capture.ts
+++ b/apps/desktop/src/services/transcription/capture.ts
@@ -11,8 +11,8 @@ const SOURCE_ENDED_CHANNEL = "transcription-source-ended";
export interface CaptureWindowOptions {
/**
- * Called once when capturing stops on its own: the page crashed, or every source ended (a
- * device was unplugged, the system audio went away). Not called after
+ * Called once when capturing stops on its own: the page crashed or reloaded, or every source
+ * ended (a device was unplugged, the system audio went away). Not called after
* {@link CaptureWindow.stop}.
*/
onLost(reason: string): void;
@@ -55,6 +55,11 @@ export class CaptureWindow {
this.window = window;
window.webContents.on("render-process-gone", (_event, { reason }) =>
this.lose(`the capture page ended (${reason})`));
+ window.webContents.on("did-start-navigation", ({ isMainFrame, isSameDocument }) => {
+ if (isMainFrame && !isSameDocument) {
+ this.lose("the capture page reloaded");
+ }
+ });
window.webContents.ipc.on(SOURCE_ENDED_CHANNEL, (_event, source: TranscriptSource) => {
getLog().error(`Transcription: the ${source} source ended.`);
this.running.delete(source);
diff --git a/apps/desktop/src/services/window.spec.ts b/apps/desktop/src/services/window.spec.ts
index 0e92442205..ed2c06703c 100644
--- a/apps/desktop/src/services/window.spec.ts
+++ b/apps/desktop/src/services/window.spec.ts
@@ -865,10 +865,13 @@ describe("window service", () => {
expect(extraWindowOptions?.webPreferences?.nodeIntegration).toBe(false);
});
- it("reload-all-windows reloads every window", () => {
+ it("reload-all-windows reloads every app window and leaves other pages alone", () => {
const win = state.windows[state.windows.length - 1];
+ const capture = new FakeBrowserWindow();
+ capture.webContents.getURL.mockReturnValue("file:///tmp/trilium-transcription.html");
fireOn("reload-all-windows", makeEvent());
expect(win.reload).toHaveBeenCalled();
+ expect(capture.reload).not.toHaveBeenCalled();
});
it("restart-app relaunches and exits", () => {
diff --git a/apps/desktop/src/services/window.ts b/apps/desktop/src/services/window.ts
index 706e278cce..1bb6b848bb 100644
--- a/apps/desktop/src/services/window.ts
+++ b/apps/desktop/src/services/window.ts
@@ -6,7 +6,7 @@ import { t } from "i18next";
import path from "path";
import { markStartupMetric } from "./startup_metrics.js";
-import { TRILIUM_APP_BASE_URL } from "./trilium_app_origin.js";
+import { isTriliumAppShellUrl, TRILIUM_APP_BASE_URL } from "./trilium_app_origin.js";
import { setupWebContentsSecurity } from "./web_contents_security.js";
// Preload bundle path. Two layouts:
@@ -528,9 +528,12 @@ export function setupWindowing() {
console.error(`Could not set the application menu: ${e}`);
});
+ // Only app windows: reloading the hidden transcription capture page would end its capture.
electron.ipcMain.on("reload-all-windows", () => {
for (const win of electron.BrowserWindow.getAllWindows()) {
- win.reload();
+ if (isTriliumAppShellUrl(win.webContents.getURL())) {
+ win.reload();
+ }
}
});