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/security): add an option to restart the app
Elian Dorana11024472911
diff --git a/apps/client/src/translations/en/translation.json b/apps/client/src/translations/en/translation.jsonindex c2a163d95d..8c748a1385 100644--- a/apps/client/src/translations/en/translation.json+++ b/apps/client/src/translations/en/translation.json@@ -1581,7 +1581,8 @@"how_to_enable": "How to enable","server_config_hint": "Add the following to your config.ini file:","server_env_hint": "Or set the following environment variable:",- "restart_required": "Restart required for this change to take effect."+ "restart_required": "Restart required for this change to take effect.",+ "restart_now": "Restart the application now"},"password": {"heading": "Password",diff --git a/apps/client/src/widgets/type_widgets/options/security.tsx b/apps/client/src/widgets/type_widgets/options/security.tsxindex 468c2c61b8..0292834cf6 100644--- a/apps/client/src/widgets/type_widgets/options/security.tsx+++ b/apps/client/src/widgets/type_widgets/options/security.tsx@@ -2,17 +2,33 @@ import { useState } from "preact/hooks";import { t } from "../../../services/i18n";import toast from "../../../services/toast";-import { isElectron } from "../../../services/utils";+import { isElectron, restartDesktopApp } from "../../../services/utils";+import Button from "../../react/Button";import Collapsible from "../../react/Collapsible";import { useTriliumOptionBool } from "../../react/hooks";-import { OptionsRowWithToggle } from "./components/OptionsRow";+import OptionsRow, { OptionsRowWithToggle } from "./components/OptionsRow";import OptionsSection from "./components/OptionsSection";export default function SecuritySettings() {+ const [pendingRestart, setPendingRestart] = useState(false);+return (<>- <BackendScriptingSettings />- <SqlConsoleSettings />+ <BackendScriptingSettings pendingRestart={pendingRestart} setPendingRestart={setPendingRestart} />+ <SqlConsoleSettings pendingRestart={pendingRestart} setPendingRestart={setPendingRestart} />+ {pendingRestart && 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>+ )}</>);}@@ -32,9 +48,13 @@ function ServerConfigHint({ configKey, envVar }: { configKey: string; envVar: st);}-function BackendScriptingSettings() {+interface ToggleSectionProps {+ pendingRestart: boolean;+ setPendingRestart: (value: boolean) => void;+}++function BackendScriptingSettings({ pendingRestart, setPendingRestart }: ToggleSectionProps) {const [backendScriptingEnabled] = useTriliumOptionBool("backendScriptingEnabled");- const [pendingRestart, setPendingRestart] = useState(false);const isDesktop = isElectron();async function handleToggle(enabled: boolean) {@@ -69,9 +89,8 @@ function BackendScriptingSettings() {);}-function SqlConsoleSettings() {+function SqlConsoleSettings({ pendingRestart, setPendingRestart }: ToggleSectionProps) {const [sqlConsoleEnabled] = useTriliumOptionBool("sqlConsoleEnabled");- const [pendingRestart, setPendingRestart] = useState(false);const isDesktop = isElectron();async function handleToggle(enabled: boolean) {