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(options): hide the password and ETAPI pages in the standalone build
Elian Dorand0f6a15bc83b
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.spec.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.spec.tsxindex 08e2a799a3..67896bcbbc 100644--- a/apps/client/src/widgets/dialogs/OptionsDialog.spec.tsx+++ b/apps/client/src/widgets/dialogs/OptionsDialog.spec.tsx@@ -4,14 +4,21 @@ import type FNote from "../../entities/fnote";import { isElectron } from "../../services/utils";import { isOptionPageVisibleOnPlatform } from "./OptionsDialog";+// `isStandalone` is a const in the target, read here as a live getter so each scenario can flip it.+// `vi.hoisted` runs before the hoisted `vi.mock` factory, so the factory can reference it.+const ctrl = vi.hoisted(() => ({ standalone: false }));+// Importing the dialog pulls in the options stack, so keep the real `utils` module (e.g. `isShare`,-// needed when `options.ts` initialises) and only swap out the platform check.+// needed when `options.ts` initialises) and only swap out the platform checks.vi.mock("../../services/utils", async (importActual) => ({...(await importActual<typeof import("../../services/utils")>()),- isElectron: vi.fn(() => true)+ isElectron: vi.fn(() => true),+ get isStandalone() {+ return ctrl.standalone;+ }}));-function fakePage(label?: "electronOnly" | "serverOnly") {+function fakePage(label?: "electronOnly" | "serverOnly" | "notInStandalone") {return {isLabelTruthy: (name: string) => name === label} as unknown as FNote;@@ -20,6 +27,7 @@ function fakePage(label?: "electronOnly" | "serverOnly") {describe("isOptionPageVisibleOnPlatform", () => {beforeEach(() => {vi.mocked(isElectron).mockReturnValue(true);+ ctrl.standalone = false;});it("shows pages without a platform label on every platform", () => {@@ -42,4 +50,19 @@ describe("isOptionPageVisibleOnPlatform", () => {vi.mocked(isElectron).mockReturnValue(true);expect(isOptionPageVisibleOnPlatform(fakePage("serverOnly"))).toBe(false);});++ it("hides a #notInStandalone page in the standalone build, on either platform it runs as", () => {+ // Standalone serves itself from this browser, so it answers to neither of the labels above+ // and has to be asked about on its own — including where it runs inside Electron.+ for (const electron of [ true, false ]) {+ vi.mocked(isElectron).mockReturnValue(electron);++ ctrl.standalone = false;+ expect(isOptionPageVisibleOnPlatform(fakePage("notInStandalone"))).toBe(true);+ ctrl.standalone = true;+ expect(isOptionPageVisibleOnPlatform(fakePage("notInStandalone"))).toBe(false);+ // Only the labelled pages go: the rest of the settings are still there.+ expect(isOptionPageVisibleOnPlatform(fakePage())).toBe(true);+ }+ });});diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsxindex 0178d0d09b..586fc5c608 100644--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx@@ -7,7 +7,7 @@ import appContext from "../../components/app_context";import NoteContext from "../../components/note_context";import type FNote from "../../entities/fnote";import { t } from "../../services/i18n";-import utils, { isElectron } from "../../services/utils";+import utils, { isElectron, isStandalone } from "../../services/utils";import NoteDetail from "../NoteDetail";import FormList, { FormListItem } from "../react/FormList";import { useChildNotes, useContainedLinkNavigation, useNoteContext, useTriliumEvent } from "../react/hooks";@@ -139,13 +139,19 @@ export function useOptionPages() {/*** Whether an option page applies to the running platform. A page note in the hidden subtree (see- * `hidden_subtree.ts`) can carry a boolean label restricting it to one platform: `#electronOnly`- * hides it on the server (web/mobile) clients, `#serverOnly` hides it on the desktop (Electron) app.- * Pages without either label apply everywhere. The page still exists in the note tree and stays- * reachable directly; only the modal's navigation hides it.+ * `hidden_subtree.ts`) can carry a boolean label restricting where it appears: `#electronOnly`+ * hides it on the server (web/mobile) clients, `#serverOnly` hides it on the desktop (Electron)+ * app, and `#notInStandalone` hides it in the standalone build. Pages without any of them apply+ * everywhere. The page still exists in the note tree and stays reachable directly; only the modal's+ * navigation hides it.*- * This is the platform axis (Electron app vs. served over HTTP), distinct from the layout axis- * (`isDesktop`/`isMobile`) that the launcher's `desktopOnly` label uses.+ * The first two are one axis — where the stack is served from — and are written as `Only` labels+ * because each names a single platform. Standalone is neither: its server runs in this browser, so+ * it is Electron and server at once for some purposes and neither for others. What a page needs+ * there is stated as the exclusion it is.+ *+ * All of this is the platform axis, distinct from the layout axis (`isDesktop`/`isMobile`) that the+ * launcher's `desktopOnly` label uses.*/export function isOptionPageVisibleOnPlatform(page: FNote) {if (!isElectron() && page.isLabelTruthy("electronOnly")) {@@ -156,6 +162,10 @@ export function isOptionPageVisibleOnPlatform(page: FNote) {return false;}+ if (isStandalone && page.isLabelTruthy("notInStandalone")) {+ return false;+ }+return true;}diff --git a/packages/trilium-core/src/services/hidden_subtree.spec.ts b/packages/trilium-core/src/services/hidden_subtree.spec.tsindex faca394a6f..481512485f 100644--- a/packages/trilium-core/src/services/hidden_subtree.spec.ts+++ b/packages/trilium-core/src/services/hidden_subtree.spec.ts@@ -107,6 +107,16 @@ describe("hidden_subtree (real DB)", () => {expect(tpl.getParentBranches().some((b) => b.parentNoteId === LBTPL_ROOT)).toBe(true);}});++ it("marks the settings pages that have nothing to set in the standalone build", () => {+ // The client's settings navigation reads these (isOptionPageVisibleOnPlatform); a rename+ // here would silently put the pages back rather than fail anywhere.+ for (const pageId of [ "_optionsPassword", "_optionsEtapi" ]) {+ expect(becca.notes[pageId]?.isLabelTruthy("notInStandalone"), pageId).toBe(true);+ }+ // Not a blanket mark: the pages that do apply everywhere carry nothing.+ expect(becca.notes._optionsAppearance?.isLabelTruthy("notInStandalone")).toBe(false);+ });});describe("enforceAttributes", () => {diff --git a/packages/trilium-core/src/services/hidden_subtree.ts b/packages/trilium-core/src/services/hidden_subtree.tsindex cb12729ff0..3369b1049a 100644--- a/packages/trilium-core/src/services/hidden_subtree.ts+++ b/packages/trilium-core/src/services/hidden_subtree.ts@@ -305,9 +305,13 @@ function buildHiddenSubtreeDefinition(helpSubtree: HiddenSubtreeItem[]): HiddenS{ id: "_optionsSpellcheck", title: t("hidden-subtree.spellcheck-title"), type: "contentWidget", icon: "bx-check-double", attributes: [{ type: "label", name: "electronOnly" }] },{ id: "_optionsDesktop", title: t("hidden-subtree.desktop-title"), type: "contentWidget", icon: "bx-desktop", attributes: [{ type: "label", name: "electronOnly" }] },{ id: "_optionsSecurity", title: t("hidden-subtree.security-title"), type: "contentWidget", icon: "bx-shield" },- { id: "_optionsPassword", title: t("hidden-subtree.password-title"), type: "contentWidget", icon: "bx-lock" },+ // Password and ETAPI both answer to something reaching the instance over HTTP —+ // a login to hold a session for, a token for another program to call with. The+ // standalone build is the only reader of its own database and is served by no+ // one, so neither page has anything to set there.+ { id: "_optionsPassword", title: t("hidden-subtree.password-title"), type: "contentWidget", icon: "bx-lock", attributes: [{ type: "label", name: "notInStandalone" }] },{ id: "_optionsMFA", title: t("hidden-subtree.multi-factor-authentication-title"), type: "contentWidget", enforceDeleted: true },- { id: "_optionsEtapi", title: t("hidden-subtree.etapi-title"), type: "contentWidget", icon: "bx-extension" },+ { id: "_optionsEtapi", title: t("hidden-subtree.etapi-title"), type: "contentWidget", icon: "bx-extension", attributes: [{ type: "label", name: "notInStandalone" }] },{ id: "_optionsBackup", title: t("hidden-subtree.backup-title"), type: "contentWidget", icon: "bx-data" },{ id: "_optionsSync", title: t("hidden-subtree.sync-title"), type: "contentWidget", icon: "bx-wifi" },{ id: "_optionsLlm", title: t("hidden-subtree.llm-title"), type: "contentWidget", icon: "bx-bot" },