Skip to content

Build your personal knowledge base with Trilium Notes

feat(sync): name the server in use beside the test that contacts it

Elian Dorana49d085505b2
diff --git a/apps/client/src/translations/en-GB/translation.json b/apps/client/src/translations/en-GB/translation.json
index 90224cb4aa..e5ed7fbd61 100644
--- a/apps/client/src/translations/en-GB/translation.json
+++ b/apps/client/src/translations/en-GB/translation.json
@@ -243,5 +243,8 @@
},
"sidebar_help": {
"highlights_configure": "Which formats count is yours to set: bold, italic, underlined, coloured text and text on a background colour can each be listed or left out, from the gear in this card's header. Pressing an entry scrolls the note to it."
+ },
+ "sync_2": {
+ "effective_server_disabled": "Synchronisation is turned off."
}
}
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.json
index b57e17ddf8..59ee8e7315 100644
--- a/apps/client/src/translations/en/translation.json
+++ b/apps/client/src/translations/en/translation.json
@@ -1119,8 +1119,7 @@
"connected_no_changes": "<p>Connected to the sync server.<br>All changes have been already synced.</p><p>Click to trigger sync.</p>",
"disconnected_with_changes": "<p>Establishing the connection to the sync server was unsuccessful.<br>There are some outstanding changes yet to be synced.</p><p>Click to trigger sync.</p>",
"disconnected_no_changes": "<p>Establishing the connection to the sync server was unsuccessful.<br>All known changes have been synced.</p><p>Click to trigger sync.</p>",
- "in_progress": "Sync with the server is in progress.",
- "server": "Sync server: {{host}}"
+ "in_progress": "Sync with the server is in progress."
},
"left_pane_toggle": {
"show_panel": "Show panel",
@@ -2421,7 +2420,10 @@
"test_title": "Test Connection",
"test_description": "Test the connection to the sync server. If not initialized, this will set up syncing.",
"test_button": "Test now",
- "handshake_failed": "Sync server handshake failed, error: {{message}}"
+ "handshake_failed": "Sync server handshake failed, error: {{message}}",
+ "effective_server": "Server in use",
+ "effective_server_description": "Set through config.ini or environment variables, which take priority over the server address above.",
+ "effective_server_disabled": "Synchronization is turned off."
},
"api_log": {
"close": "Close"
diff --git a/apps/client/src/widgets/launch_bar/SyncStatus.spec.tsx b/apps/client/src/widgets/launch_bar/SyncStatus.spec.tsx
index 073b0b3c3b..955dc77438 100644
--- a/apps/client/src/widgets/launch_bar/SyncStatus.spec.tsx
+++ b/apps/client/src/widgets/launch_bar/SyncStatus.spec.tsx
@@ -89,39 +89,31 @@ function showTooltip() {
}
describe("SyncStatus", () => {
- it("names the server in use rather than the stored one, and syncs when pressed", () => {
- mocks.options.syncServerHost = "";
+ it("syncs when pressed, and refuses a second request while one is running", () => {
mount();
- const { element, body } = showTooltip();
- expect(body.textContent).toContain("https://effective.example/");
- element.click();
+ icon()?.click();
+ expect(mocks.syncNow).toHaveBeenCalledTimes(1);
+
+ act(() => { mocks.onMessage?.({ type: "sync-pull-in-progress", lastSyncedPush: 0 }); });
+ icon()?.click();
expect(mocks.syncNow).toHaveBeenCalledTimes(1);
});
- it("keeps the host through status changes and prevents duplicate sync requests", () => {
+ it("names the sync state without naming the server", () => {
mount();
- for (const type of [ "sync-finished", "sync-failed", "sync-pull-in-progress" ] as const) {
- act(() => { mocks.onMessage?.({ type, lastSyncedPush: 0 }); });
- const { element, body } = showTooltip();
- expect(body.textContent).toContain("https://effective.example/");
- expect(body.textContent).not.toContain("https://stored.example/");
- if (type === "sync-pull-in-progress") {
- element.click();
- expect(mocks.syncNow).not.toHaveBeenCalled();
- }
- }
+ const { body } = showTooltip();
+ expect(body.textContent).toContain("Sync status will be known");
+ expect(body.textContent).not.toContain("https://effective.example/");
+ expect(body.textContent).not.toContain("https://stored.example/");
});
- it("escapes markup in the host instead of rendering it", () => {
- const host = 'https://sync.example/<b title="test">&value</b>';
- mocks.options.effectiveSyncServerHost = host;
+ it("shows the button when a config override supplies the address, whatever is stored", () => {
+ mocks.options.syncServerHost = "";
mount();
- const { body } = showTooltip();
- expect(body.textContent).toContain(host);
- expect(body.querySelector("b")).toBeNull();
+ expect(icon()).not.toBeNull();
});
it("hides the button when the configuration turns sync off, whatever the stored host says", () => {
diff --git a/apps/client/src/widgets/launch_bar/SyncStatus.tsx b/apps/client/src/widgets/launch_bar/SyncStatus.tsx
index 9db8a861ac..b4b2c2f2c6 100644
--- a/apps/client/src/widgets/launch_bar/SyncStatus.tsx
+++ b/apps/client/src/widgets/launch_bar/SyncStatus.tsx
@@ -60,9 +60,7 @@ export default function SyncStatus({ launcherNote }: LauncherNoteProps) {
useStaticTooltip(spanRef, {
html: true,
- title: escapeQuotes(title) + (effectiveSyncServerHost
- ? `<p>${t("sync_status.server", { host: effectiveSyncServerHost, interpolation: { escapeValue: true } })}</p>`
- : "")
+ title: escapeQuotes(title)
});
// config.ini and environment variables hold still for the life of the process, so only the
diff --git a/apps/client/src/widgets/type_widgets/options/sync.spec.tsx b/apps/client/src/widgets/type_widgets/options/sync.spec.tsx
index 2ad552d854..408bc09b80 100644
--- a/apps/client/src/widgets/type_widgets/options/sync.spec.tsx
+++ b/apps/client/src/widgets/type_widgets/options/sync.spec.tsx
@@ -31,7 +31,8 @@ vi.mock("../../react/hooks", async (importOriginal) => ({
useTriliumOption: (name: string) => [
mocks.stored[name] ?? "",
async (value: string) => void mocks.saved.push([ name, value ])
- ]
+ ],
+ useTriliumOptionBool: (name: string) => [ mocks.stored[name] === "true", vi.fn() ]
}));
vi.mock("./components/OptionsPageHeader", () => ({ default: () => <div className="header-stub" /> }));
@@ -76,6 +77,12 @@ function type(index: number, value: string) {
});
}
+/** The read-only row naming the address sync contacts, which only an override puts on screen. */
+function effectiveServerRow() {
+ return [ ...host.querySelectorAll(".tn-card-option") ]
+ .find((row) => row.querySelector(".tn-card-option-value"));
+}
+
describe("the sync settings", () => {
it("keeps the test apart from the settings it checks, in a card with no heading of its own", () => {
open();
@@ -118,4 +125,36 @@ describe("the sync settings", () => {
expect(mocks.showError).toHaveBeenCalled();
expect(mocks.showMessage).not.toHaveBeenCalled();
});
+
+ it("says nothing about the server in use while the stored address is the one in force", () => {
+ open();
+
+ // The card is there and holds the test alone, rather than the row having gone missing.
+ const testCard = testButton()?.closest(".tn-card");
+ expect(testCard).not.toBeNull();
+ expect(testCard?.querySelectorAll(".tn-card-option")).toHaveLength(1);
+ expect(effectiveServerRow()).toBeUndefined();
+ });
+
+ it("names the server in use beside the test that contacts it, under a config override", () => {
+ mocks.stored.syncServerHostOverridden = "true";
+ mocks.stored.effectiveSyncServerHost = "https://override.example.com";
+ open();
+
+ const row = effectiveServerRow();
+ expect(row?.textContent).toContain("sync_2.effective_server");
+ expect(row?.querySelector(".tn-card-option-value")?.textContent)
+ .toBe("https://override.example.com");
+ // Beside the test, not among the settings: the button it explains shares its card.
+ expect(row?.closest(".tn-card")).toBe(testButton()?.closest(".tn-card"));
+ });
+
+ it("reports sync turned off rather than an empty address when the override disables it", () => {
+ mocks.stored.syncServerHostOverridden = "true";
+ mocks.stored.effectiveSyncServerHost = "";
+ open();
+
+ expect(effectiveServerRow()?.querySelector(".tn-card-option-value")?.textContent)
+ .toBe("sync_2.effective_server_disabled");
+ });
});
diff --git a/apps/client/src/widgets/type_widgets/options/sync.tsx b/apps/client/src/widgets/type_widgets/options/sync.tsx
index c3183ab8c4..794e1796af 100644
--- a/apps/client/src/widgets/type_widgets/options/sync.tsx
+++ b/apps/client/src/widgets/type_widgets/options/sync.tsx
@@ -7,7 +7,7 @@ import toast from "../../../services/toast";
import Button from "../../react/Button";
import { Card, OptionCardSection } from "../../react/Card";
import FormTextBox from "../../react/FormTextBox";
-import { useTriliumOption } from "../../react/hooks";
+import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";
import OptionsPageHeader from "./components/OptionsPageHeader";
import TimeSelector from "./components/TimeSelector";
@@ -21,11 +21,11 @@ export default function SyncOptions() {
}
/**
- * Where to sync and how patiently, followed by the one thing on this page that acts rather than sets.
+ * The sync settings, followed by a card for what is not a setting: the address sync contacts, and
+ * the test that contacts it.
*
- * The test stands on a card of its own, so that what it does is not read as one more setting; it is
- * still driven from here because it saves what has been typed before it runs, and so needs the values
- * still sitting in the boxes rather than the ones already stored.
+ * `testConnection()` saves the address boxes before it posts to `sync/test`, so it reads what is
+ * still on screen rather than what is stored.
*/
export function SyncConfiguration() {
const [syncServerHost, setSyncServerHost] = useTriliumOption("syncServerHost");
@@ -96,6 +96,8 @@ export function SyncConfiguration() {
</Card>
<Card>
+ <EffectiveSyncServer />
+
<OptionCardSection
label={t("sync_2.test_title")}
description={t("sync_2.test_description")}
@@ -111,3 +113,27 @@ export function SyncConfiguration() {
</>
);
}
+
+/**
+ * The address sync contacts, shown only when config.ini or an environment variable supplies it.
+ * Without an override it would repeat the box above, where the stored option is already editable.
+ */
+function EffectiveSyncServer() {
+ const [isOverridden] = useTriliumOptionBool("syncServerHostOverridden");
+ const [effectiveSyncServerHost] = useTriliumOption("effectiveSyncServerHost");
+
+ if (!isOverridden) {
+ return null;
+ }
+
+ return (
+ <OptionCardSection
+ label={t("sync_2.effective_server")}
+ description={t("sync_2.effective_server_description")}
+ >
+ <span className="tn-card-option-value">
+ {effectiveSyncServerHost || t("sync_2.effective_server_disabled")}
+ </span>
+ </OptionCardSection>
+ );
+}