diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx index 018f3845..e9fb29fb 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx @@ -7,8 +7,7 @@ import { useVolume } from "@logics_common"; import MicSvg from "@images/mic.svg?react"; import HeadphonesSvg from "@images/headphones.svg?react"; import { - useMicThreshold, - useSpeakerThreshold, + useDevice, } from "@logics_configs"; export const ThresholdComponent = (props) => { @@ -27,7 +26,7 @@ const MicComponent = (props) => { currentMicThreshold, setMicThreshold, currentEnableAutomaticMicThreshold, - } = useMicThreshold(); + } = useDevice(); const [ui_threshold, setUiThreshold] = useState(currentMicThreshold.data); const { volumeCheckStart_Mic, @@ -84,7 +83,7 @@ const SpeakerComponent = (props) => { currentSpeakerThreshold, setSpeakerThreshold, currentEnableAutomaticSpeakerThreshold, - } = useSpeakerThreshold(); + } = useDevice(); const [ui_threshold, setUiThreshold] = useState(currentSpeakerThreshold.data); const { volumeCheckStart_Speaker, diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx index 8c67637c..475f2410 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx @@ -4,8 +4,7 @@ import { useStore_SpeakerVolume, } from "@store"; import { - useMicThreshold, - useSpeakerThreshold, + useDevice, } from "@logics_configs"; export const SliderAndMeter = (props) => { @@ -24,7 +23,7 @@ export const SliderAndMeter = (props) => { const ThresholdVolumeMeter_Mic = (props) => { const { currentMicVolume } = useStore_MicVolume(); - const { currentEnableAutomaticMicThreshold } = useMicThreshold(); + const { currentEnableAutomaticMicThreshold } = useDevice(); const currentVolumeVariable = Math.min(currentMicVolume.data, props.max); const volume_width_percentage = (currentVolumeVariable / props.max) * 100; @@ -50,7 +49,7 @@ const ThresholdVolumeMeter_Mic = (props) => { const ThresholdVolumeMeter_Speaker = (props) => { const { currentSpeakerVolume } = useStore_SpeakerVolume(); - const { currentEnableAutomaticSpeakerThreshold } = useSpeakerThreshold(); + const { currentEnableAutomaticSpeakerThreshold } = useDevice(); const currentVolumeVariable = Math.min(currentSpeakerVolume.data, props.max); const volume_width_percentage = (currentVolumeVariable / props.max) * 100; diff --git a/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx b/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx index 56b11398..d3f20645 100644 --- a/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx @@ -4,16 +4,7 @@ import clsx from "clsx"; import { useStore_IsBreakPoint } from "@store"; import { ui_configs } from "@ui_configs"; import { - useEnableAutoMicSelect, - useMicHostList, - useSelectedMicHost, - useMicDeviceList, - useSelectedMicDevice, - useMicThreshold, - useEnableAutoSpeakerSelect, - useSpeakerDeviceList, - useSelectedSpeakerDevice, - useSpeakerThreshold, + useDevice, } from "@logics_configs"; import { @@ -38,13 +29,21 @@ export const Device = () => { const Mic_Container = () => { const { t } = useTranslation(); - const { currentEnableAutoMicSelect, toggleEnableAutoMicSelect } = useEnableAutoMicSelect(); - const { currentSelectedMicHost, setSelectedMicHost } = useSelectedMicHost(); - const { currentMicHostList } = useMicHostList(); - const { currentSelectedMicDevice, setSelectedMicDevice } = useSelectedMicDevice(); - const { currentMicDeviceList } = useMicDeviceList(); + const { + currentEnableAutoMicSelect, + toggleEnableAutoMicSelect, + currentMicDeviceList, + currentMicHostList, + + currentSelectedMicHost, + setSelectedMicHost, + currentSelectedMicDevice, + setSelectedMicDevice, + + currentEnableAutomaticMicThreshold, + toggleEnableAutomaticMicThreshold, + } = useDevice(); const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu(); - const { currentEnableAutomaticMicThreshold, toggleEnableAutomaticMicThreshold } = useMicThreshold(); const selectFunction_host = (selected_data) => { setSelectedMicHost(selected_data.selected_id); @@ -139,11 +138,16 @@ const Mic_Container = () => { const Speaker_Container = () => { const { t } = useTranslation(); - const { currentEnableAutoSpeakerSelect, toggleEnableAutoSpeakerSelect } = useEnableAutoSpeakerSelect(); - const { currentSelectedSpeakerDevice, setSelectedSpeakerDevice } = useSelectedSpeakerDevice(); - const { currentSpeakerDeviceList } = useSpeakerDeviceList(); + const { + currentEnableAutoSpeakerSelect, + toggleEnableAutoSpeakerSelect, + currentSpeakerDeviceList, + currentSelectedSpeakerDevice, + setSelectedSpeakerDevice, + currentEnableAutomaticSpeakerThreshold, + toggleEnableAutomaticSpeakerThreshold, + } = useDevice(); const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu(); - const { currentEnableAutomaticSpeakerThreshold, toggleEnableAutomaticSpeakerThreshold } = useSpeakerThreshold(); const selectFunction = (selected_data) => { setSelectedSpeakerDevice(selected_data.selected_id); diff --git a/src-ui/logics/configs/device/useDevice.js b/src-ui/logics/configs/device/useDevice.js new file mode 100644 index 00000000..25a05f1c --- /dev/null +++ b/src-ui/logics/configs/device/useDevice.js @@ -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, + + + }; +}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useEnableAutoMicSelect.js b/src-ui/logics/configs/device/useEnableAutoMicSelect.js deleted file mode 100644 index c9f7e5d6..00000000 --- a/src-ui/logics/configs/device/useEnableAutoMicSelect.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useEnableAutoSpeakerSelect.js b/src-ui/logics/configs/device/useEnableAutoSpeakerSelect.js deleted file mode 100644 index 406cbf25..00000000 --- a/src-ui/logics/configs/device/useEnableAutoSpeakerSelect.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useMicDeviceList.js b/src-ui/logics/configs/device/useMicDeviceList.js deleted file mode 100644 index d145a890..00000000 --- a/src-ui/logics/configs/device/useMicDeviceList.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useMicHostList.js b/src-ui/logics/configs/device/useMicHostList.js deleted file mode 100644 index 898f348c..00000000 --- a/src-ui/logics/configs/device/useMicHostList.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useMicThreshold.js b/src-ui/logics/configs/device/useMicThreshold.js deleted file mode 100644 index a6224c38..00000000 --- a/src-ui/logics/configs/device/useMicThreshold.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSelectedMicDevice.js b/src-ui/logics/configs/device/useSelectedMicDevice.js deleted file mode 100644 index 6bd7d11a..00000000 --- a/src-ui/logics/configs/device/useSelectedMicDevice.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSelectedMicHost.js b/src-ui/logics/configs/device/useSelectedMicHost.js deleted file mode 100644 index 0197cfc8..00000000 --- a/src-ui/logics/configs/device/useSelectedMicHost.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSelectedSpeakerDevice.js b/src-ui/logics/configs/device/useSelectedSpeakerDevice.js deleted file mode 100644 index 672a9267..00000000 --- a/src-ui/logics/configs/device/useSelectedSpeakerDevice.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSpeakerDeviceList.js b/src-ui/logics/configs/device/useSpeakerDeviceList.js deleted file mode 100644 index b88ed285..00000000 --- a/src-ui/logics/configs/device/useSpeakerDeviceList.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSpeakerThreshold.js b/src-ui/logics/configs/device/useSpeakerThreshold.js deleted file mode 100644 index c21fe2ef..00000000 --- a/src-ui/logics/configs/device/useSpeakerThreshold.js +++ /dev/null @@ -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, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/index.js b/src-ui/logics/configs/index.js index 03214771..aadb1519 100644 --- a/src-ui/logics/configs/index.js +++ b/src-ui/logics/configs/index.js @@ -1,13 +1,4 @@ -export { useEnableAutoMicSelect } from "./device/useEnableAutoMicSelect"; -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 { useDevice } from "./device/useDevice"; export { useMessageLogUiScaling } from "./appearance/useMessageLogUiScaling"; export { useSelectedFontFamily } from "./appearance/useSelectedFontFamily"; diff --git a/src-ui/logics/useReceiveRoutes.js b/src-ui/logics/useReceiveRoutes.js index 54f49203..8961c2cf 100644 --- a/src-ui/logics/useReceiveRoutes.js +++ b/src-ui/logics/useReceiveRoutes.js @@ -91,49 +91,49 @@ export const ROUTE_META_LIST = [ // Config Page // Device - { endpoint: "/get/data/auto_mic_select", ns: configs, hook_name: "useEnableAutoMicSelect", method_name: "updateEnableAutoMicSelect" }, - { endpoint: "/set/enable/auto_mic_select", ns: configs, hook_name: "useEnableAutoMicSelect", method_name: "updateEnableAutoMicSelect" }, - { endpoint: "/set/disable/auto_mic_select", ns: configs, hook_name: "useEnableAutoMicSelect", method_name: "updateEnableAutoMicSelect" }, - { endpoint: "/get/data/auto_speaker_select", ns: configs, hook_name: "useEnableAutoSpeakerSelect", method_name: "updateEnableAutoSpeakerSelect" }, - { endpoint: "/set/enable/auto_speaker_select", ns: configs, hook_name: "useEnableAutoSpeakerSelect", method_name: "updateEnableAutoSpeakerSelect" }, - { endpoint: "/set/disable/auto_speaker_select", ns: configs, hook_name: "useEnableAutoSpeakerSelect", method_name: "updateEnableAutoSpeakerSelect" }, + { endpoint: "/get/data/auto_mic_select", ns: configs, hook_name: "useDevice", 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: "useDevice", method_name: "updateEnableAutoMicSelect" }, + { endpoint: "/get/data/auto_speaker_select", ns: configs, hook_name: "useDevice", 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: "useDevice", method_name: "updateEnableAutoSpeakerSelect" }, // Device (Mic) - { endpoint: "/get/data/mic_host_list", ns: configs, hook_name: "useMicHostList", method_name: "updateMicHostList_FromBackend" }, - { endpoint: "/run/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: "useDevice", method_name: "updateMicHostList_FromBackend" }, - { endpoint: "/get/data/selected_mic_host", ns: configs, hook_name: "useSelectedMicHost", method_name: "updateSelectedMicHost" }, - { endpoint: "/set/data/selected_mic_host", ns: configs, hook_name: "useSelectedMicHost", method_name: "updateSelectedMicHostAndDevice" }, // Need refactoring (Duplicated, Host, Device) + { endpoint: "/get/data/selected_mic_host", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicHost" }, + { 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: "/run/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: "useDevice", method_name: "updateMicDeviceList_FromBackend" }, - { endpoint: "/get/data/selected_mic_device", ns: configs, hook_name: "useSelectedMicDevice", method_name: "updateSelectedMicDevice" }, - { endpoint: "/set/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: "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) - { endpoint: "/get/data/speaker_device_list", ns: configs, hook_name: "useSpeakerDeviceList", method_name: "updateSpeakerDeviceList_FromBackend" }, - { endpoint: "/run/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: "useDevice", method_name: "updateSpeakerDeviceList_FromBackend" }, - { endpoint: "/get/data/selected_speaker_device", ns: configs, hook_name: "useSelectedSpeakerDevice", method_name: "updateSelectedSpeakerDevice" }, - { endpoint: "/set/data/selected_speaker_device", ns: configs, hook_name: "useSelectedSpeakerDevice", method_name: "updateSelectedSpeakerDevice" }, - { endpoint: "/run/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: "useDevice", method_name: "updateSelectedSpeakerDevice" }, + { endpoint: "/run/selected_speaker_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedSpeakerDevice" }, // Device (Threshold) - { endpoint: "/get/data/mic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateMicThreshold" }, - { endpoint: "/set/data/mic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateMicThreshold" }, - { endpoint: "/get/data/speaker_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateSpeakerThreshold" }, - { endpoint: "/set/data/speaker_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateSpeakerThreshold" }, + { endpoint: "/get/data/mic_threshold", ns: configs, hook_name: "useDevice", 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: "useDevice", 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: "/set/enable/mic_automatic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateEnableAutomaticMicThreshold" }, - { endpoint: "/set/disable/mic_automatic_threshold", ns: configs, hook_name: "useMicThreshold", method_name: "updateEnableAutomaticMicThreshold" }, - { endpoint: "/get/data/speaker_automatic_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateEnableAutomaticSpeakerThreshold" }, - { endpoint: "/set/enable/speaker_automatic_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateEnableAutomaticSpeakerThreshold" }, - { endpoint: "/set/disable/speaker_automatic_threshold", ns: configs, hook_name: "useSpeakerThreshold", method_name: "updateEnableAutomaticSpeakerThreshold" }, + { endpoint: "/get/data/mic_automatic_threshold", ns: configs, hook_name: "useDevice", 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: "useDevice", method_name: "updateEnableAutomaticMicThreshold" }, + { endpoint: "/get/data/speaker_automatic_threshold", ns: configs, hook_name: "useDevice", 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: "useDevice", method_name: "updateEnableAutomaticSpeakerThreshold" }, // Appearance