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(setup): add "open config file" shortcut to the unreachable banner
Elian Doran6d7169afdf87
diff --git a/apps/client/src/setup.css b/apps/client/src/setup.cssindex dfcabb1862..b57ca3c8e5 100644--- a/apps/client/src/setup.css+++ b/apps/client/src/setup.css@@ -450,6 +450,19 @@ body[dir=rtl] .slide-in-backward {}}}++ .sync-from-desktop-unreachable .config-path {+ display: flex;+ flex-wrap: wrap;+ align-items: center;+ gap: 0.75rem;+ margin-bottom: 0;++ code {+ user-select: text;+ word-break: break-all;+ }+ }}.page.sync-in-progress {diff --git a/apps/client/src/setup.tsx b/apps/client/src/setup.tsxindex 2149fb9086..54cf0c9907 100644--- a/apps/client/src/setup.tsx+++ b/apps/client/src/setup.tsx@@ -446,6 +446,18 @@ function SyncFromDesktop({ setState }: { setState: (state: State) => void }) {<Admonition type="caution" className="sync-from-desktop-unreachable"><strong>{t("setup.sync-from-desktop-unreachable-title")}</strong><p>{t("setup.sync-from-desktop-unreachable-description")}</p>+ {networkInfo.configPath && (+ <p class="config-path">+ <code>{networkInfo.configPath}</code>+ {isElectron() && (+ <Button+ icon="bx bx-edit"+ text={t("setup.sync-from-desktop-open-config")}+ onClick={() => void openConfigFile(networkInfo.configPath)}+ />+ )}+ </p>+ )}</Admonition>) : (<>@@ -579,6 +591,20 @@ async function getNetworkAddresses(): Promise<NetworkAddressesResponse> {return await server.get<NetworkAddressesResponse>("network-addresses");}+async function openConfigFile(configPath?: string) {+ if (!configPath) {+ return;+ }++ // `openPath` resolves to a non-empty string when the OS couldn't open the+ // file (e.g. no editor associated with `.ini`). The path is also shown in+ // the banner, so the user can still navigate to it manually.+ const error = await window.electronApi?.shell.openPath(configPath);+ if (error) {+ console.error(`Could not open config file "${configPath}": ${error}`);+ }+}+function onSetupFinished() {if (isElectron()) {// On Electron we need to use the setup route because it handles the closing of the setup window and opening the main app window.diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex 1d48b76c3e..c764ff1de6 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -2791,6 +2791,7 @@"sync-from-desktop-waiting": "Waiting for connection...","sync-from-desktop-unreachable-title": "This device can't be reached by other devices","sync-from-desktop-unreachable-description": "Trilium is only listening on localhost, so another device can't connect to it. Set \"host=0.0.0.0\" under the [Network] section of your config.ini, restart Trilium, and try again.",+ "sync-from-desktop-open-config": "Open config file","advanced-options": "Advanced options","sync-failed": "Failed to sync: {{message}}","server-host": "Trilium server address",diff --git a/apps/server/src/routes/api/system_info.ts b/apps/server/src/routes/api/system_info.tsindex e2648b1c14..a9b8b9f45b 100644--- a/apps/server/src/routes/api/system_info.ts+++ b/apps/server/src/routes/api/system_info.ts@@ -3,6 +3,7 @@ import { execSync } from "child_process";import { arch, cpus, networkInterfaces } from "os";import config from "../../services/config.js";+import dataDir from "../../services/data_dir.js";import host from "../../services/host.js";import port from "../../services/port.js";import { isMac, isWindows } from "../../services/utils";@@ -26,7 +27,8 @@ function getNetworkAddresses(): NetworkAddressesResponse {return {addresses: collectNetworkAddresses(networkInterfaces()).map((addr) => buildNetworkUrl(protocol, addr, port)),- reachableOnNetwork: isHostReachableOnNetwork(host)+ reachableOnNetwork: isHostReachableOnNetwork(host),+ configPath: dataDir.CONFIG_INI_PATH};}diff --git a/packages/commons/src/lib/server_api.ts b/packages/commons/src/lib/server_api.tsindex 3a72e9bfdd..bf3bb5e4cf 100644--- a/packages/commons/src/lib/server_api.ts+++ b/packages/commons/src/lib/server_api.ts@@ -472,6 +472,12 @@ export interface NetworkAddressesResponse {* actually be reached by another device.*/reachableOnNetwork: boolean;+ /**+ * Absolute path to this instance's `config.ini`. Only sent when the request+ * is served by a Node host (server/desktop); lets the setup screen offer an+ * "open config" shortcut when the host needs to be reconfigured.+ */+ configPath?: string;}export type ScriptParams = any[];