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 platform-specific settings pages in the modal
Elian Doran655e5123b742
diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.spec.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.spec.tsxnew file mode 100644index 0000000000..08e2a799a3--- /dev/null+++ b/apps/client/src/widgets/dialogs/OptionsDialog.spec.tsx@@ -0,0 +1,45 @@+import { beforeEach, describe, expect, it, vi } from "vitest";++import type FNote from "../../entities/fnote";+import { isElectron } from "../../services/utils";+import { isOptionPageVisibleOnPlatform } from "./OptionsDialog";++// 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.+vi.mock("../../services/utils", async (importActual) => ({+ ...(await importActual<typeof import("../../services/utils")>()),+ isElectron: vi.fn(() => true)+}));++function fakePage(label?: "electronOnly" | "serverOnly") {+ return {+ isLabelTruthy: (name: string) => name === label+ } as unknown as FNote;+}++describe("isOptionPageVisibleOnPlatform", () => {+ beforeEach(() => {+ vi.mocked(isElectron).mockReturnValue(true);+ });++ it("shows pages without a platform label on every platform", () => {+ vi.mocked(isElectron).mockReturnValue(true);+ expect(isOptionPageVisibleOnPlatform(fakePage())).toBe(true);+ vi.mocked(isElectron).mockReturnValue(false);+ expect(isOptionPageVisibleOnPlatform(fakePage())).toBe(true);+ });++ it("shows an #electronOnly page only on the Electron desktop app", () => {+ vi.mocked(isElectron).mockReturnValue(true);+ expect(isOptionPageVisibleOnPlatform(fakePage("electronOnly"))).toBe(true);+ vi.mocked(isElectron).mockReturnValue(false);+ expect(isOptionPageVisibleOnPlatform(fakePage("electronOnly"))).toBe(false);+ });++ it("shows a #serverOnly page only on the server (web/mobile)", () => {+ vi.mocked(isElectron).mockReturnValue(false);+ expect(isOptionPageVisibleOnPlatform(fakePage("serverOnly"))).toBe(true);+ vi.mocked(isElectron).mockReturnValue(true);+ expect(isOptionPageVisibleOnPlatform(fakePage("serverOnly"))).toBe(false);+ });+});diff --git a/apps/client/src/widgets/dialogs/OptionsDialog.tsx b/apps/client/src/widgets/dialogs/OptionsDialog.tsxindex c6a2ab1014..c3c467ce96 100644--- a/apps/client/src/widgets/dialogs/OptionsDialog.tsx+++ b/apps/client/src/widgets/dialogs/OptionsDialog.tsx@@ -4,8 +4,9 @@ import { useCallback, useContext, useRef, useState } from "preact/hooks";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 from "../../services/utils";+import utils, { isElectron } from "../../services/utils";import NoteDetail from "../NoteDetail";import ActionButton from "../react/ActionButton";import FormList, { FormListItem } from "../react/FormList";@@ -102,6 +103,38 @@ export default function OptionsDialog() {);}+/**+ * The children of `_options` to list in the settings modal, filtered to those applicable to the+ * running platform (see {@link isOptionPageVisibleOnPlatform}). Shared by the desktop sidebar+ * ({@link SettingsNavigation}) and the mobile master list ({@link MobileSettingsList}) so both stay+ * in sync.+ */+export function useOptionPages() {+ return useChildNotes("_options").filter(isOptionPageVisibleOnPlatform);+}++/**+ * 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.+ *+ * 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.+ */+export function isOptionPageVisibleOnPlatform(page: FNote) {+ if (!isElectron() && page.isLabelTruthy("electronOnly")) {+ return false;+ }++ if (isElectron() && page.isLabelTruthy("serverOnly")) {+ return false;+ }++ return true;+}+/*** The settings page selector shown in the dialog's sidebar. It derives the active page from* `useNoteContext()` (resolved against the dialog's own context via the surrounding provider) so the@@ -119,7 +152,7 @@ function SettingsSidebar() {* standard list component rather than the desktop sidebar's compact selector.*/function MobileSettingsList({ onSelect }: { onSelect: (noteId: string) => void }) {- const pages = useChildNotes("_options");+ const pages = useOptionPages();const { noteId: activeNoteId } = useNoteContext();return (<FormList onSelect={onSelect}>diff --git a/apps/client/src/widgets/type_widgets/options/components/SettingsNavigation.tsx b/apps/client/src/widgets/type_widgets/options/components/SettingsNavigation.tsxindex 68113cd867..3e993eb5b5 100644--- a/apps/client/src/widgets/type_widgets/options/components/SettingsNavigation.tsx+++ b/apps/client/src/widgets/type_widgets/options/components/SettingsNavigation.tsx@@ -2,7 +2,7 @@ import "./SettingsNavigation.css";import clsx from "clsx";-import { useChildNotes } from "../../../react/hooks";+import { useOptionPages } from "../../../dialogs/OptionsDialog";interface SettingsNavigationProps {/** Note ID of the settings page currently being displayed (e.g. `_optionsAppearance`). */@@ -18,7 +18,7 @@ interface SettingsNavigationProps {* modified clicks (ctrl/middle/shift) fall through to the global handler to open a new tab/window.*/export default function SettingsNavigation({ activeNoteId }: SettingsNavigationProps) {- const pages = useChildNotes("_options");+ const pages = useOptionPages();return (<nav className="settings-navigation">diff --git a/packages/trilium-core/src/services/hidden_subtree.ts b/packages/trilium-core/src/services/hidden_subtree.tsindex ce06e2f580..68e28f7b72 100644--- a/packages/trilium-core/src/services/hidden_subtree.ts+++ b/packages/trilium-core/src/services/hidden_subtree.ts@@ -301,10 +301,10 @@ function buildHiddenSubtreeDefinition(helpSubtree: HiddenSubtreeItem[]): HiddenS{ id: "_optionsCodeNotes", title: t("hidden-subtree.code-notes-title"), type: "contentWidget", icon: "bx-code" },{ id: "_optionsImages", title: "Images", type: "contentWidget", enforceDeleted: true },{ id: "_optionsMedia", title: t("hidden-subtree.images-title"), type: "contentWidget", icon: "bx-image" },- { id: "_optionsSpellcheck", title: t("hidden-subtree.spellcheck-title"), type: "contentWidget", icon: "bx-check-double" },+ { id: "_optionsSpellcheck", title: t("hidden-subtree.spellcheck-title"), type: "contentWidget", icon: "bx-check-double", 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" },- { id: '_optionsMFA', title: t('hidden-subtree.multi-factor-authentication-title'), type: 'contentWidget', icon: 'bx-lock ' },+ { id: '_optionsMFA', title: t('hidden-subtree.multi-factor-authentication-title'), type: 'contentWidget', icon: 'bx-lock ', attributes: [{ type: "label", name: "serverOnly" }] },{ id: "_optionsEtapi", title: t("hidden-subtree.etapi-title"), type: "contentWidget", icon: "bx-extension" },{ 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" },