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
refactor(options): move desktop-only settings to a dedicated Desktop page
Elian Doran70ab9398f527
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex bedc33045f..0be6fc1075 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1519,6 +1519,9 @@"custom_url_placeholder": "Search engine URL","save_button": "Save"},+ "desktop": {+ "web_placeholder": "These options apply only for desktop builds."+ },"startup": {"title": "Startup","launch_on_startup": "Launch on startup",diff --git a/apps/client/src/widgets/type_widgets/ContentWidget.tsx b/apps/client/src/widgets/type_widgets/ContentWidget.tsxindex e15bd47853..a5369de454 100644--- a/apps/client/src/widgets/type_widgets/ContentWidget.tsx+++ b/apps/client/src/widgets/type_widgets/ContentWidget.tsx@@ -11,6 +11,7 @@ import MultiFactorAuthenticationSettings from "./options/multi_factor_authenticaimport EtapiSettings from "./options/etapi";import BackupSettings from "./options/backup";import SyncOptions from "./options/sync";+import DesktopSettings from "./options/desktop";import OtherSettings from "./options/other";import InternationalizationOptions from "./options/i18n";import AdvancedSettings from "./options/advanced";@@ -20,7 +21,7 @@ import "./ContentWidget.css";import { t } from "../../services/i18n";import BackendLog from "./code/BackendLog";-export type OptionPages = "_optionsAppearance" | "_optionsShortcuts" | "_optionsTextNotes" | "_optionsCodeNotes" | "_optionsMedia" | "_optionsSpellcheck" | "_optionsPassword" | "_optionsMFA" | "_optionsEtapi" | "_optionsBackup" | "_optionsSync" | "_optionsOther" | "_optionsLocalization" | "_optionsSecurity" | "_optionsAdvanced" | "_optionsLlm";+export type OptionPages = "_optionsAppearance" | "_optionsShortcuts" | "_optionsTextNotes" | "_optionsCodeNotes" | "_optionsMedia" | "_optionsSpellcheck" | "_optionsPassword" | "_optionsMFA" | "_optionsEtapi" | "_optionsBackup" | "_optionsSync" | "_optionsDesktop" | "_optionsOther" | "_optionsLocalization" | "_optionsSecurity" | "_optionsAdvanced" | "_optionsLlm";const CONTENT_WIDGETS: Record<OptionPages | "_backendLog", (props: TypeWidgetProps) => JSX.Element> = {_optionsAppearance: AppearanceSettings,@@ -34,6 +35,7 @@ const CONTENT_WIDGETS: Record<OptionPages | "_backendLog", (props: TypeWidgetPro_optionsEtapi: EtapiSettings,_optionsBackup: BackupSettings,_optionsSync: SyncOptions,+ _optionsDesktop: DesktopSettings,_optionsOther: OtherSettings,_optionsLocalization: InternationalizationOptions,_optionsSecurity: SecuritySettings,diff --git a/apps/client/src/widgets/type_widgets/options/desktop.tsx b/apps/client/src/widgets/type_widgets/options/desktop.tsxnew file mode 100644index 0000000000..7f95178001--- /dev/null+++ b/apps/client/src/widgets/type_widgets/options/desktop.tsx@@ -0,0 +1,146 @@+import { useMemo } from "preact/hooks";++import { t } from "../../../services/i18n";+import utils, { isElectron } from "../../../services/utils";+import { Badge } from "../../react/Badge";+import FormTextBox from "../../react/FormTextBox";+import { useTriliumOption, useTriliumOptionBool } from "../../react/hooks";+import NoItems from "../../react/NoItems";+import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";+import OptionsSection from "./components/OptionsSection";++export default function DesktopSettings() {+ // The page is hidden from the options nav on the server (it's #electronOnly),+ // but can still be reached directly — show a placeholder there, mirroring the+ // spellcheck page.+ if (!isElectron()) {+ return (+ <OptionsSection>+ <NoItems text={t("desktop.web_placeholder")} icon="bx bx-desktop" />+ </OptionsSection>+ );+ }++ return (+ <>+ <TrayOptionsSettings />+ <StartupSettings />+ <SearchEngineSettings />+ </>+ );+}++function TrayOptionsSettings() {+ const [ disableTray, setDisableTray ] = useTriliumOptionBool("disableTray");+ const [ closeToTray, setCloseToTray ] = useTriliumOptionBool("closeToTray");++ return (+ <OptionsSection title={t("tray.title")}>+ <OptionsRowWithToggle+ name="tray-enabled"+ label={t("tray.enable_tray")}+ description={t("tray.enable_tray_description")}+ currentValue={!disableTray}+ onChange={async trayEnabled => {+ await setDisableTray(!trayEnabled);+ // Apply the change immediately so the user doesn't have to restart the app.+ utils.reloadTray();+ }}+ />+ <OptionsRowWithToggle+ name="close-to-tray"+ label={t("tray.close_to_tray")}+ description={t("tray.close_to_tray_description")}+ currentValue={closeToTray}+ // Close-to-tray with no tray icon would hide the app with no way back.+ disabled={disableTray}+ onChange={setCloseToTray}+ />+ </OptionsSection>+ );+}++function StartupSettings() {+ const [ launchOnStartup, setLaunchOnStartup ] = useTriliumOptionBool("launchOnStartup");+ const [ hideOnAutoStart, setHideOnAutoStart ] = useTriliumOptionBool("hideOnAutoStart");+ const [ disableTray ] = useTriliumOptionBool("disableTray");++ return (+ <OptionsSection title={t("startup.title")}>+ <OptionsRowWithToggle+ name="launch-on-startup"+ label={t("startup.launch_on_startup")}+ description={t("startup.launch_on_startup_description")}+ currentValue={launchOnStartup}+ onChange={async enabled => {+ await setLaunchOnStartup(enabled);+ // Apply the change immediately so the user doesn't have to restart the app.+ utils.reapplyLaunchOnStartup();+ }}+ />+ <OptionsRowWithToggle+ name="hide-on-auto-start"+ label={t("startup.hide_on_auto_start")}+ description={t("startup.hide_on_auto_start_description")}+ currentValue={hideOnAutoStart}+ // Only meaningful when launched at login, and the tray must exist to+ // bring the hidden window back.+ disabled={!launchOnStartup || disableTray}+ onChange={async enabled => {+ await setHideOnAutoStart(enabled);+ // Re-tag the autostart entry so it launches hidden (or not).+ utils.reapplyLaunchOnStartup();+ }}+ />+ </OptionsSection>+ );+}++function SearchEngineSettings() {+ const [ customSearchEngineName, setCustomSearchEngineName ] = useTriliumOption("customSearchEngineName");+ const [ customSearchEngineUrl, setCustomSearchEngineUrl ] = useTriliumOption("customSearchEngineUrl");++ const searchEngines = useMemo(() => {+ return [+ { url: "https://duckduckgo.com/?q={keyword}", name: t("search_engine.duckduckgo") },+ { url: "https://www.bing.com/search?q={keyword}", name: t("search_engine.bing"), icon: "bx bxl-bing" },+ { url: "https://www.baidu.com/s?wd={keyword}", name: t("search_engine.baidu"), icon: "bx bxl-baidu" },+ { url: "https://www.google.com/search?q={keyword}", name: t("search_engine.google"), icon: "bx bxl-google" }+ ];+ }, []);++ return (+ <OptionsSection title={t("search_engine.title")} description={t("search_engine.custom_search_engine_info")}>+ <OptionsRow name="predefined-templates" label={t("search_engine.predefined_templates_label")}>+ <div className="search-engine-templates">+ {searchEngines.map(engine => (+ <Badge+ key={engine.url}+ icon={engine.icon}+ text={engine.name}+ className={customSearchEngineUrl === engine.url ? "selected" : ""}+ onClick={() => {+ setCustomSearchEngineName(engine.name);+ setCustomSearchEngineUrl(engine.url);+ }}+ />+ ))}+ </div>+ </OptionsRow>++ <OptionsRow name="custom-name" label={t("search_engine.custom_name_label")}>+ <FormTextBox+ currentValue={customSearchEngineName} onBlur={setCustomSearchEngineName}+ placeholder={t("search_engine.custom_name_placeholder")}+ />+ </OptionsRow>++ <OptionsRow name="custom-url" label={t("search_engine.custom_url_label")} description={t("search_engine.custom_url_description")} stacked>+ <FormTextBox+ currentValue={customSearchEngineUrl} onBlur={setCustomSearchEngineUrl}+ placeholder={t("search_engine.custom_url_placeholder")}+ />+ </OptionsRow>+ </OptionsSection>+ );+}diff --git a/apps/client/src/widgets/type_widgets/options/other.tsx b/apps/client/src/widgets/type_widgets/options/other.tsxindex 01d7976492..bc12a017e6 100644--- a/apps/client/src/widgets/type_widgets/options/other.tsx+++ b/apps/client/src/widgets/type_widgets/options/other.tsx@@ -5,11 +5,9 @@ import { t } from "../../../services/i18n";import search from "../../../services/search";import server from "../../../services/server";import toast from "../../../services/toast";-import utils, { isElectron } from "../../../services/utils";-import { Badge } from "../../react/Badge";import Button from "../../react/Button";import FormText from "../../react/FormText";-import FormTextBox, { FormTextBoxWithUnit } from "../../react/FormTextBox";+import { FormTextBoxWithUnit } from "../../react/FormTextBox";import { useTriliumOption, useTriliumOptionBool, useTriliumOptionJson } from "../../react/hooks";import OptionsRow, { OptionsRowWithButton, OptionsRowWithToggle } from "./components/OptionsRow";import OptionsSection from "./components/OptionsSection";@@ -19,11 +17,6 @@ export default function OtherSettings() {return (<><SearchSettings />- {isElectron() && <>- <SearchEngineSettings />- <TrayOptionsSettings />- <StartupSettings />- </>}<NoteErasureTimeout /><AttachmentErasureTimeout /><RevisionSettings />@@ -59,121 +52,6 @@ function SearchSettings() {);}-function SearchEngineSettings() {- const [ customSearchEngineName, setCustomSearchEngineName ] = useTriliumOption("customSearchEngineName");- const [ customSearchEngineUrl, setCustomSearchEngineUrl ] = useTriliumOption("customSearchEngineUrl");-- const searchEngines = useMemo(() => {- return [- { url: "https://duckduckgo.com/?q={keyword}", name: t("search_engine.duckduckgo") },- { url: "https://www.bing.com/search?q={keyword}", name: t("search_engine.bing"), icon: "bx bxl-bing" },- { url: "https://www.baidu.com/s?wd={keyword}", name: t("search_engine.baidu"), icon: "bx bxl-baidu" },- { url: "https://www.google.com/search?q={keyword}", name: t("search_engine.google"), icon: "bx bxl-google" }- ];- }, []);-- return (- <OptionsSection title={t("search_engine.title")} description={t("search_engine.custom_search_engine_info")}>- <OptionsRow name="predefined-templates" label={t("search_engine.predefined_templates_label")}>- <div className="search-engine-templates">- {searchEngines.map(engine => (- <Badge- key={engine.url}- icon={engine.icon}- text={engine.name}- className={customSearchEngineUrl === engine.url ? "selected" : ""}- onClick={() => {- setCustomSearchEngineName(engine.name);- setCustomSearchEngineUrl(engine.url);- }}- />- ))}- </div>- </OptionsRow>-- <OptionsRow name="custom-name" label={t("search_engine.custom_name_label")}>- <FormTextBox- currentValue={customSearchEngineName} onBlur={setCustomSearchEngineName}- placeholder={t("search_engine.custom_name_placeholder")}- />- </OptionsRow>-- <OptionsRow name="custom-url" label={t("search_engine.custom_url_label")} description={t("search_engine.custom_url_description")} stacked>- <FormTextBox- currentValue={customSearchEngineUrl} onBlur={setCustomSearchEngineUrl}- placeholder={t("search_engine.custom_url_placeholder")}- />- </OptionsRow>- </OptionsSection>- );-}--function StartupSettings() {- const [ launchOnStartup, setLaunchOnStartup ] = useTriliumOptionBool("launchOnStartup");- const [ hideOnAutoStart, setHideOnAutoStart ] = useTriliumOptionBool("hideOnAutoStart");- const [ disableTray ] = useTriliumOptionBool("disableTray");-- return (- <OptionsSection title={t("startup.title")}>- <OptionsRowWithToggle- name="launch-on-startup"- label={t("startup.launch_on_startup")}- description={t("startup.launch_on_startup_description")}- currentValue={launchOnStartup}- onChange={async enabled => {- await setLaunchOnStartup(enabled);- // Apply the change immediately so the user doesn't have to restart the app.- utils.reapplyLaunchOnStartup();- }}- />- <OptionsRowWithToggle- name="hide-on-auto-start"- label={t("startup.hide_on_auto_start")}- description={t("startup.hide_on_auto_start_description")}- currentValue={hideOnAutoStart}- // Only meaningful when launched at login, and the tray must exist to- // bring the hidden window back.- disabled={!launchOnStartup || disableTray}- onChange={async enabled => {- await setHideOnAutoStart(enabled);- // Re-tag the autostart entry so it launches hidden (or not).- utils.reapplyLaunchOnStartup();- }}- />- </OptionsSection>- );-}--function TrayOptionsSettings() {- const [ disableTray, setDisableTray ] = useTriliumOptionBool("disableTray");- const [ closeToTray, setCloseToTray ] = useTriliumOptionBool("closeToTray");-- return (- <OptionsSection title={t("tray.title")}>- <OptionsRowWithToggle- name="tray-enabled"- label={t("tray.enable_tray")}- description={t("tray.enable_tray_description")}- currentValue={!disableTray}- onChange={async trayEnabled => {- await setDisableTray(!trayEnabled);- // Apply the change immediately so the user doesn't have to restart the app.- utils.reloadTray();- }}- />- <OptionsRowWithToggle- name="close-to-tray"- label={t("tray.close_to_tray")}- description={t("tray.close_to_tray_description")}- currentValue={closeToTray}- // Close-to-tray with no tray icon would hide the app with no way back.- disabled={disableTray}- onChange={setCloseToTray}- />- </OptionsSection>- );-}-function NoteErasureTimeout() {return (<OptionsSection title={t("note_erasure_timeout.note_erasure_timeout_title")}>diff --git a/apps/server/src/assets/translations/en/server.json b/apps/server/src/assets/translations/en/server.jsonindex 8c77e157d8..e1f767fa41 100644--- a/apps/server/src/assets/translations/en/server.json+++ b/apps/server/src/assets/translations/en/server.json@@ -324,6 +324,7 @@"code-notes-title": "Code Notes","images-title": "Media","spellcheck-title": "Spellcheck",+ "desktop-title": "Desktop","security-title": "Security","password-title": "Password","multi-factor-authentication-title": "MFA",diff --git a/packages/trilium-core/src/services/hidden_subtree.ts b/packages/trilium-core/src/services/hidden_subtree.tsindex 68e28f7b72..abc6715c99 100644--- a/packages/trilium-core/src/services/hidden_subtree.ts+++ b/packages/trilium-core/src/services/hidden_subtree.ts@@ -302,6 +302,7 @@ function buildHiddenSubtreeDefinition(helpSubtree: HiddenSubtreeItem[]): HiddenS{ 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", 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" },{ id: '_optionsMFA', title: t('hidden-subtree.multi-factor-authentication-title'), type: 'contentWidget', icon: 'bx-lock ', attributes: [{ type: "label", name: "serverOnly" }] },diff --git a/packages/trilium-e2e/src/settings.spec.ts b/packages/trilium-e2e/src/settings.spec.tsindex d1262f0832..f72e34c094 100644--- a/packages/trilium-e2e/src/settings.spec.ts+++ b/packages/trilium-e2e/src/settings.spec.ts@@ -9,11 +9,11 @@ test("Native Title Bar not displayed on web", async ({ page, context }) => {await expect(app.currentNoteSplitContent.getByRole("heading", { name: "Native Title Bar (requires" })).toBeHidden();});-test("Tray settings not displayed on web", async ({ page, context }) => {+test("Desktop settings not displayed on web", async ({ page, context }) => {const app = new App(page, context);- await app.goto({ url: "/#root/_hidden/_options/_optionsOther" });- await expect(app.currentNoteSplitContent.getByRole("heading", { name: "Deleted Notes" })).toBeVisible();- await expect(app.currentNoteSplitContent.getByRole("heading", { name: "Tray" })).toBeHidden();+ await app.goto({ url: "/#root/_hidden/_options/_optionsDesktop" });+ await expect(app.currentNoteSplitContent.getByText("These options apply only for desktop builds")).toBeVisible();+ await expect(app.currentNoteSplitContent.getByRole("heading", { name: "System Tray" })).toBeHidden();});test("Spellcheck settings not displayed on web", async ({ page, context }) => {