[Refactor] Put together device-related logic into useDevice.

This commit is contained in:
Sakamoto Shiina
2025-06-14 03:24:39 +09:00
parent fb2b224231
commit 4886552639
16 changed files with 318 additions and 371 deletions

View File

@@ -7,8 +7,7 @@ import { useVolume } from "@logics_common";
import MicSvg from "@images/mic.svg?react"; import MicSvg from "@images/mic.svg?react";
import HeadphonesSvg from "@images/headphones.svg?react"; import HeadphonesSvg from "@images/headphones.svg?react";
import { import {
useMicThreshold, useDevice,
useSpeakerThreshold,
} from "@logics_configs"; } from "@logics_configs";
export const ThresholdComponent = (props) => { export const ThresholdComponent = (props) => {
@@ -27,7 +26,7 @@ const MicComponent = (props) => {
currentMicThreshold, currentMicThreshold,
setMicThreshold, setMicThreshold,
currentEnableAutomaticMicThreshold, currentEnableAutomaticMicThreshold,
} = useMicThreshold(); } = useDevice();
const [ui_threshold, setUiThreshold] = useState(currentMicThreshold.data); const [ui_threshold, setUiThreshold] = useState(currentMicThreshold.data);
const { const {
volumeCheckStart_Mic, volumeCheckStart_Mic,
@@ -84,7 +83,7 @@ const SpeakerComponent = (props) => {
currentSpeakerThreshold, currentSpeakerThreshold,
setSpeakerThreshold, setSpeakerThreshold,
currentEnableAutomaticSpeakerThreshold, currentEnableAutomaticSpeakerThreshold,
} = useSpeakerThreshold(); } = useDevice();
const [ui_threshold, setUiThreshold] = useState(currentSpeakerThreshold.data); const [ui_threshold, setUiThreshold] = useState(currentSpeakerThreshold.data);
const { const {
volumeCheckStart_Speaker, volumeCheckStart_Speaker,

View File

@@ -4,8 +4,7 @@ import {
useStore_SpeakerVolume, useStore_SpeakerVolume,
} from "@store"; } from "@store";
import { import {
useMicThreshold, useDevice,
useSpeakerThreshold,
} from "@logics_configs"; } from "@logics_configs";
export const SliderAndMeter = (props) => { export const SliderAndMeter = (props) => {
@@ -24,7 +23,7 @@ export const SliderAndMeter = (props) => {
const ThresholdVolumeMeter_Mic = (props) => { const ThresholdVolumeMeter_Mic = (props) => {
const { currentMicVolume } = useStore_MicVolume(); const { currentMicVolume } = useStore_MicVolume();
const { currentEnableAutomaticMicThreshold } = useMicThreshold(); const { currentEnableAutomaticMicThreshold } = useDevice();
const currentVolumeVariable = Math.min(currentMicVolume.data, props.max); const currentVolumeVariable = Math.min(currentMicVolume.data, props.max);
const volume_width_percentage = (currentVolumeVariable / props.max) * 100; const volume_width_percentage = (currentVolumeVariable / props.max) * 100;
@@ -50,7 +49,7 @@ const ThresholdVolumeMeter_Mic = (props) => {
const ThresholdVolumeMeter_Speaker = (props) => { const ThresholdVolumeMeter_Speaker = (props) => {
const { currentSpeakerVolume } = useStore_SpeakerVolume(); const { currentSpeakerVolume } = useStore_SpeakerVolume();
const { currentEnableAutomaticSpeakerThreshold } = useSpeakerThreshold(); const { currentEnableAutomaticSpeakerThreshold } = useDevice();
const currentVolumeVariable = Math.min(currentSpeakerVolume.data, props.max); const currentVolumeVariable = Math.min(currentSpeakerVolume.data, props.max);
const volume_width_percentage = (currentVolumeVariable / props.max) * 100; const volume_width_percentage = (currentVolumeVariable / props.max) * 100;

View File

@@ -4,16 +4,7 @@ import clsx from "clsx";
import { useStore_IsBreakPoint } from "@store"; import { useStore_IsBreakPoint } from "@store";
import { ui_configs } from "@ui_configs"; import { ui_configs } from "@ui_configs";
import { import {
useEnableAutoMicSelect, useDevice,
useMicHostList,
useSelectedMicHost,
useMicDeviceList,
useSelectedMicDevice,
useMicThreshold,
useEnableAutoSpeakerSelect,
useSpeakerDeviceList,
useSelectedSpeakerDevice,
useSpeakerThreshold,
} from "@logics_configs"; } from "@logics_configs";
import { import {
@@ -38,13 +29,21 @@ export const Device = () => {
const Mic_Container = () => { const Mic_Container = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { currentEnableAutoMicSelect, toggleEnableAutoMicSelect } = useEnableAutoMicSelect(); const {
const { currentSelectedMicHost, setSelectedMicHost } = useSelectedMicHost(); currentEnableAutoMicSelect,
const { currentMicHostList } = useMicHostList(); toggleEnableAutoMicSelect,
const { currentSelectedMicDevice, setSelectedMicDevice } = useSelectedMicDevice(); currentMicDeviceList,
const { currentMicDeviceList } = useMicDeviceList(); currentMicHostList,
currentSelectedMicHost,
setSelectedMicHost,
currentSelectedMicDevice,
setSelectedMicDevice,
currentEnableAutomaticMicThreshold,
toggleEnableAutomaticMicThreshold,
} = useDevice();
const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu(); const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu();
const { currentEnableAutomaticMicThreshold, toggleEnableAutomaticMicThreshold } = useMicThreshold();
const selectFunction_host = (selected_data) => { const selectFunction_host = (selected_data) => {
setSelectedMicHost(selected_data.selected_id); setSelectedMicHost(selected_data.selected_id);
@@ -139,11 +138,16 @@ const Mic_Container = () => {
const Speaker_Container = () => { const Speaker_Container = () => {
const { t } = useTranslation(); const { t } = useTranslation();
const { currentEnableAutoSpeakerSelect, toggleEnableAutoSpeakerSelect } = useEnableAutoSpeakerSelect(); const {
const { currentSelectedSpeakerDevice, setSelectedSpeakerDevice } = useSelectedSpeakerDevice(); currentEnableAutoSpeakerSelect,
const { currentSpeakerDeviceList } = useSpeakerDeviceList(); toggleEnableAutoSpeakerSelect,
currentSpeakerDeviceList,
currentSelectedSpeakerDevice,
setSelectedSpeakerDevice,
currentEnableAutomaticSpeakerThreshold,
toggleEnableAutomaticSpeakerThreshold,
} = useDevice();
const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu(); const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu();
const { currentEnableAutomaticSpeakerThreshold, toggleEnableAutomaticSpeakerThreshold } = useSpeakerThreshold();
const selectFunction = (selected_data) => { const selectFunction = (selected_data) => {
setSelectedSpeakerDevice(selected_data.selected_id); setSelectedSpeakerDevice(selected_data.selected_id);

View File

@@ -0,0 +1,257 @@
import {
useStore_EnableAutoMicSelect,
useStore_EnableAutoSpeakerSelect,
useStore_MicDeviceList,
useStore_MicHostList,
useStore_SpeakerDeviceList,
useStore_SelectedMicHost,
useStore_SelectedMicDevice,
useStore_SelectedSpeakerDevice,
useStore_MicThreshold,
useStore_EnableAutomaticMicThreshold,
useStore_SpeakerThreshold,
useStore_EnableAutomaticSpeakerThreshold,
} from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
import { arrayToObject } from "@utils";
export const useDevice = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentEnableAutoMicSelect, updateEnableAutoMicSelect, pendingEnableAutoMicSelect } = useStore_EnableAutoMicSelect();
const { currentEnableAutoSpeakerSelect, updateEnableAutoSpeakerSelect, pendingEnableAutoSpeakerSelect } = useStore_EnableAutoSpeakerSelect();
const { currentMicDeviceList, updateMicDeviceList, pendingMicDeviceList } = useStore_MicDeviceList();
const { currentMicHostList, updateMicHostList, pendingMicHostList } = useStore_MicHostList();
const { currentSpeakerDeviceList, updateSpeakerDeviceList, pendingSpeakerDeviceList } = useStore_SpeakerDeviceList();
const { currentSelectedMicHost, updateSelectedMicHost, pendingSelectedMicHost } = useStore_SelectedMicHost();
const { currentSelectedMicDevice, updateSelectedMicDevice, pendingSelectedMicDevice } = useStore_SelectedMicDevice();
const { currentSelectedSpeakerDevice, updateSelectedSpeakerDevice, pendingSelectedSpeakerDevice } = useStore_SelectedSpeakerDevice();
const { updateMicThreshold, currentMicThreshold } = useStore_MicThreshold();
const { updateEnableAutomaticMicThreshold, currentEnableAutomaticMicThreshold, pendingEnableAutomaticMicThreshold } = useStore_EnableAutomaticMicThreshold();
const { updateSpeakerThreshold, currentSpeakerThreshold } = useStore_SpeakerThreshold();
const { updateEnableAutomaticSpeakerThreshold, currentEnableAutomaticSpeakerThreshold, pendingEnableAutomaticSpeakerThreshold } = useStore_EnableAutomaticSpeakerThreshold();
// Auto Select (Mic)
const getEnableAutoMicSelect = () => {
pendingEnableAutoMicSelect();
asyncStdoutToPython("/get/data/auto_mic_select");
};
const toggleEnableAutoMicSelect = () => {
pendingEnableAutoMicSelect();
if (currentEnableAutoMicSelect.data) {
asyncStdoutToPython("/set/disable/auto_mic_select");
} else {
asyncStdoutToPython("/set/enable/auto_mic_select");
}
};
// Auto Select (Speaker)
const getEnableAutoSpeakerSelect = () => {
pendingEnableAutoSpeakerSelect();
asyncStdoutToPython("/get/data/auto_speaker_select");
};
const toggleEnableAutoSpeakerSelect = () => {
pendingEnableAutoSpeakerSelect();
if (currentEnableAutoSpeakerSelect.data) {
asyncStdoutToPython("/set/disable/auto_speaker_select");
} else {
asyncStdoutToPython("/set/enable/auto_speaker_select");
}
};
// List (Mic device)
const getMicDeviceList = () => {
pendingMicDeviceList();
asyncStdoutToPython("/get/data/mic_device_list");
};
const updateMicDeviceList_FromBackend = (payload) => {
updateMicDeviceList(arrayToObject(payload));
};
// List (Mic host)
const getMicHostList = () => {
pendingMicHostList();
asyncStdoutToPython("/get/data/mic_host_list");
};
const updateMicHostList_FromBackend = (payload) => {
updateMicHostList(arrayToObject(payload));
};
// List (Speaker device)
const getSpeakerDeviceList = () => {
pendingSpeakerDeviceList();
asyncStdoutToPython("/get/data/speaker_device_list");
};
const updateSpeakerDeviceList_FromBackend = (payload) => {
updateSpeakerDeviceList(arrayToObject(payload));
};
// Selected (Mic host)
const getSelectedMicHost = () => {
pendingSelectedMicHost();
asyncStdoutToPython("/get/data/selected_mic_host");
};
const setSelectedMicHost = (selected_mic_host) => {
pendingSelectedMicHost();
asyncStdoutToPython("/set/data/selected_mic_host", selected_mic_host);
};
// Selected (Mic device)
const getSelectedMicDevice = () => {
pendingSelectedMicDevice();
asyncStdoutToPython("/get/data/selected_mic_device");
};
const setSelectedMicDevice = (selected_mic_device) => {
pendingSelectedMicDevice();
asyncStdoutToPython("/set/data/selected_mic_device", selected_mic_device);
};
// Selected (Mic and Host)
const updateSelectedMicHostAndDevice = (payload) => {
updateSelectedMicHost(payload.host);
updateSelectedMicDevice(payload.device);
};
// Selected (Speaker device)
const getSelectedSpeakerDevice = () => {
pendingSelectedSpeakerDevice();
asyncStdoutToPython("/get/data/selected_speaker_device");
};
const setSelectedSpeakerDevice = (selected_speaker_device) => {
pendingSelectedSpeakerDevice();
asyncStdoutToPython("/set/data/selected_speaker_device", selected_speaker_device);
};
// Threshold (Mic)
const getMicThreshold = () => {
asyncStdoutToPython("/get/data/mic_threshold");
};
const setMicThreshold = (mic_threshold) => {
asyncStdoutToPython("/set/data/mic_threshold", mic_threshold);
};
const getEnableAutomaticMicThreshold = () => {
pendingEnableAutomaticMicThreshold();
asyncStdoutToPython("/get/data/mic_automatic_threshold");
};
const toggleEnableAutomaticMicThreshold = () => {
pendingEnableAutomaticMicThreshold();
if (currentEnableAutomaticMicThreshold.data) {
asyncStdoutToPython("/set/disable/mic_automatic_threshold");
} else {
asyncStdoutToPython("/set/enable/mic_automatic_threshold");
}
};
// Threshold (Speaker)
const getSpeakerThreshold = () => {
asyncStdoutToPython("/get/data/speaker_threshold");
};
const setSpeakerThreshold = (speaker_threshold) => {
asyncStdoutToPython("/set/data/speaker_threshold", speaker_threshold);
};
const getEnableAutomaticSpeakerThreshold = () => {
pendingEnableAutomaticSpeakerThreshold();
asyncStdoutToPython("/get/data/speaker_automatic_threshold");
};
const toggleEnableAutomaticSpeakerThreshold = () => {
pendingEnableAutomaticSpeakerThreshold();
if (currentEnableAutomaticSpeakerThreshold.data) {
asyncStdoutToPython("/set/disable/speaker_automatic_threshold");
} else {
asyncStdoutToPython("/set/enable/speaker_automatic_threshold");
}
};
return {
currentEnableAutoMicSelect,
getEnableAutoMicSelect,
updateEnableAutoMicSelect,
toggleEnableAutoMicSelect,
currentEnableAutoSpeakerSelect,
getEnableAutoSpeakerSelect,
updateEnableAutoSpeakerSelect,
toggleEnableAutoSpeakerSelect,
currentMicDeviceList,
getMicDeviceList,
updateMicDeviceList,
updateMicDeviceList_FromBackend,
currentMicHostList,
getMicHostList,
updateMicHostList,
updateMicHostList_FromBackend,
currentSpeakerDeviceList,
getSpeakerDeviceList,
updateSpeakerDeviceList,
updateSpeakerDeviceList_FromBackend,
currentSelectedMicHost,
getSelectedMicHost,
updateSelectedMicHost,
setSelectedMicHost,
currentSelectedMicDevice,
getSelectedMicDevice,
updateSelectedMicDevice,
setSelectedMicDevice,
updateSelectedMicHostAndDevice,
currentSelectedSpeakerDevice,
getSelectedSpeakerDevice,
updateSelectedSpeakerDevice,
setSelectedSpeakerDevice,
currentMicThreshold,
getMicThreshold,
setMicThreshold,
updateMicThreshold,
currentEnableAutomaticMicThreshold,
getEnableAutomaticMicThreshold,
toggleEnableAutomaticMicThreshold,
updateEnableAutomaticMicThreshold,
currentSpeakerThreshold,
getSpeakerThreshold,
setSpeakerThreshold,
updateSpeakerThreshold,
currentEnableAutomaticSpeakerThreshold,
getEnableAutomaticSpeakerThreshold,
toggleEnableAutomaticSpeakerThreshold,
updateEnableAutomaticSpeakerThreshold,
};
};

View File

@@ -1,28 +0,0 @@
import { useStore_EnableAutoMicSelect } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
export const useEnableAutoMicSelect = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentEnableAutoMicSelect, updateEnableAutoMicSelect, pendingEnableAutoMicSelect } = useStore_EnableAutoMicSelect();
const getEnableAutoMicSelect = () => {
pendingEnableAutoMicSelect();
asyncStdoutToPython("/get/data/auto_mic_select");
};
const toggleEnableAutoMicSelect = () => {
pendingEnableAutoMicSelect();
if (currentEnableAutoMicSelect.data) {
asyncStdoutToPython("/set/disable/auto_mic_select");
} else {
asyncStdoutToPython("/set/enable/auto_mic_select");
}
};
return {
currentEnableAutoMicSelect,
getEnableAutoMicSelect,
updateEnableAutoMicSelect,
toggleEnableAutoMicSelect,
};
};

View File

@@ -1,28 +0,0 @@
import { useStore_EnableAutoSpeakerSelect } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
export const useEnableAutoSpeakerSelect = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentEnableAutoSpeakerSelect, updateEnableAutoSpeakerSelect, pendingEnableAutoSpeakerSelect } = useStore_EnableAutoSpeakerSelect();
const getEnableAutoSpeakerSelect = () => {
pendingEnableAutoSpeakerSelect();
asyncStdoutToPython("/get/data/auto_speaker_select");
};
const toggleEnableAutoSpeakerSelect = () => {
pendingEnableAutoSpeakerSelect();
if (currentEnableAutoSpeakerSelect.data) {
asyncStdoutToPython("/set/disable/auto_speaker_select");
} else {
asyncStdoutToPython("/set/enable/auto_speaker_select");
}
};
return {
currentEnableAutoSpeakerSelect,
getEnableAutoSpeakerSelect,
updateEnableAutoSpeakerSelect,
toggleEnableAutoSpeakerSelect,
};
};

View File

@@ -1,27 +0,0 @@
import { useStore_MicDeviceList } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
import { arrayToObject } from "@utils";
export const useMicDeviceList = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentMicDeviceList, updateMicDeviceList, pendingMicDeviceList } = useStore_MicDeviceList();
const getMicDeviceList = () => {
pendingMicDeviceList();
asyncStdoutToPython("/get/data/mic_device_list");
};
const updateMicDeviceList_FromBackend = (payload) => {
updateMicDeviceList(arrayToObject(payload));
};
return {
currentMicDeviceList,
getMicDeviceList,
updateMicDeviceList,
updateMicDeviceList_FromBackend,
};
};

View File

@@ -1,25 +0,0 @@
import { useStore_MicHostList } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
import { arrayToObject } from "@utils";
export const useMicHostList = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentMicHostList, updateMicHostList, pendingMicHostList } = useStore_MicHostList();
const getMicHostList = () => {
pendingMicHostList();
asyncStdoutToPython("/get/data/mic_host_list");
};
const updateMicHostList_FromBackend = (payload) => {
updateMicHostList(arrayToObject(payload));
};
return {
currentMicHostList,
getMicHostList,
updateMicHostList,
updateMicHostList_FromBackend,
};
};

View File

@@ -1,42 +0,0 @@
import { useStore_MicThreshold, useStore_EnableAutomaticMicThreshold } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
export const useMicThreshold = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { updateMicThreshold, currentMicThreshold } = useStore_MicThreshold();
const { updateEnableAutomaticMicThreshold, currentEnableAutomaticMicThreshold, pendingEnableAutomaticMicThreshold } = useStore_EnableAutomaticMicThreshold();
const getMicThreshold = () => {
asyncStdoutToPython("/get/data/mic_threshold");
};
const setMicThreshold = (mic_threshold) => {
asyncStdoutToPython("/set/data/mic_threshold", mic_threshold);
};
const getEnableAutomaticMicThreshold = () => {
pendingEnableAutomaticMicThreshold();
asyncStdoutToPython("/get/data/mic_automatic_threshold");
};
const toggleEnableAutomaticMicThreshold = () => {
pendingEnableAutomaticMicThreshold();
if (currentEnableAutomaticMicThreshold.data) {
asyncStdoutToPython("/set/disable/mic_automatic_threshold");
} else {
asyncStdoutToPython("/set/enable/mic_automatic_threshold");
}
};
return {
currentMicThreshold,
getMicThreshold,
setMicThreshold,
updateMicThreshold,
currentEnableAutomaticMicThreshold,
getEnableAutomaticMicThreshold,
toggleEnableAutomaticMicThreshold,
updateEnableAutomaticMicThreshold,
};
};

View File

@@ -1,24 +0,0 @@
import { useStore_SelectedMicDevice } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
export const useSelectedMicDevice = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentSelectedMicDevice, updateSelectedMicDevice, pendingSelectedMicDevice } = useStore_SelectedMicDevice();
const getSelectedMicDevice = () => {
pendingSelectedMicDevice();
asyncStdoutToPython("/get/data/selected_mic_device");
};
const setSelectedMicDevice = (selected_mic_device) => {
pendingSelectedMicDevice();
asyncStdoutToPython("/set/data/selected_mic_device", selected_mic_device);
};
return {
currentSelectedMicDevice,
getSelectedMicDevice,
updateSelectedMicDevice,
setSelectedMicDevice,
};
};

View File

@@ -1,37 +0,0 @@
import { useStore_SelectedMicHost } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
import { useSelectedMicDevice } from "@logics_configs";
export const useSelectedMicHost = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentSelectedMicHost, updateSelectedMicHost, pendingSelectedMicHost } = useStore_SelectedMicHost();
const { updateSelectedMicDevice } = useSelectedMicDevice();
const getSelectedMicHost = () => {
pendingSelectedMicHost();
asyncStdoutToPython("/get/data/selected_mic_host");
};
const setSelectedMicHost = (selected_mic_host) => {
pendingSelectedMicHost();
asyncStdoutToPython("/set/data/selected_mic_host", selected_mic_host);
};
// Need refactoring (Duplicated, Host, Device)
const updateSelectedMicHostAndDevice = (payload) => {
updateSelectedMicHost(payload.host);
updateSelectedMicDevice(payload.device);
};
return {
currentSelectedMicHost,
getSelectedMicHost,
updateSelectedMicHost,
setSelectedMicHost,
updateSelectedMicHostAndDevice,
};
};

View File

@@ -1,24 +0,0 @@
import { useStore_SelectedSpeakerDevice } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
export const useSelectedSpeakerDevice = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentSelectedSpeakerDevice, updateSelectedSpeakerDevice, pendingSelectedSpeakerDevice } = useStore_SelectedSpeakerDevice();
const getSelectedSpeakerDevice = () => {
pendingSelectedSpeakerDevice();
asyncStdoutToPython("/get/data/selected_speaker_device");
};
const setSelectedSpeakerDevice = (selected_speaker_device) => {
pendingSelectedSpeakerDevice();
asyncStdoutToPython("/set/data/selected_speaker_device", selected_speaker_device);
};
return {
currentSelectedSpeakerDevice,
getSelectedSpeakerDevice,
updateSelectedSpeakerDevice,
setSelectedSpeakerDevice,
};
};

View File

@@ -1,26 +0,0 @@
import { useStore_SpeakerDeviceList } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
import { arrayToObject } from "@utils";
export const useSpeakerDeviceList = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { currentSpeakerDeviceList, updateSpeakerDeviceList, pendingSpeakerDeviceList } = useStore_SpeakerDeviceList();
const getSpeakerDeviceList = () => {
pendingSpeakerDeviceList();
asyncStdoutToPython("/get/data/speaker_device_list");
};
const updateSpeakerDeviceList_FromBackend = (payload) => {
updateSpeakerDeviceList(arrayToObject(payload));
};
return {
currentSpeakerDeviceList,
getSpeakerDeviceList,
updateSpeakerDeviceList,
updateSpeakerDeviceList_FromBackend,
};
};

View File

@@ -1,42 +0,0 @@
import { useStore_SpeakerThreshold, useStore_EnableAutomaticSpeakerThreshold } from "@store";
import { useStdoutToPython } from "@useStdoutToPython";
export const useSpeakerThreshold = () => {
const { asyncStdoutToPython } = useStdoutToPython();
const { updateSpeakerThreshold, currentSpeakerThreshold } = useStore_SpeakerThreshold();
const { updateEnableAutomaticSpeakerThreshold, currentEnableAutomaticSpeakerThreshold, pendingEnableAutomaticSpeakerThreshold } = useStore_EnableAutomaticSpeakerThreshold();
const getSpeakerThreshold = () => {
asyncStdoutToPython("/get/data/speaker_threshold");
};
const setSpeakerThreshold = (speaker_threshold) => {
asyncStdoutToPython("/set/data/speaker_threshold", speaker_threshold);
};
const getEnableAutomaticSpeakerThreshold = () => {
pendingEnableAutomaticSpeakerThreshold();
asyncStdoutToPython("/get/data/speaker_automatic_threshold");
};
const toggleEnableAutomaticSpeakerThreshold = () => {
pendingEnableAutomaticSpeakerThreshold();
if (currentEnableAutomaticSpeakerThreshold.data) {
asyncStdoutToPython("/set/disable/speaker_automatic_threshold");
} else {
asyncStdoutToPython("/set/enable/speaker_automatic_threshold");
}
};
return {
currentSpeakerThreshold,
getSpeakerThreshold,
setSpeakerThreshold,
updateSpeakerThreshold,
currentEnableAutomaticSpeakerThreshold,
getEnableAutomaticSpeakerThreshold,
toggleEnableAutomaticSpeakerThreshold,
updateEnableAutomaticSpeakerThreshold,
};
};

View File

@@ -1,13 +1,4 @@
export { useEnableAutoMicSelect } from "./device/useEnableAutoMicSelect"; export { useDevice } from "./device/useDevice";
export { useEnableAutoSpeakerSelect } from "./device/useEnableAutoSpeakerSelect";
export { useMicDeviceList } from "./device/useMicDeviceList";
export { useMicHostList } from "./device/useMicHostList";
export { useMicThreshold } from "./device/useMicThreshold";
export { useSelectedMicDevice } from "./device/useSelectedMicDevice";
export { useSelectedMicHost } from "./device/useSelectedMicHost";
export { useSelectedSpeakerDevice } from "./device/useSelectedSpeakerDevice";
export { useSpeakerDeviceList } from "./device/useSpeakerDeviceList";
export { useSpeakerThreshold } from "./device/useSpeakerThreshold";
export { useMessageLogUiScaling } from "./appearance/useMessageLogUiScaling"; export { useMessageLogUiScaling } from "./appearance/useMessageLogUiScaling";
export { useSelectedFontFamily } from "./appearance/useSelectedFontFamily"; export { useSelectedFontFamily } from "./appearance/useSelectedFontFamily";

View File

@@ -91,49 +91,49 @@ export const ROUTE_META_LIST = [
// Config Page // Config Page
// Device // Device
{ endpoint: "/get/data/auto_mic_select", ns: configs, hook_name: "useEnableAutoMicSelect", method_name: "updateEnableAutoMicSelect" }, { endpoint: "/get/data/auto_mic_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoMicSelect" },
{ endpoint: "/set/enable/auto_mic_select", ns: configs, hook_name: "useEnableAutoMicSelect", method_name: "updateEnableAutoMicSelect" }, { endpoint: "/set/enable/auto_mic_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoMicSelect" },
{ endpoint: "/set/disable/auto_mic_select", ns: configs, hook_name: "useEnableAutoMicSelect", method_name: "updateEnableAutoMicSelect" }, { endpoint: "/set/disable/auto_mic_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoMicSelect" },
{ endpoint: "/get/data/auto_speaker_select", ns: configs, hook_name: "useEnableAutoSpeakerSelect", method_name: "updateEnableAutoSpeakerSelect" }, { endpoint: "/get/data/auto_speaker_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoSpeakerSelect" },
{ endpoint: "/set/enable/auto_speaker_select", ns: configs, hook_name: "useEnableAutoSpeakerSelect", method_name: "updateEnableAutoSpeakerSelect" }, { endpoint: "/set/enable/auto_speaker_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoSpeakerSelect" },
{ endpoint: "/set/disable/auto_speaker_select", ns: configs, hook_name: "useEnableAutoSpeakerSelect", method_name: "updateEnableAutoSpeakerSelect" }, { endpoint: "/set/disable/auto_speaker_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoSpeakerSelect" },
// Device (Mic) // Device (Mic)
{ endpoint: "/get/data/mic_host_list", ns: configs, hook_name: "useMicHostList", method_name: "updateMicHostList_FromBackend" }, { endpoint: "/get/data/mic_host_list", ns: configs, hook_name: "useDevice", method_name: "updateMicHostList_FromBackend" },
{ endpoint: "/run/mic_host_list", ns: configs, hook_name: "useMicHostList", method_name: "updateMicHostList_FromBackend" }, { endpoint: "/run/mic_host_list", ns: configs, hook_name: "useDevice", method_name: "updateMicHostList_FromBackend" },
{ endpoint: "/get/data/selected_mic_host", ns: configs, hook_name: "useSelectedMicHost", method_name: "updateSelectedMicHost" }, { endpoint: "/get/data/selected_mic_host", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicHost" },
{ endpoint: "/set/data/selected_mic_host", ns: configs, hook_name: "useSelectedMicHost", method_name: "updateSelectedMicHostAndDevice" }, // Need refactoring (Duplicated, Host, Device) { endpoint: "/set/data/selected_mic_host", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicHostAndDevice" },
{ endpoint: "/get/data/mic_device_list", ns: configs, hook_name: "useMicDeviceList", method_name: "updateMicDeviceList_FromBackend" }, { endpoint: "/get/data/mic_device_list", ns: configs, hook_name: "useDevice", method_name: "updateMicDeviceList_FromBackend" },
{ endpoint: "/run/mic_device_list", ns: configs, hook_name: "useMicDeviceList", method_name: "updateMicDeviceList_FromBackend" }, { endpoint: "/run/mic_device_list", ns: configs, hook_name: "useDevice", method_name: "updateMicDeviceList_FromBackend" },
{ endpoint: "/get/data/selected_mic_device", ns: configs, hook_name: "useSelectedMicDevice", method_name: "updateSelectedMicDevice" }, { endpoint: "/get/data/selected_mic_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicDevice" },
{ endpoint: "/set/data/selected_mic_device", ns: configs, hook_name: "useSelectedMicDevice", method_name: "updateSelectedMicDevice" }, { endpoint: "/set/data/selected_mic_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicDevice" },
{ endpoint: "/run/selected_mic_device", ns: configs, hook_name: "useSelectedMicHost", method_name: "updateSelectedMicHostAndDevice" }, // Need refactoring (Duplicated, Host, Device) { endpoint: "/run/selected_mic_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicHostAndDevice" },
// Device (Speaker) // Device (Speaker)
{ endpoint: "/get/data/speaker_device_list", ns: configs, hook_name: "useSpeakerDeviceList", method_name: "updateSpeakerDeviceList_FromBackend" }, { endpoint: "/get/data/speaker_device_list", ns: configs, hook_name: "useDevice", method_name: "updateSpeakerDeviceList_FromBackend" },
{ endpoint: "/run/speaker_device_list", ns: configs, hook_name: "useSpeakerDeviceList", method_name: "updateSpeakerDeviceList_FromBackend" }, { endpoint: "/run/speaker_device_list", ns: configs, hook_name: "useDevice", method_name: "updateSpeakerDeviceList_FromBackend" },
{ endpoint: "/get/data/selected_speaker_device", ns: configs, hook_name: "useSelectedSpeakerDevice", method_name: "updateSelectedSpeakerDevice" }, { endpoint: "/get/data/selected_speaker_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedSpeakerDevice" },
{ endpoint: "/set/data/selected_speaker_device", ns: configs, hook_name: "useSelectedSpeakerDevice", method_name: "updateSelectedSpeakerDevice" }, { endpoint: "/set/data/selected_speaker_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedSpeakerDevice" },
{ endpoint: "/run/selected_speaker_device", ns: configs, hook_name: "useSelectedSpeakerDevice", method_name: "updateSelectedSpeakerDevice" }, { endpoint: "/run/selected_speaker_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedSpeakerDevice" },
// Device (Threshold) // Device (Threshold)
{ endpoint: "/get/data/mic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateMicThreshold" }, { endpoint: "/get/data/mic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateMicThreshold" },
{ endpoint: "/set/data/mic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateMicThreshold" }, { endpoint: "/set/data/mic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateMicThreshold" },
{ endpoint: "/get/data/speaker_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateSpeakerThreshold" }, { endpoint: "/get/data/speaker_threshold", ns: configs, hook_name: "useDevice", method_name: "updateSpeakerThreshold" },
{ endpoint: "/set/data/speaker_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateSpeakerThreshold" }, { endpoint: "/set/data/speaker_threshold", ns: configs, hook_name: "useDevice", method_name: "updateSpeakerThreshold" },
{ endpoint: "/get/data/mic_automatic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateEnableAutomaticMicThreshold" }, { endpoint: "/get/data/mic_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticMicThreshold" },
{ endpoint: "/set/enable/mic_automatic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateEnableAutomaticMicThreshold" }, { endpoint: "/set/enable/mic_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticMicThreshold" },
{ endpoint: "/set/disable/mic_automatic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateEnableAutomaticMicThreshold" }, { endpoint: "/set/disable/mic_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticMicThreshold" },
{ endpoint: "/get/data/speaker_automatic_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateEnableAutomaticSpeakerThreshold" }, { endpoint: "/get/data/speaker_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticSpeakerThreshold" },
{ endpoint: "/set/enable/speaker_automatic_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateEnableAutomaticSpeakerThreshold" }, { endpoint: "/set/enable/speaker_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticSpeakerThreshold" },
{ endpoint: "/set/disable/speaker_automatic_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateEnableAutomaticSpeakerThreshold" }, { endpoint: "/set/disable/speaker_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticSpeakerThreshold" },
// Appearance // Appearance