From 81ac390eab6202f79e78193deed1106a162fde3a Mon Sep 17 00:00:00 2001 From: Elian Doran Date: Thu, 14 Aug 2025 21:42:48 +0300 Subject: [PATCH] feat(react/settings): port electron integration --- apps/client/src/services/utils.ts | 4 +- apps/client/src/widgets/react/Button.tsx | 2 +- .../type_widgets/options/appearance.tsx | 44 ++++++++++- .../appearance/electron_integration.ts | 76 ------------------- 4 files changed, 43 insertions(+), 83 deletions(-) delete mode 100644 apps/client/src/widgets/type_widgets/options/appearance/electron_integration.ts diff --git a/apps/client/src/services/utils.ts b/apps/client/src/services/utils.ts index 4ae43dcb5..fb2d1941d 100644 --- a/apps/client/src/services/utils.ts +++ b/apps/client/src/services/utils.ts @@ -13,7 +13,7 @@ export function reloadFrontendApp(reason?: string) { window.location.reload(); } -function restartDesktopApp() { +export function restartDesktopApp() { if (!isElectron()) { reloadFrontendApp(); return; @@ -144,7 +144,7 @@ function now() { /** * Returns `true` if the client is currently running under Electron, or `false` if running in a web browser. */ -function isElectron() { +export function isElectron() { return !!(window && window.process && window.process.type); } diff --git a/apps/client/src/widgets/react/Button.tsx b/apps/client/src/widgets/react/Button.tsx index d18e4b5c6..a0ea6da3b 100644 --- a/apps/client/src/widgets/react/Button.tsx +++ b/apps/client/src/widgets/react/Button.tsx @@ -14,7 +14,7 @@ interface ButtonProps { onClick?: () => void; primary?: boolean; disabled?: boolean; - size: "normal" | "small" | "micro"; + size?: "normal" | "small" | "micro"; style?: CSSProperties; } diff --git a/apps/client/src/widgets/type_widgets/options/appearance.tsx b/apps/client/src/widgets/type_widgets/options/appearance.tsx index bdccb5b18..07d0f1ee7 100644 --- a/apps/client/src/widgets/type_widgets/options/appearance.tsx +++ b/apps/client/src/widgets/type_widgets/options/appearance.tsx @@ -1,6 +1,6 @@ import { useEffect, useState } from "preact/hooks"; import { t } from "../../../services/i18n"; -import { isMobile, reloadFrontendApp } from "../../../services/utils"; +import { isElectron, isMobile, reloadFrontendApp, restartDesktopApp } from "../../../services/utils"; import Column from "../../react/Column"; import FormRadioGroup from "../../react/FormRadioGroup"; import FormSelect, { FormSelectWithGroups } from "../../react/FormSelect"; @@ -81,9 +81,10 @@ export default function AppearanceSettings() { return (
- + {!isMobile() && } {overrideThemeFonts === "true" && } + {isElectron() && }
) } @@ -93,7 +94,7 @@ function LayoutOrientation() { return ( - {!isMobile() && } + /> ); } @@ -193,4 +194,39 @@ function Font({ title, fontFamilyOption, fontSizeOption }: { title: string, font ); +} + +function ElectronIntegration() { + const [ zoomFactor, setZoomFactor ] = useTriliumOption("zoomFactor"); + const [ nativeTitleBarVisible, setNativeTitleBarVisible ] = useTriliumOptionBool("nativeTitleBarVisible"); + const [ backgroundEffects, setBackgroundEffects ] = useTriliumOptionBool("backgroundEffects"); + + return ( + + + + +
+ + + + + + + + + + - -`; - -export default class ElectronIntegrationOptions extends OptionsWidget { - - private $zoomFactorSelect!: JQuery; - private $nativeTitleBar!: JQuery; - private $backgroundEffects!: JQuery; - - doRender() { - this.$widget = $(TPL); - - this.$zoomFactorSelect = this.$widget.find(".zoom-factor-select"); - this.$zoomFactorSelect.on("change", () => { - this.triggerCommand("setZoomFactorAndSave", { zoomFactor: String(this.$zoomFactorSelect.val()) }); - }); - - this.$nativeTitleBar = this.$widget.find("input.native-title-bar"); - this.$nativeTitleBar.on("change", () => this.updateCheckboxOption("nativeTitleBarVisible", this.$nativeTitleBar)); - - this.$backgroundEffects = this.$widget.find("input.background-effects"); - this.$backgroundEffects.on("change", () => this.updateCheckboxOption("backgroundEffects", this.$backgroundEffects)); - - const restartAppButton = this.$widget.find(".restart-app-button"); - restartAppButton.on("click", utils.restartDesktopApp); - } - - isEnabled() { - return utils.isElectron(); - } - - async optionsLoaded(options: OptionMap) { - this.$zoomFactorSelect.val(options.zoomFactor); - this.setCheckboxState(this.$nativeTitleBar, options.nativeTitleBarVisible); - this.setCheckboxState(this.$backgroundEffects, options.backgroundEffects); - } -}