🚧[WIP/TEST] Controller : stdioでのtauriとpythonの通信をutf8でエンコード/デコードするように変更
This commit is contained in:
@@ -5,11 +5,17 @@ from subprocess import Popen
|
|||||||
from threading import Thread
|
from threading import Thread
|
||||||
from config import config
|
from config import config
|
||||||
from model import model
|
from model import model
|
||||||
# from view import view
|
from utils import getKeyByValue, isUniqueStrings
|
||||||
from utils import getKeyByValue, isUniqueStrings, strPctToInt
|
|
||||||
import argparse
|
|
||||||
|
|
||||||
# Common
|
# 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:
|
class DownloadSoftwareProgressBar:
|
||||||
def __init__(self, action):
|
def __init__(self, action):
|
||||||
self.action = action
|
self.action = action
|
||||||
@@ -305,7 +311,7 @@ class ChatMessage:
|
|||||||
|
|
||||||
def send(self, data):
|
def send(self, data):
|
||||||
id = data["id"]
|
id = data["id"]
|
||||||
message = data["message"]
|
message = decodeUtf8(data["message"])
|
||||||
if len(message) > 0:
|
if len(message) > 0:
|
||||||
addSentMessageLog(message)
|
addSentMessageLog(message)
|
||||||
translation = ""
|
translation = ""
|
||||||
@@ -345,6 +351,8 @@ class ChatMessage:
|
|||||||
translation = f" ({translation})"
|
translation = f" ({translation})"
|
||||||
model.logger.info(f"[SENT] {message}{translation}")
|
model.logger.info(f"[SENT] {message}{translation}")
|
||||||
|
|
||||||
|
message = encodeUtf8(message)
|
||||||
|
translation = encodeUtf8(translation)
|
||||||
return {"status":200,
|
return {"status":200,
|
||||||
"result":{
|
"result":{
|
||||||
"id":id,
|
"id":id,
|
||||||
@@ -1365,3 +1373,4 @@ def init(endpoints:dict, *args, **kwargs) -> None:
|
|||||||
model.startReceiveOSC()
|
model.startReceiveOSC()
|
||||||
if config.ENABLE_VRC_MIC_MUTE_SYNC is True:
|
if config.ENABLE_VRC_MIC_MUTE_SYNC is True:
|
||||||
model.startCheckMuteSelfStatus()
|
model.startCheckMuteSelfStatus()
|
||||||
|
print(json.dumps({"status":348, "log": "End Initialization"}), flush=True)
|
||||||
@@ -326,13 +326,10 @@ def main():
|
|||||||
print(response, flush=True)
|
print(response, flush=True)
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
print(json.dumps({"status":200, "endpoint": "/initialization/start", "result":True}), flush=True)
|
|
||||||
controller.init({
|
controller.init({
|
||||||
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"],
|
"ctranslate2": action_mapping["/controller/callback_download_ctranslate2_weight"]["download"],
|
||||||
"whisper": action_mapping["/controller/callback_download_whisper_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"
|
process = "main"
|
||||||
match process:
|
match process:
|
||||||
|
|||||||
@@ -7,13 +7,14 @@ import { useStdoutToPython } from "./useStdoutToPython";
|
|||||||
export const useMessage = () => {
|
export const useMessage = () => {
|
||||||
const { currentMessageLogsStatus, addMessageLogsStatus, updateMessageLogsStatus } = useMessageLogsStatus();
|
const { currentMessageLogsStatus, addMessageLogsStatus, updateMessageLogsStatus } = useMessageLogsStatus();
|
||||||
const { asyncStdoutToPython } = useStdoutToPython();
|
const { asyncStdoutToPython } = useStdoutToPython();
|
||||||
|
const encoder = new TextEncoder();
|
||||||
|
|
||||||
return {
|
return {
|
||||||
sendMessage: (message) => {
|
sendMessage: (message) => {
|
||||||
const uuid = crypto.randomUUID();
|
const uuid = crypto.randomUUID();
|
||||||
const send_message_object = {
|
const send_message_object = {
|
||||||
id: uuid,
|
id: uuid,
|
||||||
message: message,
|
message: encoder.encode(message),
|
||||||
};
|
};
|
||||||
asyncStdoutToPython("/controller/callback_messagebox_press_key_enter", send_message_object);
|
asyncStdoutToPython("/controller/callback_messagebox_press_key_enter", send_message_object);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user