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(desktop): ship a trimmed config-sample for desktop builds
Elian Doranc2b95cf25a04
diff --git a/apps/server/src/assets/config-sample-desktop.ini b/apps/server/src/assets/config-sample-desktop.ininew file mode 100644index 0000000000..da37e554cf--- /dev/null+++ b/apps/server/src/assets/config-sample-desktop.ini@@ -0,0 +1,37 @@+# Configuration for the Trilium desktop app.+#+# The desktop app talks to its bundled server in-process, so web-deployment+# options (host, port, CORS, reverse proxy, sessions, OAuth) don't apply and are+# omitted from this file. Network access and scripting are managed through the+# application UI (Settings -> Security), not here.+#+# The fixed local port can be changed with the TRILIUM_PORT environment variable.++[General]+# Instance name can be used to distinguish between different instances using backend api.getInstanceName()+instanceName=++# set to true to disable backups (e.g. because of limited disk space)+noBackup=false++[Network]+# These only take effect once you've enabled network access (Settings -> Security),+# e.g. to sync from another device over an encrypted connection.+# true for TLS/SSL/HTTPS (secure), false for HTTP (insecure).+https=false+# path to certificate (run "bash bin/generate-cert.sh" to generate a self-signed certificate). Relevant only if https=true+certPath=+keyPath=++[Sync]+#syncServerHost=+#syncServerTimeout=+#syncServerProxy=++[Security]+# On desktop these are managed through Settings -> Security; the values below are+# only the startup defaults used until you change them in the UI.+# Enable backend script execution (startup scripts, custom request handlers, event handlers, scheduled scripts, etc.).+backendScriptingEnabled=false+# Enable the SQL console (allows raw SQL execution against the database).+sqlConsoleEnabled=falsediff --git a/apps/server/src/services/config.spec.ts b/apps/server/src/services/config.spec.tsindex f29b9004c7..f5022e80f0 100644--- a/apps/server/src/services/config.spec.ts+++ b/apps/server/src/services/config.spec.ts@@ -320,6 +320,32 @@ corsAllowOrigin=https://ini-cors.comexpect(fs.writeFileSync).toHaveBeenCalledWith("/test/config.ini", sampleContents);expect(config.General.instanceName).toBe("from-sample");});++ it("uses the trimmed desktop sample under Electron", async () => {+ const originalElectron = process.versions.electron;+ Object.defineProperty(process.versions, "electron", { value: "41.0.0", configurable: true });+ try {+ vi.mocked(fs.existsSync).mockReturnValue(false);+ const desktopSample = "[General]\ninstanceName=desktop-sample";+ vi.mocked(fs.readFileSync).mockImplementation((path) => {+ if (String(path).includes("config-sample-desktop.ini")) {+ return Buffer.from(desktopSample) as any;+ }+ return desktopSample as any;+ });++ const { default: config } = await import("./config.js");++ expect(fs.writeFileSync).toHaveBeenCalledWith("/test/config.ini", desktopSample);+ expect(config.General.instanceName).toBe("desktop-sample");+ } finally {+ if (originalElectron === undefined) {+ delete (process.versions as { electron?: string }).electron;+ } else {+ Object.defineProperty(process.versions, "electron", { value: originalElectron, configurable: true });+ }+ }+ });});describe("Boolean transformation edge cases", () => {diff --git a/apps/server/src/services/config.ts b/apps/server/src/services/config.tsindex 0fbfb2f461..a8975e26e0 100644--- a/apps/server/src/services/config.ts+++ b/apps/server/src/services/config.ts@@ -28,10 +28,15 @@ import dataDir from "./data_dir.js";import resourceDir from "./resource_dir.js";/**- * Path to the sample configuration file that serves as a template for new installations.- * This file contains all available configuration options with documentation.+ * Path to the sample configuration file copied into the data directory on first+ * run. Desktop builds get a trimmed template: web-deployment options (host, port,+ * CORS, reverse proxy, sessions, OAuth) don't apply because the renderer talks to+ * the bundled server in-process, and network/scripting are managed through the UI.+ * `process.versions.electron` is used (not the core `isElectron()`) because this+ * runs at module load, before the platform is initialized.*/-const configSampleFilePath = path.resolve(resourceDir.RESOURCE_DIR, "config-sample.ini");+const configSampleFileName = process.versions.electron ? "config-sample-desktop.ini" : "config-sample.ini";+const configSampleFilePath = path.resolve(resourceDir.RESOURCE_DIR, configSampleFileName);/*** Initialize config.ini file if it doesn't exist.