From ca7ba5ce099bc8cd5e94eba624a83fbb27dcba0f Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Sat, 26 Oct 2024 01:24:37 +0900 Subject: [PATCH 1/6] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Optimize=20?= =?UTF-8?q?:=20Init=E6=99=82=E3=81=AEconfig=E3=81=AE=E5=8F=96=E5=BE=97?= =?UTF-8?q?=E5=87=A6=E7=90=86=E3=82=92=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 56 ++++++------- .../transcription/transcription_whisper.py | 1 - src-python/utils.py | 6 -- src-python/webui_controller.py | 41 +++++++-- src-python/webui_mainloop.py | 25 ++++-- src-ui/app/App.jsx | 84 +++++++++---------- 6 files changed, 118 insertions(+), 95 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index 3f1e24a3..8fab754e 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -6,7 +6,7 @@ from json import dump as json_dump from device_manager import device_manager from models.transcription.transcription_languages import transcription_lang -from utils import generatePercentageStringsList, isUniqueStrings +from utils import isUniqueStrings json_serializable_vars = {} def json_serializable(var_name): @@ -78,8 +78,8 @@ class Config: return self._APPEARANCE_THEME_LIST @property - def UI_SCALING_LIST(self): - return self._UI_SCALING_LIST + def UI_SCALING_RANGE(self): + return self._UI_SCALING_RANGE @property def TEXTBOX_UI_SCALING_RANGE(self): @@ -90,12 +90,12 @@ class Config: return self._MESSAGE_BOX_RATIO_RANGE @property - def SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT(self): - return self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT + def SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST(self): + return self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST @property - def SELECTABLE_WHISPER_WEIGHT_TYPE_DICT(self): - return self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT + def SELECTABLE_WHISPER_WEIGHT_TYPE_LIST(self): + return self._SELECTABLE_WHISPER_WEIGHT_TYPE_LIST @property def MAX_MIC_THRESHOLD(self): @@ -753,7 +753,7 @@ class Config: @CTRANSLATE2_WEIGHT_TYPE.setter def CTRANSLATE2_WEIGHT_TYPE(self, value): - # if isinstance(value, str) and value in self.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT: + # if isinstance(value, str) and value in self.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST: if isinstance(value, str): self._CTRANSLATE2_WEIGHT_TYPE = value saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) @@ -966,27 +966,25 @@ class Config: self._BOOTH_URL = "https://misyaguziya.booth.pm/" self._DOCUMENTS_URL = "https://mzsoftware.notion.site/VRCT-Documents-be79b7a165f64442ad8f326d86c22246" self._DEEPL_AUTH_KEY_PAGE_URL = "https://www.deepl.com/ja/account/summary" - self._TRANSPARENCY_RANGE = (50, 100) + self._TRANSPARENCY_RANGE = (40, 100) self._APPEARANCE_THEME_LIST = ["Light", "Dark", "System"] - self._UI_SCALING_LIST = generatePercentageStringsList(start=40, end=200, step=10) - self._TEXTBOX_UI_SCALING_RANGE = (50, 200) + self._UI_SCALING_RANGE = (40, 200) + self._TEXTBOX_UI_SCALING_RANGE = (40, 200) self._MESSAGE_BOX_RATIO_RANGE = (1, 99) - self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = { - # {Save json str}: {i18n_placeholder} pairs - "Small": "Small", - "Large": "Large", - } + self._SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST = [ + "Small", + "Large", + ] - self._SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = { - # {Save json str}: {i18n_placeholder} pairs - "tiny": "tiny", - "base": "base", - "small": "small", - "medium": "medium", - "large-v1": "large-v1", - "large-v2": "large-v2", - "large-v3": "large-v3", - } + self._SELECTABLE_WHISPER_WEIGHT_TYPE_LIST = [ + "tiny", + "base", + "small", + "medium", + "large-v1", + "large-v2", + "large-v3", + ] self._MAX_MIC_THRESHOLD = 2000 self._MAX_SPEAKER_THRESHOLD = 4000 @@ -1165,15 +1163,9 @@ class Config: with open(self.PATH_CONFIG, 'r', encoding="utf-8") as fp: config = json_load(fp) - old_message_format = None for key in config.keys(): - if key == "MESSAGE_FORMAT": - old_message_format = config[key] setattr(self, key, config[key]) - if old_message_format is not None: - setattr(self, "SEND_MESSAGE_FORMAT_WITH_T", old_message_format) - with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp: config = {} for var_name, var_func in json_serializable_vars.items(): diff --git a/src-python/models/transcription/transcription_whisper.py b/src-python/models/transcription/transcription_whisper.py index 5e6f00bf..398a7524 100644 --- a/src-python/models/transcription/transcription_whisper.py +++ b/src-python/models/transcription/transcription_whisper.py @@ -1,7 +1,6 @@ from os import path as os_path, makedirs as os_makedirs from requests import get as requests_get from typing import Callable -import torch import huggingface_hub from faster_whisper import WhisperModel import logging diff --git a/src-python/utils.py b/src-python/utils.py index fbf55c43..9ea1725e 100644 --- a/src-python/utils.py +++ b/src-python/utils.py @@ -22,12 +22,6 @@ def makeEven(number, minus:bool=False): return number if isEven(number) else number - 1 return number if isEven(number) else number + 1 -def generatePercentageStringsList(start:int, end:int, step:int): - strings = [] - for percent in range(start, end + 1, step): - strings.append(f"{percent}%") - return strings - def intToPctStr(value:int): return f"{value}%" diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index c707a775..af52009e 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -11,16 +11,45 @@ import torch class Controller: def __init__(self) -> None: + self.init_mapping = {} self.run_mapping = {} self.run = None self.device_access_status = True + def setInitMapping(self, init_mapping:dict) -> None: + self.init_mapping = init_mapping + def setRunMapping(self, run_mapping:dict) -> None: self.run_mapping = run_mapping def setRun(self, run:Callable[[int, str, Any], None]) -> None: self.run = run + # configの初期値を設定 + def sendConfigStatusTrueData(self) -> None: + for endpoint, dict_data in self.init_mapping.items(): + if dict_data["status"] is True: + response = dict_data["variable"](None) + status = response.get("status", None) + result = response.get("result", None) + self.run( + status, + endpoint, + result, + ) + + def sendConfigStatusFalseData(self) -> None: + for endpoint, dict_data in self.init_mapping.items(): + if dict_data["status"] is False: + response = dict_data["variable"](None) + status = response.get("status", None) + result = response.get("result", None) + self.run( + status, + endpoint, + result, + ) + # response functions def updateMicHostList(self) -> None: self.run( @@ -353,8 +382,8 @@ class Controller: return {"status":200, "result":config.APPEARANCE_THEME_LIST} @staticmethod - def getUiScalingList(*args, **kwargs) -> dict: - return {"status":200, "result":config.UI_SCALING_LIST} + def getUiScalingRange(*args, **kwargs) -> dict: + return {"status":200, "result":config.UI_SCALING_RANGE} @staticmethod def getTextboxUiScalingRange(*args, **kwargs) -> dict: @@ -381,8 +410,8 @@ class Controller: return {"status":200,"result":config.SELECTED_TRANSLATION_COMPUTE_DEVICE} @staticmethod - def getSelectableCtranslate2WeightTypeDict(*args, **kwargs) -> dict: - return {"status":200, "result":config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT} + def getSelectableCtranslate2WeightTypeList(*args, **kwargs) -> dict: + return {"status":200, "result":config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_LIST} @staticmethod def getSelectedTranscriptionComputeDevice(*args, **kwargs) -> dict: @@ -395,8 +424,8 @@ class Controller: return {"status":200,"result":config.SELECTED_TRANSCRIPTION_COMPUTE_DEVICE} @staticmethod - def getSelectableWhisperModelTypeDict(*args, **kwargs) -> dict: - return {"status":200, "result":config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT} + def getSelectableWhisperWeightTypeList(*args, **kwargs) -> dict: + return {"status":200, "result":config.SELECTABLE_WHISPER_WEIGHT_TYPE_LIST} @staticmethod def getMaxMicThreshold(*args, **kwargs) -> dict: diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index f49872cf..7088ff49 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -94,11 +94,11 @@ mapping = { "/get/data/transparency": {"status": True, "variable":controller.getTransparency}, "/set/data/transparency": {"status": True, "variable":controller.setTransparency}, - "/get/data/appearance_theme_list": {"status": True, "variable":controller.getAppearanceThemesList}, - "/get/data/appearance_theme": {"status": True, "variable":controller.getAppearanceTheme}, - "/set/data/appearance_theme": {"status": True, "variable":controller.setAppearanceTheme}, + # "/get/data/appearance_theme_list": {"status": True, "variable":controller.getAppearanceThemesList}, + # "/get/data/appearance_theme": {"status": True, "variable":controller.getAppearanceTheme}, + # "/set/data/appearance_theme": {"status": True, "variable":controller.setAppearanceTheme}, - "/get/data/ui_scaling_list": {"status": True, "variable":controller.getUiScalingList}, + "/get/data/ui_scaling_range": {"status": True, "variable":controller.getUiScalingRange}, "/get/data/ui_scaling": {"status": True, "variable":controller.getUiScaling}, "/set/data/ui_scaling": {"status": True, "variable":controller.setUiScaling}, @@ -128,11 +128,11 @@ mapping = { "/set/enable/use_translation_feature": {"status": True, "variable":controller.setEnableUseTranslationFeature}, "/set/disable/use_translation_feature": {"status": True, "variable":controller.setDisableUseTranslationFeature}, - "/get/data/translation_compute_device_dict": {"status": True, "variable":controller.getComputeDeviceList}, + "/get/data/translation_compute_device_list": {"status": True, "variable":controller.getComputeDeviceList}, "/get/data/selected_translation_compute_device": {"status": True, "variable":controller.getSelectedTranslationComputeDevice}, "/set/data/selected_translation_compute_device": {"status": True, "variable":controller.setSelectedTranslationComputeDevice}, - "/get/data/selectable_ctranslate2_weight_type_dict": {"status": True, "variable":controller.getSelectableCtranslate2WeightTypeDict}, + "/get/data/selectable_ctranslate2_weight_type_list": {"status": True, "variable":controller.getSelectableCtranslate2WeightTypeList}, "/get/data/ctranslate2_weight_type": {"status": True, "variable":controller.getCtranslate2WeightType}, "/set/data/ctranslate2_weight_type": {"status": True, "variable":controller.setCtranslate2WeightType}, @@ -233,11 +233,11 @@ mapping = { "/set/enable/check_speaker_threshold": {"status": True, "variable":controller.setEnableCheckSpeakerThreshold}, "/set/disable/check_speaker_threshold": {"status": True, "variable":controller.setDisableCheckSpeakerThreshold}, - "/get/data/transcription_compute_device_dict": {"status": True, "variable":controller.getComputeDeviceList}, + "/get/data/transcription_compute_device_list": {"status": True, "variable":controller.getComputeDeviceList}, "/get/data/selected_transcription_compute_device": {"status": True, "variable":controller.getSelectedTranscriptionComputeDevice}, "/set/data/selected_transcription_compute_device": {"status": True, "variable":controller.setSelectedTranscriptionComputeDevice}, - "/get/data/selectable_whisper_weight_type_dict": {"status": True, "variable":controller.getSelectableWhisperModelTypeDict}, + "/get/data/selectable_whisper_weight_type_list": {"status": True, "variable":controller.getSelectableWhisperWeightTypeList}, "/get/data/whisper_weight_type": {"status": True, "variable":controller.getWhisperWeightType}, "/set/data/whisper_weight_type": {"status": True, "variable":controller.setWhisperWeightType}, @@ -315,6 +315,9 @@ mapping = { # "/run/stop_watchdog": {"status": True, "variable":controller.stopWatchdog}, } +init_mapping = {key:value for key, value in mapping.items() if key.startswith("/get/data/")} +controller.setInitMapping(init_mapping) + class Main: def __init__(self) -> None: self.queue = Queue() @@ -392,9 +395,15 @@ if __name__ == "__main__": main.startReceiver() main.startHandler() + # mappingのget/data/*でかつstatus:Trueのendpointを実行する + controller.sendConfigStatusTrueData() + controller.setWatchdogCallback(main.stop) controller.init() + # mappingのget/data/*でかつstatus:Falseのendpointを実行する + controller.sendConfigStatusFalseData() + # mappingのすべてのstatusをTrueにする for key in mapping.keys(): mapping[key]["status"] = True diff --git a/src-ui/app/App.jsx b/src-ui/app/App.jsx index 1e3b57a8..55f35d36 100644 --- a/src-ui/app/App.jsx +++ b/src-ui/app/App.jsx @@ -138,60 +138,60 @@ const StartPythonFacadeComponent = () => { fetchAndUpdateWindowGeometry(); - getUiLanguage(); - getUiScaling(); - getMessageLogUiScaling(); - getIsMainPageCompactMode(); - getMessageInputBoxRatio(); - getTransparency(); + // getUiLanguage(); + // getUiScaling(); + // getMessageLogUiScaling(); + // getIsMainPageCompactMode(); + // getMessageInputBoxRatio(); + // getTransparency(); asyncFetchFonts(); - getSelectedFontFamily(); + // getSelectedFontFamily(); - getSoftwareVersion(); + // getSoftwareVersion(); - getSelectedPresetTabNumber(); - getEnableMultiTranslation(); - getSelectedYourLanguages(); - getSelectedTargetLanguages(); - getSelectableLanguageList(); - getTranslationEngines(); - getSelectedTranslationEngines(); + // getSelectedPresetTabNumber(); + // getEnableMultiTranslation(); + // getSelectedYourLanguages(); + // getSelectedTargetLanguages(); + // getSelectableLanguageList(); + // getTranslationEngines(); + // getSelectedTranslationEngines(); - getMicHostList(); - getMicDeviceList(); - getSpeakerDeviceList(); + // getMicHostList(); + // getMicDeviceList(); + // getSpeakerDeviceList(); - getEnableAutoMicSelect(); - getEnableAutoSpeakerSelect(); - getSelectedMicHost(); - getSelectedMicDevice(); - getSelectedSpeakerDevice(); + // getEnableAutoMicSelect(); + // getEnableAutoSpeakerSelect(); + // getSelectedMicHost(); + // getSelectedMicDevice(); + // getSelectedSpeakerDevice(); - getMicThreshold(); - getSpeakerThreshold(); - getEnableAutomaticMicThreshold(); - getEnableAutomaticSpeakerThreshold(); + // getMicThreshold(); + // getSpeakerThreshold(); + // getEnableAutomaticMicThreshold(); + // getEnableAutomaticSpeakerThreshold(); - getMicRecordTimeout(); - getMicPhraseTimeout(); - getMicMaxWords(); - getMicWordFilterList(); + // getMicRecordTimeout(); + // getMicPhraseTimeout(); + // getMicMaxWords(); + // getMicWordFilterList(); - getSpeakerRecordTimeout(); - getSpeakerPhraseTimeout(); - getSpeakerMaxWords(); + // getSpeakerRecordTimeout(); + // getSpeakerPhraseTimeout(); + // getSpeakerMaxWords(); - getEnableAutoClearMessageInputBox(); - getSendMessageButtonType(); + // getEnableAutoClearMessageInputBox(); + // getSendMessageButtonType(); - getEnableSendOnlyTranslatedMessages(); - getEnableAutoExportMessageLogs(); - getEnableVrcMicMuteSync(); - getEnableSendMessageToVrc(); + // getEnableSendOnlyTranslatedMessages(); + // getEnableAutoExportMessageLogs(); + // getEnableVrcMicMuteSync(); + // getEnableSendMessageToVrc(); - getOscIpAddress(); - getOscPort(); + // getOscIpAddress(); + // getOscPort(); }).catch((err) => { console.error(err); }); From 69d9de686e9b2aa7051496a43f8ac4b891555850 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Sun, 27 Oct 2024 09:49:51 +0900 Subject: [PATCH 2/6] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Optimize=20?= =?UTF-8?q?:=20Init=E5=AE=8C=E4=BA=86=E6=99=82=E3=81=AB`run\initialization?= =?UTF-8?q?=5Fcomplete`=E3=81=A7config=E8=A8=AD=E5=AE=9A=E5=80=A4=E3=82=92?= =?UTF-8?q?=E3=81=99=E3=81=B9=E3=81=A6result=E3=81=A7=E6=B8=A1=E3=81=99?= =?UTF-8?q?=E3=82=88=E3=81=86=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/webui_controller.py | 39 ++++++++++++---------------------- src-python/webui_mainloop.py | 8 ++----- 2 files changed, 16 insertions(+), 31 deletions(-) diff --git a/src-python/webui_controller.py b/src-python/webui_controller.py index af52009e..9a9712e2 100644 --- a/src-python/webui_controller.py +++ b/src-python/webui_controller.py @@ -25,31 +25,6 @@ class Controller: def setRun(self, run:Callable[[int, str, Any], None]) -> None: self.run = run - # configの初期値を設定 - def sendConfigStatusTrueData(self) -> None: - for endpoint, dict_data in self.init_mapping.items(): - if dict_data["status"] is True: - response = dict_data["variable"](None) - status = response.get("status", None) - result = response.get("result", None) - self.run( - status, - endpoint, - result, - ) - - def sendConfigStatusFalseData(self) -> None: - for endpoint, dict_data in self.init_mapping.items(): - if dict_data["status"] is False: - response = dict_data["variable"](None) - status = response.get("status", None) - result = response.get("result", None) - self.run( - status, - endpoint, - result, - ) - # response functions def updateMicHostList(self) -> None: self.run( @@ -72,6 +47,18 @@ class Controller: model.getListSpeakerDevice(), ) + def updateConfigSettings(self) -> None: + settings = {} + for endpoint, dict_data in self.init_mapping.items(): + response = dict_data["variable"](None) + result = response.get("result", None) + settings[endpoint] = result + self.run( + 200, + self.run_mapping["initialization_complete"], + settings, + ) + def restartAccessDevices(self) -> None: if config.ENABLE_TRANSCRIPTION_SEND is True: self.startThreadingTranscriptionSendMessage() @@ -1733,6 +1720,8 @@ class Controller: if config.AUTO_SPEAKER_SELECT is True: self.setEnableAutoSpeakerSelect() + self.updateConfigSettings() + printLog("End Initialization") self.startWatchdog() \ No newline at end of file diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 7088ff49..1b0961cd 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -34,6 +34,8 @@ run_mapping = { "speaker_device_list":"/run/speaker_device_list", "update_software_flag":"/run/update_software_flag", + + "initialization_complete":"run/initialization_complete", } controller.setRunMapping(run_mapping) @@ -395,15 +397,9 @@ if __name__ == "__main__": main.startReceiver() main.startHandler() - # mappingのget/data/*でかつstatus:Trueのendpointを実行する - controller.sendConfigStatusTrueData() - controller.setWatchdogCallback(main.stop) controller.init() - # mappingのget/data/*でかつstatus:Falseのendpointを実行する - controller.sendConfigStatusFalseData() - # mappingのすべてのstatusをTrueにする for key in mapping.keys(): mapping[key]["status"] = True From 2dd4419bb126dbba46828b2a195e1995d757a9d3 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Sun, 27 Oct 2024 15:12:04 +0900 Subject: [PATCH 3/6] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Config=20:?= =?UTF-8?q?=20config.json=E3=81=AE=E4=BF=9D=E5=AD=98=E3=82=BF=E3=82=A4?= =?UTF-8?q?=E3=83=9F=E3=83=B3=E3=82=B0=E3=82=92fire=20and=20forget?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 33 +++++++++++++++------------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index 3f1e24a3..8d719516 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -3,7 +3,7 @@ import inspect from os import path as os_path, makedirs as os_makedirs from json import load as json_load from json import dump as json_dump - +from asyncio import new_event_loop from device_manager import device_manager from models.transcription.transcription_languages import transcription_lang from utils import generatePercentageStringsList, isUniqueStrings @@ -15,12 +15,14 @@ def json_serializable(var_name): return func return decorator -def saveJson(path, key, value): - with open(path, "r", encoding="utf-8") as fp: - json_data = json_load(fp) - json_data[key] = value +config_data = {} +def saveJsonData(path, key, value): + config_data[key] = value with open(path, "w", encoding="utf-8") as fp: - json_dump(json_data, fp, indent=4, ensure_ascii=False) + json_dump(config_data, fp, indent=4, ensure_ascii=False) + +def saveJson(path, key, value): + new_event_loop().run_in_executor(None, saveJsonData, path, key, value) class Config: _instance = None @@ -1163,21 +1165,16 @@ class Config: def load_config(self): if os_path.isfile(self.PATH_CONFIG) is not False: with open(self.PATH_CONFIG, 'r', encoding="utf-8") as fp: - config = json_load(fp) + if fp.readable() and fp.seek(0, 2) > 0: + fp.seek(0) + config_data = json_load(fp) - old_message_format = None - for key in config.keys(): - if key == "MESSAGE_FORMAT": - old_message_format = config[key] - setattr(self, key, config[key]) - - if old_message_format is not None: - setattr(self, "SEND_MESSAGE_FORMAT_WITH_T", old_message_format) + for key, value in config_data.items(): + setattr(self, key, value) with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp: - config = {} for var_name, var_func in json_serializable_vars.items(): - config[var_name] = var_func(self) - json_dump(config, fp, indent=4, ensure_ascii=False) + config_data[var_name] = var_func(self) + json_dump(config_data, fp, indent=4, ensure_ascii=False) config = Config() \ No newline at end of file From 4fff1111737c0dc2f9ff2680202a1838ec504388 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Sun, 27 Oct 2024 18:22:20 +0900 Subject: [PATCH 4/6] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Config=20:?= =?UTF-8?q?=20config.json=E3=81=AE=E4=BF=9D=E5=AD=98=E3=82=BF=E3=82=A4?= =?UTF-8?q?=E3=83=9F=E3=83=B3=E3=82=B0=E3=82=92debounce=E5=87=A6=E7=90=86?= =?UTF-8?q?=E3=81=AB=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 161 ++++++++++++++++++++++--------------------- 1 file changed, 84 insertions(+), 77 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index 8d719516..96483478 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -3,7 +3,7 @@ import inspect from os import path as os_path, makedirs as os_makedirs from json import load as json_load from json import dump as json_dump -from asyncio import new_event_loop +import threading from device_manager import device_manager from models.transcription.transcription_languages import transcription_lang from utils import generatePercentageStringsList, isUniqueStrings @@ -15,17 +15,11 @@ def json_serializable(var_name): return func return decorator -config_data = {} -def saveJsonData(path, key, value): - config_data[key] = value - with open(path, "w", encoding="utf-8") as fp: - json_dump(config_data, fp, indent=4, ensure_ascii=False) - -def saveJson(path, key, value): - new_event_loop().run_in_executor(None, saveJsonData, path, key, value) - class Config: _instance = None + config_data = {} + timer = None + debounce_time = 2 def __new__(cls): if cls._instance is None: @@ -34,6 +28,19 @@ class Config: cls._instance.load_config() return cls._instance + def saveConfigToFile(self): + with open(self.PATH_CONFIG, "w", encoding="utf-8") as fp: + json_dump(self.config_data, fp, indent=4, ensure_ascii=False) + + def saveConfig(self, key, value): + self.config_data[key] = value + + if isinstance(self.timer, threading.Timer) and self.timer.is_alive(): + self.timer.cancel() + timer = threading.Timer(self.debounce_time, self.saveConfigToFile) + timer.daemon = True + timer.start() + # Read Only @property def VERSION(self): @@ -226,7 +233,7 @@ class Config: def SELECTED_TAB_NO(self, value): if isinstance(value, str): self._SELECTED_TAB_NO = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_TRANSLATION_ENGINES') @@ -237,7 +244,7 @@ class Config: def SELECTED_TRANSLATION_ENGINES(self, value): if isinstance(value, dict): self._SELECTED_TRANSLATION_ENGINES = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_YOUR_LANGUAGES') @@ -258,7 +265,7 @@ class Config: self._SELECTED_YOUR_LANGUAGES = value except Exception: pass - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_TARGET_LANGUAGES') @@ -279,7 +286,7 @@ class Config: self._SELECTED_TARGET_LANGUAGES = value except Exception: pass - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_TRANSCRIPTION_ENGINE') @@ -290,7 +297,7 @@ class Config: def SELECTED_TRANSCRIPTION_ENGINE(self, value): if isinstance(value, str): self._SELECTED_TRANSCRIPTION_ENGINE = value - # saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + # self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MULTI_LANGUAGE_TRANSLATION') @@ -301,7 +308,7 @@ class Config: def MULTI_LANGUAGE_TRANSLATION(self, value): if isinstance(value, bool): self._MULTI_LANGUAGE_TRANSLATION = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('CONVERT_MESSAGE_TO_ROMAJI') @@ -312,7 +319,7 @@ class Config: def CONVERT_MESSAGE_TO_ROMAJI(self, value): if isinstance(value, bool): self._CONVERT_MESSAGE_TO_ROMAJI = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('CONVERT_MESSAGE_TO_HIRAGANA') @@ -323,7 +330,7 @@ class Config: def CONVERT_MESSAGE_TO_HIRAGANA(self, value): if isinstance(value, bool): self._CONVERT_MESSAGE_TO_HIRAGANA = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MAIN_WINDOW_SIDEBAR_COMPACT_MODE') @@ -334,7 +341,7 @@ class Config: def MAIN_WINDOW_SIDEBAR_COMPACT_MODE(self, value): if isinstance(value, bool): self._MAIN_WINDOW_SIDEBAR_COMPACT_MODE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) ## Config Window @property @@ -346,7 +353,7 @@ class Config: def TRANSPARENCY(self, value): if isinstance(value, int): self._TRANSPARENCY = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('APPEARANCE_THEME') @@ -357,7 +364,7 @@ class Config: def APPEARANCE_THEME(self, value): if value in self.APPEARANCE_THEME_LIST: self._APPEARANCE_THEME = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('UI_SCALING') @@ -368,7 +375,7 @@ class Config: def UI_SCALING(self, value): if isinstance(value, int): self._UI_SCALING = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('TEXTBOX_UI_SCALING') @@ -379,7 +386,7 @@ class Config: def TEXTBOX_UI_SCALING(self, value): if isinstance(value, int): self._TEXTBOX_UI_SCALING = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MESSAGE_BOX_RATIO') @@ -390,7 +397,7 @@ class Config: def MESSAGE_BOX_RATIO(self, value): if isinstance(value, (int, float)): self._MESSAGE_BOX_RATIO = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('FONT_FAMILY') @@ -401,7 +408,7 @@ class Config: def FONT_FAMILY(self, value): if isinstance(value, str): self._FONT_FAMILY = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('UI_LANGUAGE') @@ -412,7 +419,7 @@ class Config: def UI_LANGUAGE(self, value): if isinstance(value, str): self._UI_LANGUAGE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('RESTORE_MAIN_WINDOW_GEOMETRY') @@ -423,7 +430,7 @@ class Config: def RESTORE_MAIN_WINDOW_GEOMETRY(self, value): if isinstance(value, bool): self._RESTORE_MAIN_WINDOW_GEOMETRY = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MAIN_WINDOW_GEOMETRY') @@ -436,7 +443,7 @@ class Config: for key, value in value.items(): if isinstance(value, int): self._MAIN_WINDOW_GEOMETRY[key] = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.MAIN_WINDOW_GEOMETRY) + self.saveConfig(inspect.currentframe().f_code.co_name, self.MAIN_WINDOW_GEOMETRY) @property @json_serializable('AUTO_MIC_SELECT') @@ -447,7 +454,7 @@ class Config: def AUTO_MIC_SELECT(self, value): if isinstance(value, bool): self._AUTO_MIC_SELECT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_MIC_HOST') @@ -458,7 +465,7 @@ class Config: def SELECTED_MIC_HOST(self, value): if value in [host for host in device_manager.getMicDevices().keys()]: self._SELECTED_MIC_HOST = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_MIC_DEVICE') @@ -469,7 +476,7 @@ class Config: def SELECTED_MIC_DEVICE(self, value): if value in [device["name"] for device in device_manager.getMicDevices()[self.SELECTED_MIC_HOST]]: self._SELECTED_MIC_DEVICE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_THRESHOLD') @@ -480,7 +487,7 @@ class Config: def MIC_THRESHOLD(self, value): if isinstance(value, int): self._MIC_THRESHOLD = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_AUTOMATIC_THRESHOLD') @@ -491,7 +498,7 @@ class Config: def MIC_AUTOMATIC_THRESHOLD(self, value): if isinstance(value, bool): self._MIC_AUTOMATIC_THRESHOLD = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_RECORD_TIMEOUT') @@ -502,7 +509,7 @@ class Config: def MIC_RECORD_TIMEOUT(self, value): if isinstance(value, int): self._MIC_RECORD_TIMEOUT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_PHRASE_TIMEOUT') @@ -513,7 +520,7 @@ class Config: def MIC_PHRASE_TIMEOUT(self, value): if isinstance(value, int): self._MIC_PHRASE_TIMEOUT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_MAX_PHRASES') @@ -524,7 +531,7 @@ class Config: def MIC_MAX_PHRASES(self, value): if isinstance(value, int): self._MIC_MAX_PHRASES = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_WORD_FILTER') @@ -535,7 +542,7 @@ class Config: def MIC_WORD_FILTER(self, value): if isinstance(value, list): self._MIC_WORD_FILTER = sorted(set(value), key=value.index) - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_AVG_LOGPROB') @@ -546,7 +553,7 @@ class Config: def MIC_AVG_LOGPROB(self, value): if isinstance(value, (int, float)): self._MIC_AVG_LOGPROB = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('MIC_NO_SPEECH_PROB') @@ -557,7 +564,7 @@ class Config: def MIC_NO_SPEECH_PROB(self, value): if isinstance(value, (int, float)): self._MIC_NO_SPEECH_PROB = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('AUTO_SPEAKER_SELECT') @@ -568,7 +575,7 @@ class Config: def AUTO_SPEAKER_SELECT(self, value): if isinstance(value, bool): self._AUTO_SPEAKER_SELECT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_SPEAKER_DEVICE') @@ -579,7 +586,7 @@ class Config: def SELECTED_SPEAKER_DEVICE(self, value): if value in [device["name"] for device in device_manager.getSpeakerDevices()]: self._SELECTED_SPEAKER_DEVICE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SPEAKER_THRESHOLD') @@ -590,7 +597,7 @@ class Config: def SPEAKER_THRESHOLD(self, value): if isinstance(value, int): self._SPEAKER_THRESHOLD = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SPEAKER_AUTOMATIC_THRESHOLD') @@ -601,7 +608,7 @@ class Config: def SPEAKER_AUTOMATIC_THRESHOLD(self, value): if isinstance(value, bool): self._SPEAKER_AUTOMATIC_THRESHOLD = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SPEAKER_RECORD_TIMEOUT') @@ -612,7 +619,7 @@ class Config: def SPEAKER_RECORD_TIMEOUT(self, value): if isinstance(value, int): self._SPEAKER_RECORD_TIMEOUT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SPEAKER_PHRASE_TIMEOUT') @@ -623,7 +630,7 @@ class Config: def SPEAKER_PHRASE_TIMEOUT(self, value): if isinstance(value, int): self._SPEAKER_PHRASE_TIMEOUT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SPEAKER_MAX_PHRASES') @@ -634,7 +641,7 @@ class Config: def SPEAKER_MAX_PHRASES(self, value): if isinstance(value, int): self._SPEAKER_MAX_PHRASES = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SPEAKER_AVG_LOGPROB') @@ -645,7 +652,7 @@ class Config: def SPEAKER_AVG_LOGPROB(self, value): if isinstance(value, (int, float)): self._SPEAKER_AVG_LOGPROB = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SPEAKER_NO_SPEECH_PROB') @@ -656,7 +663,7 @@ class Config: def SPEAKER_NO_SPEECH_PROB(self, value): if isinstance(value, (int, float)): self._SPEAKER_NO_SPEECH_PROB = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('OSC_IP_ADDRESS') @@ -667,7 +674,7 @@ class Config: def OSC_IP_ADDRESS(self, value): if isinstance(value, str): self._OSC_IP_ADDRESS = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('OSC_PORT') @@ -678,7 +685,7 @@ class Config: def OSC_PORT(self, value): if isinstance(value, int): self._OSC_PORT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('AUTH_KEYS') @@ -691,7 +698,7 @@ class Config: for key, value in value.items(): if isinstance(value, str): self._AUTH_KEYS[key] = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.AUTH_KEYS) + self.saveConfig(inspect.currentframe().f_code.co_name, self.AUTH_KEYS) @property @json_serializable('USE_EXCLUDE_WORDS') @@ -702,7 +709,7 @@ class Config: def USE_EXCLUDE_WORDS(self, value): if isinstance(value, bool): self._USE_EXCLUDE_WORDS = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('USE_TRANSLATION_FEATURE') @@ -713,7 +720,7 @@ class Config: def USE_TRANSLATION_FEATURE(self, value): if isinstance(value, bool): self._USE_TRANSLATION_FEATURE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('USE_WHISPER_FEATURE') @@ -724,7 +731,7 @@ class Config: def USE_WHISPER_FEATURE(self, value): if isinstance(value, bool): self._USE_WHISPER_FEATURE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_TRANSLATION_COMPUTE_DEVICE') @@ -735,7 +742,7 @@ class Config: def SELECTED_TRANSLATION_COMPUTE_DEVICE(self, value): if isinstance(value, dict): self._SELECTED_TRANSLATION_COMPUTE_DEVICE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SELECTED_TRANSCRIPTION_COMPUTE_DEVICE') @@ -746,7 +753,7 @@ class Config: def SELECTED_TRANSCRIPTION_COMPUTE_DEVICE(self, value): if isinstance(value, dict): self._SELECTED_TRANSCRIPTION_COMPUTE_DEVICE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('CTRANSLATE2_WEIGHT_TYPE') @@ -758,7 +765,7 @@ class Config: # if isinstance(value, str) and value in self.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT: if isinstance(value, str): self._CTRANSLATE2_WEIGHT_TYPE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('WHISPER_WEIGHT_TYPE') @@ -769,7 +776,7 @@ class Config: def WHISPER_WEIGHT_TYPE(self, value): if isinstance(value, str): self._WHISPER_WEIGHT_TYPE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('AUTO_CLEAR_MESSAGE_BOX') @@ -780,7 +787,7 @@ class Config: def AUTO_CLEAR_MESSAGE_BOX(self, value): if isinstance(value, bool): self._AUTO_CLEAR_MESSAGE_BOX = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SEND_ONLY_TRANSLATED_MESSAGES') @@ -791,7 +798,7 @@ class Config: def SEND_ONLY_TRANSLATED_MESSAGES(self, value): if isinstance(value, bool): self._SEND_ONLY_TRANSLATED_MESSAGES = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SEND_MESSAGE_BUTTON_TYPE') @@ -802,7 +809,7 @@ class Config: def SEND_MESSAGE_BUTTON_TYPE(self, value): if isinstance(value, str): self._SEND_MESSAGE_BUTTON_TYPE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('OVERLAY_SETTINGS') @@ -815,7 +822,7 @@ class Config: for key, value in value.items(): if isinstance(value, (int, float)): self._OVERLAY_SETTINGS[key] = float(value) - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.OVERLAY_SETTINGS) + self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_SETTINGS) @property @json_serializable('OVERLAY_SMALL_LOG') @@ -826,7 +833,7 @@ class Config: def OVERLAY_SMALL_LOG(self, value): if isinstance(value, bool): self._OVERLAY_SMALL_LOG = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('OVERLAY_SMALL_LOG_SETTINGS') @@ -844,7 +851,7 @@ class Config: case "display_duration" | "fadeout_duration": if isinstance(value, int): self._OVERLAY_SMALL_LOG_SETTINGS[key] = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, self.OVERLAY_SMALL_LOG_SETTINGS) + self.saveConfig(inspect.currentframe().f_code.co_name, self.OVERLAY_SMALL_LOG_SETTINGS) @property @json_serializable('OVERLAY_UI_TYPE') @@ -855,7 +862,7 @@ class Config: def OVERLAY_UI_TYPE(self, value): if isinstance(value, str): self._OVERLAY_UI_TYPE = value - # saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + # self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SEND_MESSAGE_TO_VRC') @@ -866,7 +873,7 @@ class Config: def SEND_MESSAGE_TO_VRC(self, value): if isinstance(value, bool): self._SEND_MESSAGE_TO_VRC = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SEND_MESSAGE_FORMAT') @@ -879,7 +886,7 @@ class Config: if isUniqueStrings(["[message]"], value) is False: value = "[message]" self._SEND_MESSAGE_FORMAT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SEND_MESSAGE_FORMAT_WITH_T') @@ -892,7 +899,7 @@ class Config: if isUniqueStrings(["[message]", "[translation]"], value) is False: value = "[message]([translation])" self._SEND_MESSAGE_FORMAT_WITH_T = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('RECEIVED_MESSAGE_FORMAT') @@ -905,7 +912,7 @@ class Config: if isUniqueStrings(["[message]"], value) is False: value = "[message]" self._RECEIVED_MESSAGE_FORMAT = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('RECEIVED_MESSAGE_FORMAT_WITH_T') @@ -918,7 +925,7 @@ class Config: if isUniqueStrings(["[message]", "[translation]"], value) is False: value = "[message]([translation])" self._RECEIVED_MESSAGE_FORMAT_WITH_T = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('SEND_RECEIVED_MESSAGE_TO_VRC') @@ -929,7 +936,7 @@ class Config: def SEND_RECEIVED_MESSAGE_TO_VRC(self, value): if isinstance(value, bool): self._SEND_RECEIVED_MESSAGE_TO_VRC = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('LOGGER_FEATURE') @@ -940,7 +947,7 @@ class Config: def LOGGER_FEATURE(self, value): if isinstance(value, bool): self._LOGGER_FEATURE = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) @property @json_serializable('VRC_MIC_MUTE_SYNC') @@ -951,7 +958,7 @@ class Config: def VRC_MIC_MUTE_SYNC(self, value): if isinstance(value, bool): self._VRC_MIC_MUTE_SYNC = value - saveJson(self.PATH_CONFIG, inspect.currentframe().f_code.co_name, value) + self.saveConfig(inspect.currentframe().f_code.co_name, value) def init_config(self): # Read Only @@ -1167,14 +1174,14 @@ class Config: with open(self.PATH_CONFIG, 'r', encoding="utf-8") as fp: if fp.readable() and fp.seek(0, 2) > 0: fp.seek(0) - config_data = json_load(fp) + self.config_data = json_load(fp) - for key, value in config_data.items(): + for key, value in self.config_data.items(): setattr(self, key, value) with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp: for var_name, var_func in json_serializable_vars.items(): - config_data[var_name] = var_func(self) - json_dump(config_data, fp, indent=4, ensure_ascii=False) + self.config_data[var_name] = var_func(self) + json_dump(self.config_data, fp, indent=4, ensure_ascii=False) config = Config() \ No newline at end of file From 68d05b38a8ca8b4a4407d1239c2cc88949610913 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Mon, 28 Oct 2024 10:07:33 +0900 Subject: [PATCH 5/6] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20Config=20:=20?= =?UTF-8?q?=E4=BF=9D=E5=AD=98=E7=94=A8timer=E3=81=8Ccancel=E3=81=95?= =?UTF-8?q?=E3=82=8C=E3=81=A6=E3=81=84=E3=81=AA=E3=81=84=E5=95=8F=E9=A1=8C?= =?UTF-8?q?=E3=82=92=E4=BF=AE=E6=AD=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 28 ++++++++++++++-------------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index d74afb5e..9d5b3984 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -17,9 +17,9 @@ def json_serializable(var_name): class Config: _instance = None - config_data = {} - timer = None - debounce_time = 2 + _config_data = {} + _timer = None + _debounce_time = 2 def __new__(cls): if cls._instance is None: @@ -30,16 +30,16 @@ class Config: def saveConfigToFile(self): with open(self.PATH_CONFIG, "w", encoding="utf-8") as fp: - json_dump(self.config_data, fp, indent=4, ensure_ascii=False) + json_dump(self._config_data, fp, indent=4, ensure_ascii=False) def saveConfig(self, key, value): - self.config_data[key] = value + self._config_data[key] = value - if isinstance(self.timer, threading.Timer) and self.timer.is_alive(): - self.timer.cancel() - timer = threading.Timer(self.debounce_time, self.saveConfigToFile) - timer.daemon = True - timer.start() + if isinstance(self._timer, threading.Timer) and self._timer.is_alive(): + self._timer.cancel() + self._timer = threading.Timer(self._debounce_time, self.saveConfigToFile) + self._timer.daemon = True + self._timer.start() # Read Only @property @@ -1172,14 +1172,14 @@ class Config: with open(self.PATH_CONFIG, 'r', encoding="utf-8") as fp: if fp.readable() and fp.seek(0, 2) > 0: fp.seek(0) - self.config_data = json_load(fp) + self._config_data = json_load(fp) - for key, value in self.config_data.items(): + for key, value in self._config_data.items(): setattr(self, key, value) with open(self.PATH_CONFIG, 'w', encoding="utf-8") as fp: for var_name, var_func in json_serializable_vars.items(): - self.config_data[var_name] = var_func(self) - json_dump(self.config_data, fp, indent=4, ensure_ascii=False) + self._config_data[var_name] = var_func(self) + json_dump(self._config_data, fp, indent=4, ensure_ascii=False) config = Config() \ No newline at end of file From afed3fffcde1b6edda8c2d73eb44df90db40b28c Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Mon, 28 Oct 2024 21:04:55 +0900 Subject: [PATCH 6/6] =?UTF-8?q?[Update/bugfix]=20=E3=83=90=E3=83=83?= =?UTF-8?q?=E3=82=AF=E3=82=A8=E3=83=B3=E3=83=89=E3=81=8B=E3=82=89=E3=82=82?= =?UTF-8?q?=E3=82=89=E3=81=A3=E3=81=9F=E5=88=9D=E6=9C=9F=E3=83=87=E3=83=BC?= =?UTF-8?q?=E3=82=BF=E3=82=92=E7=B9=8B=E3=81=92=E3=80=81UI=E3=81=A8?= =?UTF-8?q?=E5=88=9D=E5=9B=9E=E5=90=8C=E6=9C=9F=20initialization=5Fcomplet?= =?UTF-8?q?e=20=E3=82=A8=E3=83=B3=E3=83=89=E3=83=9D=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=83=88=E4=BF=AE=E6=AD=A3=20('/'=E8=BF=BD=E5=8A=A0)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/webui_mainloop.py | 2 +- src-ui/app/App.jsx | 139 ------------------------------ src-ui/logics/common/useWindow.js | 4 - src-ui/logics/useReceiveRoutes.js | 12 +++ 4 files changed, 13 insertions(+), 144 deletions(-) diff --git a/src-python/webui_mainloop.py b/src-python/webui_mainloop.py index 1b0961cd..1840014a 100644 --- a/src-python/webui_mainloop.py +++ b/src-python/webui_mainloop.py @@ -35,7 +35,7 @@ run_mapping = { "update_software_flag":"/run/update_software_flag", - "initialization_complete":"run/initialization_complete", + "initialization_complete":"/run/initialization_complete", } controller.setRunMapping(run_mapping) diff --git a/src-ui/app/App.jsx b/src-ui/app/App.jsx index 55f35d36..8ed648e8 100644 --- a/src-ui/app/App.jsx +++ b/src-ui/app/App.jsx @@ -33,45 +33,14 @@ import { } from "@logics_common"; import { - useSoftwareVersion, - useEnableAutoMicSelect, - useEnableAutoSpeakerSelect, - useSelectedMicHost, - useSelectedMicDevice, - useSelectedSpeakerDevice, - useMicThreshold, - useSpeakerThreshold, - useEnableAutoClearMessageInputBox, - useEnableSendOnlyTranslatedMessages, - useEnableAutoExportMessageLogs, - useEnableVrcMicMuteSync, - useEnableSendMessageToVrc, - useSendMessageButtonType, useUiLanguage, useUiScaling, - useMessageLogUiScaling, useSelectedFontFamily, useTransparency, - useMicHostList, - useMicDeviceList, - useSpeakerDeviceList, - useMicRecordTimeout, - useMicPhraseTimeout, - useMicMaxWords, - useMicWordFilterList, - useSpeakerRecordTimeout, - useSpeakerPhraseTimeout, - useSpeakerMaxWords, - useOscIpAddress, - useOscPort, } from "@logics_configs"; import { useMainFunction, - useIsMainPageCompactMode, - useLanguageSettings, - useSelectableLanguageList, - useMessageInputBoxRatio, } from "@logics_main"; const StartPythonFacadeComponent = () => { @@ -79,119 +48,11 @@ const StartPythonFacadeComponent = () => { const hasRunRef = useRef(false); const { asyncFetchFonts } = useAsyncFetchFonts(); - const { fetchAndUpdateWindowGeometry } = useWindow(); - - const { getMicHostList } = useMicHostList(); - const { getMicDeviceList } = useMicDeviceList(); - const { getSpeakerDeviceList } = useSpeakerDeviceList(); - - const { getIsMainPageCompactMode } = useIsMainPageCompactMode(); - const { getSoftwareVersion } = useSoftwareVersion(); - const { getEnableAutoMicSelect } = useEnableAutoMicSelect(); - const { getEnableAutoSpeakerSelect } = useEnableAutoSpeakerSelect(); - const { getSelectedMicHost } = useSelectedMicHost(); - const { getSelectedMicDevice } = useSelectedMicDevice(); - const { getSelectedSpeakerDevice } = useSelectedSpeakerDevice(); - const { getMicThreshold, getEnableAutomaticMicThreshold } = useMicThreshold(); - const { getSpeakerThreshold, getEnableAutomaticSpeakerThreshold } = useSpeakerThreshold(); - - const { getEnableAutoClearMessageInputBox } = useEnableAutoClearMessageInputBox(); - const { getEnableSendOnlyTranslatedMessages } = useEnableSendOnlyTranslatedMessages(); - const { getEnableAutoExportMessageLogs } = useEnableAutoExportMessageLogs(); - const { getEnableVrcMicMuteSync } = useEnableVrcMicMuteSync(); - const { getEnableSendMessageToVrc } = useEnableSendMessageToVrc(); - - const { getSendMessageButtonType } = useSendMessageButtonType(); - const { getUiLanguage } = useUiLanguage(); - const { getUiScaling } = useUiScaling(); - const { getMessageLogUiScaling } = useMessageLogUiScaling(); - const { getSelectedFontFamily } = useSelectedFontFamily(); - const { getTransparency } = useTransparency(); - - const { - getSelectedPresetTabNumber, - getEnableMultiTranslation, - getSelectedYourLanguages, - getSelectedTargetLanguages, - getTranslationEngines, - getSelectedTranslationEngines, - } = useLanguageSettings(); - const { getSelectableLanguageList } = useSelectableLanguageList(); - const { getMessageInputBoxRatio } = useMessageInputBoxRatio(); - - const { getMicRecordTimeout } = useMicRecordTimeout(); - const { getMicPhraseTimeout } = useMicPhraseTimeout(); - const { getMicMaxWords } = useMicMaxWords(); - const { getMicWordFilterList } = useMicWordFilterList(); - - const { getSpeakerRecordTimeout } = useSpeakerRecordTimeout(); - const { getSpeakerPhraseTimeout } = useSpeakerPhraseTimeout(); - const { getSpeakerMaxWords } = useSpeakerMaxWords(); - - const { getOscIpAddress } = useOscIpAddress(); - const { getOscPort } = useOscPort(); - useEffect(() => { if (!hasRunRef.current) { asyncStartPython().then(() => { startFeedingToWatchDog(); - - fetchAndUpdateWindowGeometry(); - - // getUiLanguage(); - // getUiScaling(); - // getMessageLogUiScaling(); - // getIsMainPageCompactMode(); - // getMessageInputBoxRatio(); - // getTransparency(); - asyncFetchFonts(); - // getSelectedFontFamily(); - - // getSoftwareVersion(); - - // getSelectedPresetTabNumber(); - // getEnableMultiTranslation(); - // getSelectedYourLanguages(); - // getSelectedTargetLanguages(); - // getSelectableLanguageList(); - // getTranslationEngines(); - // getSelectedTranslationEngines(); - - // getMicHostList(); - // getMicDeviceList(); - // getSpeakerDeviceList(); - - // getEnableAutoMicSelect(); - // getEnableAutoSpeakerSelect(); - // getSelectedMicHost(); - // getSelectedMicDevice(); - // getSelectedSpeakerDevice(); - - // getMicThreshold(); - // getSpeakerThreshold(); - // getEnableAutomaticMicThreshold(); - // getEnableAutomaticSpeakerThreshold(); - - // getMicRecordTimeout(); - // getMicPhraseTimeout(); - // getMicMaxWords(); - // getMicWordFilterList(); - - // getSpeakerRecordTimeout(); - // getSpeakerPhraseTimeout(); - // getSpeakerMaxWords(); - - // getEnableAutoClearMessageInputBox(); - // getSendMessageButtonType(); - - // getEnableSendOnlyTranslatedMessages(); - // getEnableAutoExportMessageLogs(); - // getEnableVrcMicMuteSync(); - // getEnableSendMessageToVrc(); - - // getOscIpAddress(); - // getOscPort(); }).catch((err) => { console.error(err); }); diff --git a/src-ui/logics/common/useWindow.js b/src-ui/logics/common/useWindow.js index 760e866b..9d2a7669 100644 --- a/src-ui/logics/common/useWindow.js +++ b/src-ui/logics/common/useWindow.js @@ -51,9 +51,6 @@ export const useWindow = () => { } }; - const fetchAndUpdateWindowGeometry = () => { - asyncStdoutToPython("/get/data/main_window_geometry"); - }; const WindowGeometryController = () => { useEffect(() => { @@ -86,7 +83,6 @@ export const useWindow = () => { return { WindowGeometryController, asyncSaveWindowGeometry, - fetchAndUpdateWindowGeometry, restoreWindowGeometry, }; }; diff --git a/src-ui/logics/useReceiveRoutes.js b/src-ui/logics/useReceiveRoutes.js index 639edfd1..cd109e60 100644 --- a/src-ui/logics/useReceiveRoutes.js +++ b/src-ui/logics/useReceiveRoutes.js @@ -362,9 +362,21 @@ export const useReceiveRoutes = () => { "/set/data/speaker_max_phrases": updateSpeakerMaxWords, }; + const receiveRoutes = (parsed_data) => { + const initDataSyncProcess = (payload) => { + for (const [endpoint, value] of Object.entries(payload)) { + const route = routes[endpoint]; + (route) ? route(value) : console.error(`Invalid endpoint: ${endpoint}\vvalue: ${JSON.stringify(value)}`); + } + }; + switch (parsed_data.status) { case 200: + if (parsed_data.endpoint === "/run/initialization_complete") { + initDataSyncProcess(parsed_data.result); + break; + }; const route = routes[parsed_data.endpoint]; (route) ? route(parsed_data.result) : console.error(`Invalid endpoint: ${parsed_data.endpoint}\nresult: ${JSON.stringify(parsed_data.result)}`); break;