From c32a186e8846ba42ae5612620eb31df9be21e937 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Fri, 27 Sep 2024 13:13:33 +0900 Subject: [PATCH] =?UTF-8?q?[Update]=20=E8=A8=AD=E5=AE=9A=E3=83=9A=E3=83=BC?= =?UTF-8?q?=E3=82=B8=E9=96=8B=E9=96=89=E6=99=82=E3=81=AB=E3=80=81=E9=9F=B3?= =?UTF-8?q?=E5=A3=B0=E8=AA=8D=E8=AD=98=E3=82=AA=E3=83=B3=E3=82=AA=E3=83=95?= =?UTF-8?q?=E7=8A=B6=E6=85=8B=E3=81=AE=E5=BE=A9=E5=85=83=E3=82=92=E5=AE=9F?= =?UTF-8?q?=E8=A3=85=E3=80=82=20=E2=80=BB=E4=BB=8A=E3=81=BE=E3=81=A7?= =?UTF-8?q?=E3=81=AFBackend=E3=81=A7=E7=8A=B6=E6=85=8B=E5=BE=A9=E5=85=83?= =?UTF-8?q?=E3=82=92=E3=81=97=E3=81=A6=E3=81=84=E3=81=9F=E3=81=8C=E3=80=81?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=81=8C=E3=81=82=E3=82=8C=E3=81=AA=E3=81=AE?= =?UTF-8?q?=E3=81=A7UI=E5=81=B4=E3=81=A7=E3=81=AE=E4=BE=BF=E5=88=A9?= =?UTF-8?q?=E6=A9=9F=E8=83=BD=E3=81=A8=E3=81=97=E3=81=A6UI=E3=81=8C?= =?UTF-8?q?=E7=AE=A1=E7=90=86=E3=81=99=E3=82=8B=E3=81=93=E3=81=A8=E3=81=AB?= =?UTF-8?q?=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-ui/app/App.jsx | 35 +++++++++++++++-- src-ui/app/config_page/topbar/Topbar.jsx | 6 +-- src-ui/app/main_page/MainPage.jsx | 4 +- .../open_settings/OpenSettings.jsx | 6 +-- src-ui/logics/common/useIsOpenedConfigPage.js | 22 +++++++++++ src-ui/logics/main/useMainFunction.js | 39 +++++++++++-------- src-ui/store.js | 15 ++++--- 7 files changed, 94 insertions(+), 33 deletions(-) create mode 100644 src-ui/logics/common/useIsOpenedConfigPage.js diff --git a/src-ui/app/App.jsx b/src-ui/app/App.jsx index a420562e..43be2060 100644 --- a/src-ui/app/App.jsx +++ b/src-ui/app/App.jsx @@ -134,10 +134,19 @@ const UiLanguageController = () => { return null; }; +import { useStore_MainFunctionsStateMemory } from "@store"; import { useVolume } from "@logics_common/useVolume"; -import { useStore_IsOpenedConfigPage } from "@store"; +import { useIsOpenedConfigPage } from "@logics_common/useIsOpenedConfigPage"; +import { useMainFunction } from "@logics_main/useMainFunction"; const ConfigPageCloseTrigger = () => { - const { currentIsOpenedConfigPage } = useStore_IsOpenedConfigPage(); + const { currentIsOpenedConfigPage } = useIsOpenedConfigPage(); + const { currentMainFunctionsStateMemory, updateMainFunctionsStateMemory} = useStore_MainFunctionsStateMemory(); + const { + currentTranscriptionSendStatus, + setTranscriptionSend, + currentTranscriptionReceiveStatus, + setTranscriptionReceive, + } = useMainFunction(); const { currentMicThresholdCheckStatus, volumeCheckStop_Mic, @@ -145,12 +154,30 @@ const ConfigPageCloseTrigger = () => { volumeCheckStop_Speaker, } = useVolume(); + + const memorizeLatestMainFunctionsState = () => { + updateMainFunctionsStateMemory({ + transcription_send: currentTranscriptionSendStatus.data, + transcription_receive: currentTranscriptionReceiveStatus.data, + }); + }; + + const restoreMainFunctionState = () => { + if (currentMainFunctionsStateMemory.data.transcription_send === true) setTranscriptionSend(true); + if (currentMainFunctionsStateMemory.data.transcription_receive === true) setTranscriptionReceive(true); + }; + useEffect(() => { - if (currentIsOpenedConfigPage.data === false) { + if (currentIsOpenedConfigPage.data === true) { // When config page is opened. + memorizeLatestMainFunctionsState(); + if (currentTranscriptionSendStatus.data === true) setTranscriptionSend(false); + if (currentTranscriptionReceiveStatus.data === true) setTranscriptionReceive(false); + } else if (currentIsOpenedConfigPage.data === false) { // When config page is closed. if (currentMicThresholdCheckStatus.data === true) volumeCheckStop_Mic(); if (currentSpeakerThresholdCheckStatus.data === true) volumeCheckStop_Speaker(); + restoreMainFunctionState(); } - }, [currentIsOpenedConfigPage]); + }, [currentIsOpenedConfigPage.data]); return null; }; diff --git a/src-ui/app/config_page/topbar/Topbar.jsx b/src-ui/app/config_page/topbar/Topbar.jsx index 33402588..cd1284d8 100644 --- a/src-ui/app/config_page/topbar/Topbar.jsx +++ b/src-ui/app/config_page/topbar/Topbar.jsx @@ -1,7 +1,7 @@ import clsx from "clsx"; import styles from "./Topbar.module.scss"; -import { useStore_IsOpenedConfigPage } from "@store"; +import { useIsOpenedConfigPage } from "@logics_common/useIsOpenedConfigPage"; import ArrowLeftSvg from "@images/arrow_left.svg?react"; import { TitleBox } from "./title_box/TitleBox"; @@ -9,9 +9,9 @@ import { SectionTitleBox } from "./section_title_box/SectionTitleBox"; import { CompactSwitchBox } from "./compact_switch_box/CompactSwitchBox"; export const Topbar = () => { - const { currentIsOpenedConfigPage, updateIsOpenedConfigPage } = useStore_IsOpenedConfigPage(); + const { currentIsOpenedConfigPage, setIsOpenedConfigPage } = useIsOpenedConfigPage(); const closeConfigPage = () => { - updateIsOpenedConfigPage(false); + setIsOpenedConfigPage(false); }; return ( diff --git a/src-ui/app/main_page/MainPage.jsx b/src-ui/app/main_page/MainPage.jsx index 2a563fd6..58850e55 100644 --- a/src-ui/app/main_page/MainPage.jsx +++ b/src-ui/app/main_page/MainPage.jsx @@ -2,10 +2,10 @@ import clsx from "clsx"; import styles from "./MainPage.module.scss"; import { SidebarSection } from "./sidebar_section/SidebarSection"; import { MainSection } from "./main_section/MainSection"; -import { useStore_IsOpenedConfigPage } from "@store"; +import { useIsOpenedConfigPage } from "@logics_common/useIsOpenedConfigPage"; export const MainPage = () => { - const { currentIsOpenedConfigPage } = useStore_IsOpenedConfigPage(); + const { currentIsOpenedConfigPage } = useIsOpenedConfigPage(); return (
{ - const { updateIsOpenedConfigPage } = useStore_IsOpenedConfigPage(); + const { setIsOpenedConfigPage } = useIsOpenedConfigPage(); const openConfigPage = () => { - updateIsOpenedConfigPage(true); + setIsOpenedConfigPage(true); }; return ( diff --git a/src-ui/logics/common/useIsOpenedConfigPage.js b/src-ui/logics/common/useIsOpenedConfigPage.js new file mode 100644 index 00000000..08e1e833 --- /dev/null +++ b/src-ui/logics/common/useIsOpenedConfigPage.js @@ -0,0 +1,22 @@ +import { useStore_IsOpenedConfigPage } from "@store"; +import { useStdoutToPython } from "@logics/useStdoutToPython"; + +export const useIsOpenedConfigPage = () => { + const { asyncStdoutToPython } = useStdoutToPython(); + const { currentIsOpenedConfigPage, updateIsOpenedConfigPage } = useStore_IsOpenedConfigPage(); + + const setIsOpenedConfigPage = (is_opened) => { + updateIsOpenedConfigPage(is_opened); + // if (is_opened) { + // asyncStdoutToPython("/set/enable/config_window"); + // } else { + // asyncStdoutToPython("/set/disable/config_window"); + // } + }; + + return { + currentIsOpenedConfigPage, + setIsOpenedConfigPage, + updateIsOpenedConfigPage, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/main/useMainFunction.js b/src-ui/logics/main/useMainFunction.js index 4135c82b..14b1e923 100644 --- a/src-ui/logics/main/useMainFunction.js +++ b/src-ui/logics/main/useMainFunction.js @@ -32,32 +32,36 @@ export const useMainFunction = () => { const { asyncStdoutToPython } = useStdoutToPython(); - const toggleTranslation = () => { + const setTranslation = (to_enable) => { pendingTranslationStatus(); - if (currentTranslationStatus.data) { - asyncStdoutToPython("/set/disable/translation"); - } else { + if (to_enable) { asyncStdoutToPython("/set/enable/translation"); + } else { + asyncStdoutToPython("/set/disable/translation"); } }; + const toggleTranslation = () => setTranslation(!currentTranslationStatus.data); - const toggleTranscriptionSend = () => { + const setTranscriptionSend = (to_enable) => { pendingTranscriptionSendStatus(); - if (currentTranscriptionSendStatus.data) { - asyncStdoutToPython("/set/disable/transcription_send"); - } else { + if (to_enable) { asyncStdoutToPython("/set/enable/transcription_send"); - } - }; - - const toggleTranscriptionReceive = () => { - pendingTranscriptionReceiveStatus(); - if (currentTranscriptionReceiveStatus.data) { - asyncStdoutToPython("/set/disable/transcription_receive"); } else { - asyncStdoutToPython("/set/enable/transcription_receive"); + asyncStdoutToPython("/set/disable/transcription_send"); } }; + const toggleTranscriptionSend = () => setTranscriptionSend(!currentTranscriptionSendStatus.data); + + const setTranscriptionReceive = (to_enable) => { + pendingTranscriptionReceiveStatus(); + if (to_enable) { + asyncStdoutToPython("/set/enable/transcription_receive"); + } else { + asyncStdoutToPython("/set/disable/transcription_receive"); + } + }; + const toggleTranscriptionReceive = () => setTranscriptionReceive(!currentTranscriptionReceiveStatus.data); + const toggleForeground = () => { const main_page = getCurrent(); @@ -70,14 +74,17 @@ export const useMainFunction = () => { currentTranslationStatus, toggleTranslation, updateTranslationStatus, + setTranslation, currentTranscriptionSendStatus, toggleTranscriptionSend, updateTranscriptionSendStatus, + setTranscriptionSend, currentTranscriptionReceiveStatus, toggleTranscriptionReceive, updateTranscriptionReceiveStatus, + setTranscriptionReceive, currentForegroundStatus, toggleForeground, diff --git a/src-ui/store.js b/src-ui/store.js index 28297dfa..2bb8531d 100644 --- a/src-ui/store.js +++ b/src-ui/store.js @@ -98,8 +98,12 @@ const createAtomWithHook = (initialValue, base_name, options) => { }; - -export const { atomInstance: Atom_SoftwareVersion, useHook: useStore_SoftwareVersion } = createAtomWithHook("-", "SoftwareVersion"); +// Common +export const { atomInstance: Atom_IsOpenedConfigPage, useHook: useStore_IsOpenedConfigPage } = createAtomWithHook(false, "IsOpenedConfigPage"); +export const { atomInstance: Atom_MainFunctionsStateMemory, useHook: useStore_MainFunctionsStateMemory } = createAtomWithHook({ + transcription_send: false, + transcription_receive: false, +}, "MainFunctionsStateMemory"); // Main Page // Functions @@ -122,9 +126,6 @@ export const { atomInstance: Atom_TranslationEngines, useHook: useStore_Translat export const { atomInstance: Atom_SelectedTranslationEngines, useHook: useStore_SelectedTranslationEngines } = createAtomWithHook({}, "SelectedTranslationEngines"); -export const { atomInstance: Atom_IsOpenedConfigPage, useHook: useStore_IsOpenedConfigPage } = createAtomWithHook(false, "IsOpenedConfigPage"); -export const { atomInstance: Atom_SelectedConfigTabId, useHook: useStore_SelectedConfigTabId } = createAtomWithHook("device", "SelectedConfigTabId"); - // Designs export const { atomInstance: Atom_IsMainPageCompactMode, useHook: useStore_IsMainPageCompactMode } = createAtomWithHook(false, "IsMainPageCompactMode"); export const { atomInstance: Atom_MessageInputBoxRatio, useHook: useStore_MessageInputBoxRatio } = createAtomWithHook(20, "MessageInputBoxRatio"); @@ -135,6 +136,10 @@ export const { atomInstance: Atom_IsOpenedLanguageSelector, useHook: useStore_Is // Config Page +// Common +export const { atomInstance: Atom_SoftwareVersion, useHook: useStore_SoftwareVersion } = createAtomWithHook("-", "SoftwareVersion"); +export const { atomInstance: Atom_SelectedConfigTabId, useHook: useStore_SelectedConfigTabId } = createAtomWithHook("device", "SelectedConfigTabId"); + // Designs export const { atomInstance: Atom_IsOpenedDropdownMenu, useHook: useStore_IsOpenedDropdownMenu } = createAtomWithHook("", "IsOpenedDropdownMenu");