import { useEffect } from "react"; import { SettingsItem } from "@components/SettingsItem"; import { SettingsPageHeader } from "@components/SettingsPageheader"; import { useSettingsStore } from "@/hooks/stores"; import { JsonRpcResponse, useJsonRpc } from "@/hooks/useJsonRpc"; import { SelectMenuBasic } from "@components/SelectMenuBasic"; import Checkbox from "@components/Checkbox"; import notifications from "../notifications"; export default function SettingsAudioRoute() { const { send } = useJsonRpc(); const settings = useSettingsStore(); // Fetch current audio settings on mount useEffect(() => { send("getAudioOutputSource", {}, (resp: JsonRpcResponse) => { if ("error" in resp) { return; } settings.setAudioOutputSource(resp.result as string); }); send("getAudioOutputEnabled", {}, (resp: JsonRpcResponse) => { if ("error" in resp) { return; } settings.setAudioOutputEnabled(resp.result as boolean); }); send("getAudioInputEnabled", {}, (resp: JsonRpcResponse) => { if ("error" in resp) { return; } settings.setAudioInputEnabled(resp.result as boolean); }); // eslint-disable-next-line react-hooks/exhaustive-deps }, [send]); const handleAudioOutputSourceChange = (source: string) => { send("setAudioOutputSource", { source }, (resp: JsonRpcResponse) => { if ("error" in resp) { notifications.error( `Failed to set audio output source: ${resp.error.data || "Unknown error"}`, ); return; } settings.setAudioOutputSource(source); notifications.success("Audio output source updated successfully"); }); }; const handleAudioOutputEnabledChange = (enabled: boolean) => { send("setAudioOutputEnabled", { enabled }, (resp: JsonRpcResponse) => { if ("error" in resp) { notifications.error( `Failed to ${enabled ? "enable" : "disable"} audio output: ${resp.error.data || "Unknown error"}`, ); return; } settings.setAudioOutputEnabled(enabled); notifications.success(`Audio output ${enabled ? "enabled" : "disabled"} successfully`); }); }; const handleAudioInputEnabledChange = (enabled: boolean) => { send("setAudioInputEnabled", { enabled }, (resp: JsonRpcResponse) => { if ("error" in resp) { notifications.error( `Failed to ${enabled ? "enable" : "disable"} audio input: ${resp.error.data || "Unknown error"}`, ); return; } settings.setAudioInputEnabled(enabled); notifications.success(`Audio input ${enabled ? "enabled" : "disabled"} successfully`); }); }; return (
handleAudioOutputEnabledChange(e.target.checked)} /> {settings.audioOutputEnabled && ( { handleAudioOutputSourceChange(e.target.value); }} /> )} handleAudioInputEnabledChange(e.target.checked)} />
); }