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
client/options/security: switch to the new card component
Adorian Dorane70f6c43e319
diff --git a/apps/client/src/widgets/type_widgets/options/security.tsx b/apps/client/src/widgets/type_widgets/options/security.tsxindex 0bada48a13..abcd46ba60 100644--- a/apps/client/src/widgets/type_widgets/options/security.tsx+++ b/apps/client/src/widgets/type_widgets/options/security.tsx@@ -1,14 +1,15 @@import { useState } from "preact/hooks";import { t } from "../../../services/i18n";-import { isElectron, restartDesktopApp } from "../../../services/utils";-import Button from "../../react/Button";+import { isElectron } from "../../../services/utils";+import { Card, CardOption, CardSection } from "../../react/Card";import CodeBlock from "../../react/CodeBlock";import Collapsible from "../../react/Collapsible";+import FormToggle from "../../react/FormToggle";+import HelpButton from "../../react/HelpButton";import { useTriliumOptionBool } from "../../react/hooks";import OptionsPageHeader from "./components/OptionsPageHeader";-import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";-import OptionsSection from "./components/OptionsSection";+import RestartAction from "./components/RestartAction";export default function SecuritySettings() {// Local state tracks what's been written to security.json (pending restart).@@ -47,17 +48,7 @@ export default function SecuritySettings() {/>)}{hasPendingChanges && isElectron() && (- <OptionsSection noCard>- <OptionsRow name="restart" centered>- <Button- name="restart-app-button"- text={t("security.restart_now")}- icon="bx bx-refresh"- size="micro"- onClick={restartDesktopApp}- />- </OptionsRow>- </OptionsSection>+ <RestartAction text={t("security.restart_now")} icon="bx-refresh" />)}</>);@@ -69,14 +60,16 @@ function ServerConfigHint({ configKey, envVar }: { configKey: string; envVar: st}return (- <Collapsible title={t("security.how_to_enable")}>- <p>{t("security.server_config_hint")}</p>- {/* `text/x-toml` is Trilium's entry for INI-family files — it is backed by- highlight.js's `ini` grammar, which is what config.ini actually is. */}- <CodeBlock mimeType="text/x-toml" code={`[Security]\n${configKey}=true`} />- <p>{t("security.server_env_hint")}</p>- <CodeBlock mimeType="text/x-sh" code={`${envVar}=true`} />- </Collapsible>+ <CardSection>+ <Collapsible title={t("security.how_to_enable")}>+ <p>{t("security.server_config_hint")}</p>+ {/* `text/x-toml` is Trilium's entry for INI-family files — it is backed by+ highlight.js's `ini` grammar, which is what config.ini actually is. */}+ <CodeBlock mimeType="text/x-toml" code={`[Security]\n${configKey}=true`} />+ <p>{t("security.server_env_hint")}</p>+ <CodeBlock mimeType="text/x-sh" code={`${envVar}=true`} />+ </Collapsible>+ </CardSection>);}@@ -92,7 +85,7 @@ function BackendScriptingSettings({ liveValue, pendingValue, setPendingValue }:const hasPendingChange = pendingValue !== null && pendingValue !== liveValue;async function handleToggle(enabled: boolean) {- const confirmed = await window.electronApi!.security.setBackendScriptingEnabled(enabled);+ const confirmed = await window.electronApi?.security.setBackendScriptingEnabled(enabled);if (confirmed) {// If toggling back to the live value, clear pending statesetPendingValue(enabled === liveValue ? null : enabled);@@ -100,26 +93,28 @@ function BackendScriptingSettings({ liveValue, pendingValue, setPendingValue }:}return (- <OptionsSection- title={t("security.backend_scripting_title")}- description={t("security.backend_scripting_section_description")}- helpUrl="SPirpZypehBG"- >- <OptionsRowWithToggle- name="backend-scripting-enabled"- label={t("security.backend_scripting_label")}- description={hasPendingChange- ? t("security.restart_required")- : t("security.backend_scripting_description")}- currentValue={displayValue}- onChange={handleToggle}- disabled={!isDesktop}- />- <ServerConfigHint- configKey="backendScriptingEnabled"- envVar="TRILIUM_SECURITY_BACKEND_SCRIPTING_ENABLED"- />- </OptionsSection>+ <div className="options-section">+ <Card+ heading={t("security.backend_scripting_title")}+ description={t("security.backend_scripting_section_description")}+ actions={<HelpButton helpPage="SPirpZypehBG" />}+ >+ <CardOption+ name="backend-scripting-enabled"+ label={t("security.backend_scripting_label")}+ description={hasPendingChange+ ? t("security.restart_required")+ : t("security.backend_scripting_description")}+ >+ <FormToggle currentValue={displayValue} onChange={handleToggle} disabled={!isDesktop} />+ </CardOption>++ <ServerConfigHint+ configKey="backendScriptingEnabled"+ envVar="TRILIUM_SECURITY_BACKEND_SCRIPTING_ENABLED"+ />+ </Card>+ </div>);}@@ -129,33 +124,35 @@ function SqlConsoleSettings({ liveValue, pendingValue, setPendingValue }: Toggleconst hasPendingChange = pendingValue !== null && pendingValue !== liveValue;async function handleToggle(enabled: boolean) {- const confirmed = await window.electronApi!.security.setSqlConsoleEnabled(enabled);+ const confirmed = await window.electronApi?.security.setSqlConsoleEnabled(enabled);if (confirmed) {setPendingValue(enabled === liveValue ? null : enabled);}}return (- <OptionsSection- title={t("security.sql_console_title")}- description={t("security.sql_console_section_description")}- helpUrl="YKWqdJhzi2VY"- >- <OptionsRowWithToggle- name="sql-console-enabled"- label={t("security.sql_console_label")}- description={hasPendingChange- ? t("security.restart_required")- : t("security.sql_console_description")}- currentValue={displayValue}- onChange={handleToggle}- disabled={!isDesktop}- />- <ServerConfigHint- configKey="sqlConsoleEnabled"- envVar="TRILIUM_SECURITY_SQL_CONSOLE_ENABLED"- />- </OptionsSection>+ <div className="options-section">+ <Card+ heading={t("security.sql_console_title")}+ description={t("security.sql_console_section_description")}+ actions={<HelpButton helpPage="YKWqdJhzi2VY" />}+ >+ <CardOption+ name="sql-console-enabled"+ label={t("security.sql_console_label")}+ description={hasPendingChange+ ? t("security.restart_required")+ : t("security.sql_console_description")}+ >+ <FormToggle currentValue={displayValue} onChange={handleToggle} disabled={!isDesktop} />+ </CardOption>++ <ServerConfigHint+ configKey="sqlConsoleEnabled"+ envVar="TRILIUM_SECURITY_SQL_CONSOLE_ENABLED"+ />+ </Card>+ </div>);}@@ -174,20 +171,22 @@ function LanAccessSettings({ liveValue, pendingValue, setPendingValue }: ToggleS}return (- <OptionsSection- title={t("security.lan_access_title")}- description={t("security.lan_access_section_description")}- helpUrl="swSFivWk6KkA"- >- <OptionsRowWithToggle- name="lan-access-enabled"- label={t("security.lan_access_label")}- description={hasPendingChange- ? t("security.restart_required")- : t("security.lan_access_description")}- currentValue={displayValue}- onChange={handleToggle}- />- </OptionsSection>+ <div className="options-section">+ <Card+ heading={t("security.lan_access_title")}+ description={t("security.lan_access_section_description")}+ actions={<HelpButton helpPage="swSFivWk6KkA" />}+ >+ <CardOption+ name="lan-access-enabled"+ label={t("security.lan_access_label")}+ description={hasPendingChange+ ? t("security.restart_required")+ : t("security.lan_access_description")}+ >+ <FormToggle currentValue={displayValue} onChange={handleToggle} />+ </CardOption>+ </Card>+ </div>);}