diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index a008b18d..6d95a930 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -5,11 +5,17 @@ from subprocess import Popen from threading import Thread from config import config from model import model -# from view import view -from utils import getKeyByValue, isUniqueStrings, strPctToInt -import argparse +from utils import getKeyByValue, isUniqueStrings # Common +def encodeUtf8(data:str) -> dict: + data = {i: byte for i, byte in enumerate(data.encode('UTF-8'))} + return data + +def decodeUtf8(data:dict) -> str: + data = bytes(data.values()).decode("UTF-8") + return data + class DownloadSoftwareProgressBar: def __init__(self, action): self.action = action @@ -305,7 +311,7 @@ class ChatMessage: def send(self, data): id = data["id"] - message = data["message"] + message = decodeUtf8(data["message"]) if len(message) > 0: addSentMessageLog(message) translation = "" @@ -345,6 +351,8 @@ class ChatMessage: translation = f" ({translation})" model.logger.info(f"[SENT] {message}{translation}") + message = encodeUtf8(message) + translation = encodeUtf8(translation) return {"status":200, "result":{ "id":id, @@ -1364,4 +1372,5 @@ def init(endpoints:dict, *args, **kwargs) -> None: print(json.dumps({"status":348, "log": "Init OSC Receive"}), flush=True) model.startReceiveOSC() if config.ENABLE_VRC_MIC_MUTE_SYNC is True: - model.startCheckMuteSelfStatus() \ No newline at end of file + model.startCheckMuteSelfStatus() + print(json.dumps({"status":348, "log": "End Initialization"}), flush=True) \ No newline at end of file diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index a6d73a19..b9790f10 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -326,13 +326,10 @@ def main(): print(response, flush=True) if __name__ == "__main__": - print(json.dumps({"status":200, "endpoint": "/initialization/start", "result":True}), flush=True) controller.init({ "ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"], "whisper": action_mapping["/controller/callback_download_whisper_weight"]["download"], }) - print(json.dumps({"status":200, "endpoint": "/initialization/completed", "result":True}), flush=True) - print(json.dumps({"status":348, "log": "Initialization from Python."}), flush=True) process = "main" match process: diff --git a/src-ui/logics/useMessage.js b/src-ui/logics/useMessage.js index 5318a896..296bd1ed 100644 --- a/src-ui/logics/useMessage.js +++ b/src-ui/logics/useMessage.js @@ -7,13 +7,14 @@ import { useStdoutToPython } from "./useStdoutToPython"; export const useMessage = () => { const { currentMessageLogsStatus, addMessageLogsStatus, updateMessageLogsStatus } = useMessageLogsStatus(); const { asyncStdoutToPython } = useStdoutToPython(); + const encoder = new TextEncoder(); return { sendMessage: (message) => { const uuid = crypto.randomUUID(); const send_message_object = { id: uuid, - message: message, + message: encoder.encode(message), }; asyncStdoutToPython("/controller/callback_messagebox_press_key_enter", send_message_object);