From b844a8a3e857b382bc08ab670c9dfabf598c74ba Mon Sep 17 00:00:00 2001 From: Adam Shiervani Date: Thu, 16 Oct 2025 16:48:35 +0200 Subject: [PATCH] feat: add power saving mode toggle in hardware settings Implemented a new feature to enable or disable HDMI sleep mode, allowing users to reduce power consumption when the device is not in use. Added state management for the power saving setting and integrated it with the existing settings page. --- .../routes/devices.$id.settings.hardware.tsx | 51 ++++++++++++++++++- 1 file changed, 50 insertions(+), 1 deletion(-) diff --git a/ui/src/routes/devices.$id.settings.hardware.tsx b/ui/src/routes/devices.$id.settings.hardware.tsx index 9475f4fe..58578e4d 100644 --- a/ui/src/routes/devices.$id.settings.hardware.tsx +++ b/ui/src/routes/devices.$id.settings.hardware.tsx @@ -1,11 +1,13 @@ -import { useEffect } from "react"; +import { useEffect, useState } from "react"; import { SettingsItem } from "@components/SettingsItem"; import { SettingsPageHeader } from "@components/SettingsPageheader"; +import { SettingsSectionHeader } from "@components/SettingsSectionHeader"; import { BacklightSettings, useSettingsStore } from "@/hooks/stores"; import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc"; import { SelectMenuBasic } from "@components/SelectMenuBasic"; import { UsbDeviceSetting } from "@components/UsbDeviceSetting"; +import { Checkbox } from "@components/Checkbox"; import notifications from "../notifications"; import { UsbInfoSetting } from "../components/UsbInfoSetting"; @@ -15,6 +17,7 @@ export default function SettingsHardwareRoute() { const { send } = useJsonRpc(); const settings = useSettingsStore(); const { setDisplayRotation } = useSettingsStore(); + const [powerSavingEnabled, setPowerSavingEnabled] = useState(false); const handleDisplayRotationChange = (rotation: string) => { setDisplayRotation(rotation); @@ -58,6 +61,21 @@ export default function SettingsHardwareRoute() { }); }; + const handlePowerSavingChange = (enabled: boolean) => { + setPowerSavingEnabled(enabled); + const duration = enabled ? 90 : -1; + send("setVideoSleepMode", { duration }, (resp: JsonRpcResponse) => { + if ("error" in resp) { + notifications.error( + `Failed to set power saving mode: ${resp.error.data || "Unknown error"}`, + ); + setPowerSavingEnabled(!enabled); // Revert on error + return; + } + notifications.success(`Power saving mode ${enabled ? "enabled" : "disabled"}`); + }); + }; + useEffect(() => { send("getBacklightSettings", {}, (resp: JsonRpcResponse) => { if ("error" in resp) { @@ -70,6 +88,17 @@ export default function SettingsHardwareRoute() { }); }, [send, setBacklightSettings]); + useEffect(() => { + send("getVideoSleepMode", {}, (resp: JsonRpcResponse) => { + if ("error" in resp) { + console.error("Failed to get power saving mode:", resp.error); + return; + } + const result = resp.result as { enabled: boolean; duration: number }; + setPowerSavingEnabled(result.duration > 0); + }); + }, [send]); + return (
+ +
+
+ + + handlePowerSavingChange(e.target.checked)} + /> + +
+ +