From 1042c5e2b9059a089bdd4c1d57236b6a1ddf18bc Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Tue, 27 Aug 2024 11:06:10 +0900 Subject: [PATCH] [Refactor] Logic: Move object structure creation to the parent file. --- src-ui/logics/useConfig.js | 2 +- src-ui/logics/useMainFunction.js | 30 +++++++++++++++--------------- src-ui/logics/useStdoutToPython.js | 7 +++++-- 3 files changed, 21 insertions(+), 18 deletions(-) diff --git a/src-ui/logics/useConfig.js b/src-ui/logics/useConfig.js index 49108d65..43ad4aea 100644 --- a/src-ui/logics/useConfig.js +++ b/src-ui/logics/useConfig.js @@ -13,7 +13,7 @@ export const useConfig = () => { return { getSoftwareVersion: () => { - asyncStdoutToPython({endpoint: "/config/version"}); + asyncStdoutToPython("/config/version"); }, updateSoftwareVersion: (payload) => { updateSoftwareVersion(payload.data); diff --git a/src-ui/logics/useMainFunction.js b/src-ui/logics/useMainFunction.js index f34ebd3a..cae1c4e6 100644 --- a/src-ui/logics/useMainFunction.js +++ b/src-ui/logics/useMainFunction.js @@ -35,12 +35,12 @@ export const useMainFunction = () => { const asyncPending = () => new Promise(() => {}); return { toggleTranslation: () => { - if (currentTranslationStatus.data) { - asyncStdoutToPython({endpoint: "/controller/callback_disable_translation"}); - } else { - asyncStdoutToPython({endpoint: "/controller/callback_enable_translation"}); - } asyncUpdateTranslationStatus(asyncPending); + if (currentTranslationStatus.data) { + asyncStdoutToPython("/controller/callback_disable_translation"); + } else { + asyncStdoutToPython("/controller/callback_enable_translation"); + } }, currentTranslationStatus: currentTranslationStatus, updateTranslationStatus: (payload) => { @@ -48,12 +48,12 @@ export const useMainFunction = () => { }, toggleTranscriptionSend: () => { - if (currentTranscriptionSendStatus.data) { - asyncStdoutToPython({endpoint: "/controller/callback_disable_transcription_send"}); - } else { - asyncStdoutToPython({endpoint: "/controller/callback_enable_transcription_send"}); - } asyncUpdateTranscriptionSendStatus(asyncPending); + if (currentTranscriptionSendStatus.data) { + asyncStdoutToPython("/controller/callback_disable_transcription_send"); + } else { + asyncStdoutToPython("/controller/callback_enable_transcription_send"); + } }, currentTranscriptionSendStatus: currentTranscriptionSendStatus, updateTranscriptionSendStatus: (payload) => { @@ -61,12 +61,12 @@ export const useMainFunction = () => { }, toggleTranscriptionReceive: () => { - if (currentTranscriptionReceiveStatus.data) { - asyncStdoutToPython({endpoint: "/controller/callback_disable_transcription_receive"}); - } else { - asyncStdoutToPython({endpoint: "/controller/callback_enable_transcription_receive"}); - } asyncUpdateTranscriptionReceiveStatus(asyncPending); + if (currentTranscriptionReceiveStatus.data) { + asyncStdoutToPython("/controller/callback_disable_transcription_receive"); + } else { + asyncStdoutToPython("/controller/callback_enable_transcription_receive"); + } }, currentTranscriptionReceiveStatus: currentTranscriptionReceiveStatus, updateTranscriptionReceiveStatus: (payload) => { diff --git a/src-ui/logics/useStdoutToPython.js b/src-ui/logics/useStdoutToPython.js index a631545d..cde6c121 100644 --- a/src-ui/logics/useStdoutToPython.js +++ b/src-ui/logics/useStdoutToPython.js @@ -1,11 +1,14 @@ import { store } from "@store"; export const useStdoutToPython = () => { - const asyncStdoutToPython = async (value) => { + const asyncStdoutToPython = async (path, value) => { + let send_object = { endpoint: path }; + if (value) send_object.data = value; + // send to python const backend_subprocess = store.backend_subprocess; if (backend_subprocess) { - await backend_subprocess.write(JSON.stringify(value) + "\n").then(() => { + await backend_subprocess.write(JSON.stringify(send_object) + "\n").then(() => { }).catch((err) => { console.log(err); });