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
fix(desktop): don't mark browser clients as Electron in bootstrap (#10589)
Elian Doranc438b8fa6b9e
diff --git a/apps/server/src/routes/index.spec.ts b/apps/server/src/routes/index.spec.tsindex 2d41cc54dc..10ecb20469 100644--- a/apps/server/src/routes/index.spec.ts+++ b/apps/server/src/routes/index.spec.ts@@ -65,6 +65,10 @@ describe("bootstrap auth gating (desktop build, #10589)", () => {expect(body().loggedIn).toBe(false);expect(body().login).toBeTruthy();expect(body().csrfToken).toBeUndefined();+ // ...and it must NOT be told it's the Electron renderer (no `electron` body+ // class, no renderer-only trilium-app:// URLs).+ expect(body().isElectron).toBe(false);+ expect(body().wsBaseUrl).toBeUndefined();});it("treats a browser as logged in once it has a real session", () => {@@ -82,5 +86,9 @@ describe("bootstrap auth gating (desktop build, #10589)", () => {// The trilium-app:// renderer is trusted and never gates on a web session.expect(body().loggedIn).toBe(true);expect(body().csrfToken).toBe("csrf-test-token");+ // It IS the Electron renderer, so it keeps the electron flag and the+ // absolute renderer-only URLs it can't derive from trilium-app://.+ expect(body().isElectron).toBe(true);+ expect(body().wsBaseUrl).toBeTruthy();});});diff --git a/apps/server/src/routes/index.ts b/apps/server/src/routes/index.tsindex 5398b0c945..5102cd500e 100644--- a/apps/server/src/routes/index.ts+++ b/apps/server/src/routes/index.ts@@ -45,7 +45,11 @@ export function bootstrap(req: Request, res: Response) {baseApiUrl: "api/",appPath,isStandalone: false,- isElectron,+ // Reflects whether *this client* is the trusted desktop renderer, not whether+ // the server is a desktop build: a browser hitting the desktop's HTTP listener+ // is a plain web client and must not get the `electron` body class (which drops+ // web-only chrome like the login margins — #10589) or the renderer-only URLs below.+ isElectron: isElectronRenderer,isDev,platform: process.platform,triliumVersion: packageJson.version,@@ -54,10 +58,12 @@ export function bootstrap(req: Request, res: Response) {instanceName: config.General ? config.General.instanceName : null,// The desktop renderer loads from trilium-app://, so location-based// ws:// URL derivation no longer works there. Send an absolute URL.- wsBaseUrl: isElectron ? `ws://127.0.0.1:${port}/` : undefined,+ // A browser has a real HTTP origin and derives its own, so only the+ // renderer gets this.+ wsBaseUrl: isElectronRenderer ? `ws://127.0.0.1:${port}/` : undefined,// Same reason for HTTP-origin-dependent UI (e.g. the MCP URL shown// in Options) — give the renderer a real loopback origin to display.- httpBaseUrl: isElectron+ httpBaseUrl: isElectronRenderer? `${config["Network"]["https"] ? "https" : "http"}://127.0.0.1:${port}`: undefined};