mirror of https://github.com/jetkvm/kvm.git
refactor: streamline audio settings state management
Updated the SettingsAudioRoute component to directly use state management functions from useSettingsStore. This change simplifies the handling of audio output and input auto-enable settings, improving code readability and maintainability.
This commit is contained in:
parent
336a75812f
commit
58f3d2d25d
|
|
@ -12,19 +12,18 @@ import notifications from "../notifications";
|
|||
|
||||
export default function SettingsAudioRoute() {
|
||||
const { send } = useJsonRpc();
|
||||
const settings = useSettingsStore();
|
||||
|
||||
const { setAudioOutputEnabled, setAudioInputAutoEnable, audioOutputEnabled, audioInputAutoEnable } = useSettingsStore();
|
||||
useEffect(() => {
|
||||
send("getAudioOutputEnabled", {}, (resp: JsonRpcResponse) => {
|
||||
if ("error" in resp) return;
|
||||
settings.setAudioOutputEnabled(resp.result as boolean);
|
||||
setAudioOutputEnabled(resp.result as boolean);
|
||||
});
|
||||
|
||||
send("getAudioInputAutoEnable", {}, (resp: JsonRpcResponse) => {
|
||||
if ("error" in resp) return;
|
||||
settings.setAudioInputAutoEnable(resp.result as boolean);
|
||||
setAudioInputAutoEnable(resp.result as boolean);
|
||||
});
|
||||
}, [send, settings]);
|
||||
}, [send, setAudioOutputEnabled, setAudioInputAutoEnable]);
|
||||
|
||||
const handleAudioOutputEnabledChange = (enabled: boolean) => {
|
||||
send("setAudioOutputEnabled", { enabled }, (resp: JsonRpcResponse) => {
|
||||
|
|
@ -35,7 +34,7 @@ export default function SettingsAudioRoute() {
|
|||
notifications.error(errorMsg);
|
||||
return;
|
||||
}
|
||||
settings.setAudioOutputEnabled(enabled);
|
||||
setAudioOutputEnabled(enabled);
|
||||
const successMsg = enabled ? m.audio_output_enabled() : m.audio_output_disabled();
|
||||
notifications.success(successMsg);
|
||||
});
|
||||
|
|
@ -47,7 +46,7 @@ export default function SettingsAudioRoute() {
|
|||
notifications.error(String(resp.error.data || m.unknown_error()));
|
||||
return;
|
||||
}
|
||||
settings.setAudioInputAutoEnable(enabled);
|
||||
setAudioInputAutoEnable(enabled);
|
||||
const successMsg = enabled
|
||||
? m.audio_input_auto_enable_enabled()
|
||||
: m.audio_input_auto_enable_disabled();
|
||||
|
|
@ -67,7 +66,7 @@ export default function SettingsAudioRoute() {
|
|||
description={m.audio_settings_output_description()}
|
||||
>
|
||||
<Checkbox
|
||||
checked={settings.audioOutputEnabled || false}
|
||||
checked={audioOutputEnabled || false}
|
||||
onChange={(e) => handleAudioOutputEnabledChange(e.target.checked)}
|
||||
/>
|
||||
</SettingsItem>
|
||||
|
|
@ -77,7 +76,7 @@ export default function SettingsAudioRoute() {
|
|||
description={m.audio_settings_auto_enable_microphone_description()}
|
||||
>
|
||||
<Checkbox
|
||||
checked={settings.audioInputAutoEnable || false}
|
||||
checked={audioInputAutoEnable || false}
|
||||
onChange={(e) => handleAudioInputAutoEnableChange(e.target.checked)}
|
||||
/>
|
||||
</SettingsItem>
|
||||
|
|
|
|||
Loading…
Reference in New Issue