From 78d79f4a54c7c009b7c1cfe4ef7ae237e309abdd Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Thu, 6 Feb 2025 18:29:07 +0900 Subject: [PATCH 1/5] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20controller:=20offlin?= =?UTF-8?q?e=E6=99=82=E3=81=AE=E5=87=A6=E7=90=86=E3=82=92=E8=BF=BD?= =?UTF-8?q?=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/config.py | 12 ++ src-python/controller.py | 104 ++++++++++++++---- src-python/mainloop.py | 6 + src-python/model.py | 2 +- .../translation/translation_translator.py | 77 +++++++------ src-python/utils.py | 8 ++ 6 files changed, 155 insertions(+), 54 deletions(-) diff --git a/src-python/config.py b/src-python/config.py index 15d0aacb..ca9a360b 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -237,6 +237,15 @@ class Config: if isinstance(value, dict): self._SELECTABLE_TRANSLATION_ENGINE_STATUS = value + @property + def SELECTABLE_TRANSCRIPTION_ENGINE_STATUS(self): + return self._SELECTABLE_TRANSCRIPTION_ENGINE_STATUS + + @SELECTABLE_TRANSCRIPTION_ENGINE_STATUS.setter + def SELECTABLE_TRANSCRIPTION_ENGINE_STATUS(self, value): + if isinstance(value, dict): + self._SELECTABLE_TRANSCRIPTION_ENGINE_STATUS = value + # Save Json Data ## Main Window @property @@ -977,6 +986,9 @@ class Config: self._SELECTABLE_TRANSLATION_ENGINE_STATUS = {} for engine in self.SELECTABLE_TRANSLATION_ENGINE_LIST: self._SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = False + self._SELECTABLE_TRANSCRIPTION_ENGINE_STATUS = {} + for engine in self.SELECTABLE_TRANSCRIPTION_ENGINE_LIST: + self._SELECTABLE_TRANSCRIPTION_ENGINE_STATUS[engine] = False # Save Json Data ## Main Window diff --git a/src-python/controller.py b/src-python/controller.py index 95098bf8..715886c4 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -6,7 +6,7 @@ import re from device_manager import device_manager from config import config from model import model -from utils import removeLog, printLog, errorLogging +from utils import removeLog, printLog, errorLogging, isConnectedNetwork class Controller: def __init__(self) -> None: @@ -25,6 +25,18 @@ class Controller: self.run = run # response functions + def connectedNetwork(self) -> None: + self.run( + 200, + self.run_mapping["connected_network"], + ) + + def disconnectedNetwork(self) -> None: + self.run( + 200, + self.run_mapping["disconnected_network"], + ) + def updateMicHostList(self) -> None: self.run( 200, @@ -148,15 +160,25 @@ class Controller: ) def downloaded(self) -> None: - weight_type_dict = config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT - weight_type_dict[self.weight_type] = True - config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = weight_type_dict + if model.checkTranslatorCTranslate2ModelWeight(self.weight_type) is True: + weight_type_dict = config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT + weight_type_dict[self.weight_type] = True + config.SELECTABLE_CTRANSLATE2_WEIGHT_TYPE_DICT = weight_type_dict - self.run( - 200, - self.run_mapping["downloaded_ctranslate2_weight"], - self.weight_type, - ) + self.run( + 200, + self.run_mapping["downloaded_ctranslate2_weight"], + self.weight_type, + ) + else: + self.run( + 400, + self.run_mapping["error_ctranslate2_weight"], + { + "message":"CTranslate2 weight download error", + "data": None + }, + ) class DownloadWhisper: def __init__(self, run_mapping:dict, weight_type:str, run:Callable[[int, str, Any], None]) -> None: @@ -173,15 +195,25 @@ class Controller: ) def downloaded(self) -> None: - weight_type_dict = config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT - weight_type_dict[self.weight_type] = True - config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = weight_type_dict + if model.checkTranscriptionWhisperModelWeight(self.weight_type) is True: + weight_type_dict = config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT + weight_type_dict[self.weight_type] = True + config.SELECTABLE_WHISPER_WEIGHT_TYPE_DICT = weight_type_dict - self.run( - 200, - self.run_mapping["downloaded_whisper_weight"], - self.weight_type, - ) + self.run( + 200, + self.run_mapping["downloaded_whisper_weight"], + self.weight_type, + ) + else: + self.run( + 400, + self.run_mapping["error_whisper_weight"], + { + "message":"Whisper weight download error", + "data": None + }, + ) def micMessage(self, result: dict) -> None: message = result["text"] @@ -541,6 +573,11 @@ class Controller: self.updateTranslationEngineAndEngineList() return {"status":200, "result":config.SELECTED_TARGET_LANGUAGES} + @staticmethod + def getTranscriptionEngines(*args, **kwargs) -> dict: + engines = [key for key, value in config.SELECTABLE_TRANSCRIPTION_ENGINE_STATUS.items() if value is True] + return {"status":200, "result":engines} + @staticmethod def getSelectedTranscriptionEngine(*args, **kwargs) -> dict: return {"status":200, "result":config.SELECTED_TRANSCRIPTION_ENGINE} @@ -1665,6 +1702,11 @@ class Controller: def init(self, *args, **kwargs) -> None: removeLog() printLog("Start Initialization") + connected_network = isConnectedNetwork() + if connected_network is True: + self.connectedNetwork() + else: + self.disconnectedNetwork() printLog("Init Translation Engine Status") for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST: @@ -1680,9 +1722,6 @@ class Controller: auth_keys = config.AUTH_KEYS auth_keys[engine] = None config.AUTH_KEYS = auth_keys - case _: - config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = True - self.initializationProgress(1) # download CTranslate2 Model Weight @@ -1708,6 +1747,31 @@ class Controller: if isinstance(th_download_whisper, Thread): th_download_whisper.join() + for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST: + match engine: + case "CTranslate2": + if model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE) is True: + config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = True + else: + config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = False + case _: + if connected_network is True: + config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = True + else: + config.SELECTABLE_TRANSLATION_ENGINE_STATUS[engine] = False + + for engine in config.SELECTABLE_TRANSCRIPTION_ENGINE_LIST: + match engine: + case "Whisper": + if model.checkTranscriptionWhisperModelWeight(config.WHISPER_WEIGHT_TYPE) is True: + config.SELECTABLE_TRANSCRIPTION_ENGINE_STATUS[engine] = True + else: + config.SELECTABLE_TRANSCRIPTION_ENGINE_STATUS[engine] = False + case _: + if connected_network is True: + config.SELECTABLE_TRANSCRIPTION_ENGINE_STATUS[engine] = True + else: + config.SELECTABLE_TRANSCRIPTION_ENGINE_STATUS[engine] = False self.initializationProgress(2) # set Translation Engine diff --git a/src-python/mainloop.py b/src-python/mainloop.py index feff04f5..7c7ab51d 100644 --- a/src-python/mainloop.py +++ b/src-python/mainloop.py @@ -8,6 +8,9 @@ from controller import Controller from utils import printLog, printResponse, errorLogging, encodeBase64 run_mapping = { + "connected_network":"/run/connected_network", + "disconnected_network":"/run/disconnected_network", + "transcription_mic":"/run/transcription_send_mic_message", "transcription_speaker":"/run/transcription_receive_speaker_message", @@ -20,8 +23,10 @@ run_mapping = { "download_progress_ctranslate2_weight":"/run/download_progress_ctranslate2_weight", "downloaded_ctranslate2_weight":"/run/downloaded_ctranslate2_weight", + "error_ctranslate2_weight":"/run/error_ctranslate2_weight", "download_progress_whisper_weight":"/run/download_progress_whisper_weight", "downloaded_whisper_weight":"/run/downloaded_whisper_weight", + "error_whisper_weight":"/run/error_whisper_weight", "selected_mic_device":"/run/selected_mic_device", "selected_speaker_device":"/run/selected_speaker_device", @@ -79,6 +84,7 @@ mapping = { "/get/data/selected_target_languages": {"status": True, "variable":controller.getSelectedTargetLanguages}, "/set/data/selected_target_languages": {"status": True, "variable":controller.setSelectedTargetLanguages}, + "/get/data/transcription_engines": {"status": False, "variable":controller.getTranscriptionEngines}, "/get/data/selected_transcription_engine": {"status": False, "variable":controller.getSelectedTranscriptionEngine}, "/set/data/selected_transcription_engine": {"status": False, "variable":controller.setSelectedTranscriptionEngine}, diff --git a/src-python/model.py b/src-python/model.py index 8a18a838..19bbdd80 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -80,7 +80,7 @@ class Model: self.speaker_transcriber = None self.speaker_energy_recorder = None self.speaker_energy_plot_progressbar = None - + self.previous_send_message = "" self.previous_receive_message = "" self.translator = Translator() diff --git a/src-python/models/translation/translation_translator.py b/src-python/models/translation/translation_translator.py index fad96744..b9031c6c 100644 --- a/src-python/models/translation/translation_translator.py +++ b/src-python/models/translation/translation_translator.py @@ -1,6 +1,11 @@ from os import path as os_path from deepl import Translator as deepl_Translator -from translators import translate_text as other_web_Translator +try: + from translators import translate_text as other_web_Translator + ENABLE_TRANSLATORS = True +except Exception: + ENABLE_TRANSLATORS = False + from .translation_languages import translation_lang from .translation_utils import ctranslate2_weights @@ -18,6 +23,7 @@ class Translator(): self.ctranslate2_translator = None self.ctranslate2_tokenizer = None self.is_loaded_ctranslate2_model = False + self.is_enable_translators = ENABLE_TRANSLATORS def authenticationDeepLAuthKey(self, authkey): result = True @@ -97,42 +103,47 @@ class Translator(): source_language, target_language = self.getLanguageCode(translator_name, target_country, source_language, target_language) match translator_name: case "DeepL": - result = other_web_Translator( - query_text=message, - translator="deepl", - from_language=source_language, - to_language=target_language, - ) + if self.is_enable_translators is True: + result = other_web_Translator( + query_text=message, + translator="deepl", + from_language=source_language, + to_language=target_language, + ) case "DeepL_API": - if self.deepl_client is None: - result = False - else: - result = self.deepl_client.translate_text( - message, - source_lang=source_language, - target_lang=target_language, - ).text + if self.is_enable_translators is True: + if self.deepl_client is None: + result = False + else: + result = self.deepl_client.translate_text( + message, + source_lang=source_language, + target_lang=target_language, + ).text case "Google": - result = other_web_Translator( - query_text=message, - translator="google", - from_language=source_language, - to_language=target_language, - ) + if self.is_enable_translators is True: + result = other_web_Translator( + query_text=message, + translator="google", + from_language=source_language, + to_language=target_language, + ) case "Bing": - result = other_web_Translator( - query_text=message, - translator="bing", - from_language=source_language, - to_language=target_language, - ) + if self.is_enable_translators is True: + result = other_web_Translator( + query_text=message, + translator="bing", + from_language=source_language, + to_language=target_language, + ) case "Papago": - result = other_web_Translator( - query_text=message, - translator="papago", - from_language=source_language, - to_language=target_language, - ) + if self.is_enable_translators is True: + result = other_web_Translator( + query_text=message, + translator="papago", + from_language=source_language, + to_language=target_language, + ) case "CTranslate2": result = self.translateCTranslate2( message=message, diff --git a/src-python/utils.py b/src-python/utils.py index 67ef2859..e31a1f46 100644 --- a/src-python/utils.py +++ b/src-python/utils.py @@ -6,6 +6,14 @@ import logging from logging.handlers import RotatingFileHandler from ctranslate2 import get_supported_compute_types +import requests + +def isConnectedNetwork(url="http://www.google.com", timeout=3): + try: + response = requests.get(url, timeout=timeout) + return response.status_code == 200 + except requests.RequestException: + return False def getBestComputeType(device, device_index) -> str: compute_types = get_supported_compute_types(device, device_index) From 07723d495abec38dfa5dbd7c4ddaa2da50c39d10 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Fri, 7 Feb 2025 10:34:29 +0900 Subject: [PATCH 2/5] =?UTF-8?q?=F0=9F=90=9B[bugfix]=20controller:=20offlin?= =?UTF-8?q?e=E6=99=82=E3=81=AE=E5=87=A6=E7=90=86=E3=81=A7=E3=82=A8?= =?UTF-8?q?=E3=83=A9=E3=83=BC=E3=81=AB=E3=81=AA=E3=82=8B=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/controller.py | 51 +++++++++++++++++++++++----------------- src-python/mainloop.py | 1 - 2 files changed, 29 insertions(+), 23 deletions(-) diff --git a/src-python/controller.py b/src-python/controller.py index 715886c4..bc57ae1d 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -29,12 +29,14 @@ class Controller: self.run( 200, self.run_mapping["connected_network"], + True, ) def disconnectedNetwork(self) -> None: self.run( 200, - self.run_mapping["disconnected_network"], + self.run_mapping["connected_network"], + False, ) def updateMicHostList(self) -> None: @@ -526,7 +528,10 @@ class Controller: your_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"] for target_language in config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO].values(): if your_language["language"] == target_language["language"] and target_language["enable"] is True: - engines = ["CTranslate2"] + if config.SELECTABLE_TRANSLATION_ENGINE_STATUS["CTranslate2"] is True: + engines = ["CTranslate2"] + else: + engines = [] return {"status":200, "result":engines} @@ -1707,6 +1712,7 @@ class Controller: self.connectedNetwork() else: self.disconnectedNetwork() + printLog(f"Connected Network: {connected_network}") printLog("Init Translation Engine Status") for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST: @@ -1724,28 +1730,29 @@ class Controller: config.AUTH_KEYS = auth_keys self.initializationProgress(1) - # download CTranslate2 Model Weight - printLog("Download CTranslate2 Model Weight") - weight_type = config.CTRANSLATE2_WEIGHT_TYPE - th_download_ctranslate2 = None - if model.checkTranslatorCTranslate2ModelWeight(weight_type) is False: - th_download_ctranslate2 = Thread(target=self.downloadCtranslate2Weight, args=(weight_type, False)) - th_download_ctranslate2.daemon = True - th_download_ctranslate2.start() + if connected_network is True: + # download CTranslate2 Model Weight + printLog("Download CTranslate2 Model Weight") + weight_type = config.CTRANSLATE2_WEIGHT_TYPE + th_download_ctranslate2 = None + if model.checkTranslatorCTranslate2ModelWeight(weight_type) is False: + th_download_ctranslate2 = Thread(target=self.downloadCtranslate2Weight, args=(weight_type, False)) + th_download_ctranslate2.daemon = True + th_download_ctranslate2.start() - # download Whisper Model Weight - printLog("Download Whisper Model Weight") - weight_type = config.WHISPER_WEIGHT_TYPE - th_download_whisper = None - if model.checkTranscriptionWhisperModelWeight(weight_type) is False: - th_download_whisper = Thread(target=self.downloadWhisperWeight, args=(weight_type, False)) - th_download_whisper.daemon = True - th_download_whisper.start() + # download Whisper Model Weight + printLog("Download Whisper Model Weight") + weight_type = config.WHISPER_WEIGHT_TYPE + th_download_whisper = None + if model.checkTranscriptionWhisperModelWeight(weight_type) is False: + th_download_whisper = Thread(target=self.downloadWhisperWeight, args=(weight_type, False)) + th_download_whisper.daemon = True + th_download_whisper.start() - if isinstance(th_download_ctranslate2, Thread): - th_download_ctranslate2.join() - if isinstance(th_download_whisper, Thread): - th_download_whisper.join() + if isinstance(th_download_ctranslate2, Thread): + th_download_ctranslate2.join() + if isinstance(th_download_whisper, Thread): + th_download_whisper.join() for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST: match engine: diff --git a/src-python/mainloop.py b/src-python/mainloop.py index 7c7ab51d..67b5e36b 100644 --- a/src-python/mainloop.py +++ b/src-python/mainloop.py @@ -9,7 +9,6 @@ from utils import printLog, printResponse, errorLogging, encodeBase64 run_mapping = { "connected_network":"/run/connected_network", - "disconnected_network":"/run/disconnected_network", "transcription_mic":"/run/transcription_send_mic_message", "transcription_speaker":"/run/transcription_receive_speaker_message", From 0592695f1fc11eee3e9d23708468aca047c334c5 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Fri, 7 Feb 2025 17:57:27 +0900 Subject: [PATCH 3/5] [Update] Add network error notification. --- src-ui/logics/common/index.js | 3 ++- .../logics/common/useHandleNetworkConnection.js | 16 ++++++++++++++++ src-ui/logics/useReceiveRoutes.js | 5 ++++- 3 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 src-ui/logics/common/useHandleNetworkConnection.js diff --git a/src-ui/logics/common/index.js b/src-ui/logics/common/index.js index e63b28db..8f160826 100644 --- a/src-ui/logics/common/index.js +++ b/src-ui/logics/common/index.js @@ -9,4 +9,5 @@ export { useNotificationStatus } from "./useNotificationStatus"; export { useOpenFolder } from "./useOpenFolder"; export { useMessage } from "./useMessage"; export { useUpdateSoftware } from "./useUpdateSoftware"; -export { useVolume } from "./useVolume"; \ No newline at end of file +export { useVolume } from "./useVolume"; +export { useHandleNetworkConnection } from "./useHandleNetworkConnection"; \ No newline at end of file diff --git a/src-ui/logics/common/useHandleNetworkConnection.js b/src-ui/logics/common/useHandleNetworkConnection.js new file mode 100644 index 00000000..9c1d1f8c --- /dev/null +++ b/src-ui/logics/common/useHandleNetworkConnection.js @@ -0,0 +1,16 @@ +import { useNotificationStatus } from "@logics_common"; + +export const useHandleNetworkConnection = () => { + + const { showNotification_Error } = useNotificationStatus(); + + const handleNetworkConnection = (is_network_connected) => { + if (!is_network_connected) { + showNotification_Error("Network is not connected. Some of the function will not work."); + } + }; + + return { + handleNetworkConnection, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/useReceiveRoutes.js b/src-ui/logics/useReceiveRoutes.js index 030a199b..3e47507f 100644 --- a/src-ui/logics/useReceiveRoutes.js +++ b/src-ui/logics/useReceiveRoutes.js @@ -3,7 +3,7 @@ import { arrayToObject } from "@utils"; import { useNotificationStatus, - + useHandleNetworkConnection, useComputeMode, useInitProgress, @@ -178,6 +178,8 @@ export const useReceiveRoutes = () => { const { showNotification_Success, showNotification_Error } = useNotificationStatus(); + const { handleNetworkConnection } = useHandleNetworkConnection(); + const routes = { // Common "/run/feed_watchdog": () => {}, @@ -188,6 +190,7 @@ export const useReceiveRoutes = () => { "/run/open_filepath_logs": () => console.log("Opened Directory, Message Logs"), "/run/open_filepath_config_file": () => console.log("Opened Directory, Config File"), "/run/update_software_flag": updateIsSoftwareUpdateAvailable, + "/run/connected_network": handleNetworkConnection, // Main Page // Page Controls From 7746cffb0870c8eb4a165df0e03ee3116d49fb34 Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Sat, 8 Feb 2025 14:29:02 +0900 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=91=8D=EF=B8=8F[Update]=20Controller?= =?UTF-8?q?=20:=20AI=E3=83=A2=E3=83=87=E3=83=AB=E3=81=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=E5=8F=AF=E8=83=BD=E3=81=8B=E3=82=92=E9=80=9A=E7=9F=A5=E3=81=99?= =?UTF-8?q?=E3=82=8B=E3=82=A8=E3=83=B3=E3=83=89=E3=83=9D=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E3=83=88=E3=82=92=E8=BF=BD=E5=8A=A0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/controller.py | 20 ++++++++++++++++++++ src-python/mainloop.py | 1 + 2 files changed, 21 insertions(+) diff --git a/src-python/controller.py b/src-python/controller.py index bc57ae1d..8fb05825 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -39,6 +39,20 @@ class Controller: False, ) + def enableAiModels(self) -> None: + self.run( + 200, + self.run_mapping["enable_ai_models"], + True, + ) + + def disableAiModels(self) -> None: + self.run( + 200, + self.run_mapping["enable_ai_models"], + False, + ) + def updateMicHostList(self) -> None: self.run( 200, @@ -1754,6 +1768,12 @@ class Controller: if isinstance(th_download_whisper, Thread): th_download_whisper.join() + if (model.checkTranslatorCTranslate2ModelWeight(config.CTRANSLATE2_WEIGHT_TYPE) is False or + model.checkTranscriptionWhisperModelWeight(config.WHISPER_WEIGHT_TYPE) is False): + self.disableAiModels() + else: + self.enableAiModels() + for engine in config.SELECTABLE_TRANSLATION_ENGINE_LIST: match engine: case "CTranslate2": diff --git a/src-python/mainloop.py b/src-python/mainloop.py index 67b5e36b..e2dabbfc 100644 --- a/src-python/mainloop.py +++ b/src-python/mainloop.py @@ -9,6 +9,7 @@ from utils import printLog, printResponse, errorLogging, encodeBase64 run_mapping = { "connected_network":"/run/connected_network", + "enable_ai_models":"/run/enable_ai_models", "transcription_mic":"/run/transcription_send_mic_message", "transcription_speaker":"/run/transcription_receive_speaker_message", From 9daa50294e5c16ab06e9893d22be128419d75860 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Sat, 8 Feb 2025 21:58:29 +0900 Subject: [PATCH 5/5] [Update] Add VRCT Availability Status that if the status set to false, that is when ai models has not been detected by backend, can't use VRCT. --- src-ui/app/App.jsx | 16 +++++++--------- .../snackbar_controller/SnackbarController.jsx | 14 ++++++++++---- src-ui/logics/common/index.js | 3 ++- .../logics/common/useHandleNetworkConnection.js | 4 +++- src-ui/logics/common/useIsVrctAvailable.js | 10 ++++++++++ src-ui/logics/common/useNotificationStatus.js | 4 +++- src-ui/logics/useReceiveRoutes.js | 9 +++++++++ src-ui/store.js | 1 + 8 files changed, 45 insertions(+), 16 deletions(-) create mode 100644 src-ui/logics/common/useIsVrctAvailable.js diff --git a/src-ui/app/App.jsx b/src-ui/app/App.jsx index c36f7d31..86b5430d 100644 --- a/src-ui/app/App.jsx +++ b/src-ui/app/App.jsx @@ -1,9 +1,5 @@ import { useTranslation } from "react-i18next"; -import { - useWindow, -} from "@logics_common"; - import { KeyEventController, StartPythonController, @@ -23,9 +19,10 @@ import { UpdatingComponent } from "./updating_component/UpdatingComponent"; import { ModalController } from "./modal_controller/ModalController"; import { SnackbarController } from "./snackbar_controller/SnackbarController"; import styles from "./App.module.scss"; -import { useIsBackendReady, useIsSoftwareUpdating } from "@logics_common"; +import { useIsBackendReady, useIsSoftwareUpdating, useIsVrctAvailable, useWindow } from "@logics_common"; export const App = () => { + const { currentIsVrctAvailable } = useIsVrctAvailable(); const { currentIsBackendReady } = useIsBackendReady(); const { WindowGeometryController } = useWindow(); const { i18n } = useTranslation(); @@ -42,10 +39,12 @@ export const App = () => { - {currentIsBackendReady.data === false - ? - : + {(currentIsBackendReady.data === false || currentIsVrctAvailable.data === false) + ? + : } + + ); }; @@ -61,7 +60,6 @@ const Contents = () => { - : diff --git a/src-ui/app/snackbar_controller/SnackbarController.jsx b/src-ui/app/snackbar_controller/SnackbarController.jsx index dcc8f54a..0c116c09 100644 --- a/src-ui/app/snackbar_controller/SnackbarController.jsx +++ b/src-ui/app/snackbar_controller/SnackbarController.jsx @@ -17,17 +17,23 @@ export const SnackbarController = () => { [styles.is_error]: currentNotificationStatus.data.status === "error", }); + const settings = currentNotificationStatus.data; + + let hide_duration = 5000; + if (settings.options?.hide_duration === null) hide_duration = null; + if (Number(settings.options?.hide_duration)) hide_duration = settings.options.hide_duration; + return ( - {currentNotificationStatus.data.message} + {settings.message} diff --git a/src-ui/logics/common/index.js b/src-ui/logics/common/index.js index 8f160826..035f844b 100644 --- a/src-ui/logics/common/index.js +++ b/src-ui/logics/common/index.js @@ -10,4 +10,5 @@ export { useOpenFolder } from "./useOpenFolder"; export { useMessage } from "./useMessage"; export { useUpdateSoftware } from "./useUpdateSoftware"; export { useVolume } from "./useVolume"; -export { useHandleNetworkConnection } from "./useHandleNetworkConnection"; \ No newline at end of file +export { useHandleNetworkConnection } from "./useHandleNetworkConnection"; +export { useIsVrctAvailable } from "./useIsVrctAvailable"; \ No newline at end of file diff --git a/src-ui/logics/common/useHandleNetworkConnection.js b/src-ui/logics/common/useHandleNetworkConnection.js index 9c1d1f8c..4bdbd3bc 100644 --- a/src-ui/logics/common/useHandleNetworkConnection.js +++ b/src-ui/logics/common/useHandleNetworkConnection.js @@ -6,7 +6,9 @@ export const useHandleNetworkConnection = () => { const handleNetworkConnection = (is_network_connected) => { if (!is_network_connected) { - showNotification_Error("Network is not connected. Some of the function will not work."); + showNotification_Error("Network is not connected. Some of the function will not work.", { + hide_duration: 8000, + }); } }; diff --git a/src-ui/logics/common/useIsVrctAvailable.js b/src-ui/logics/common/useIsVrctAvailable.js new file mode 100644 index 00000000..dae8911e --- /dev/null +++ b/src-ui/logics/common/useIsVrctAvailable.js @@ -0,0 +1,10 @@ +import { useStore_IsVrctAvailable } from "@store"; + +export const useIsVrctAvailable = () => { + const { currentIsVrctAvailable, updateIsVrctAvailable } = useStore_IsVrctAvailable(); + + return { + currentIsVrctAvailable, + updateIsVrctAvailable, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/common/useNotificationStatus.js b/src-ui/logics/common/useNotificationStatus.js index f36c0c45..aa1ac703 100644 --- a/src-ui/logics/common/useNotificationStatus.js +++ b/src-ui/logics/common/useNotificationStatus.js @@ -5,12 +5,13 @@ export const useNotificationStatus = () => { const generateRandomKey = () => Math.random(); - const showNotification_Error = (message) => { + const showNotification_Error = (message, options = {}) => { updateNotificationStatus({ status: "error", is_open: true, key: generateRandomKey(), message: message, + options: options, }); }; @@ -20,6 +21,7 @@ export const useNotificationStatus = () => { is_open: true, key: generateRandomKey(), message: message, + options: options, }); }; diff --git a/src-ui/logics/useReceiveRoutes.js b/src-ui/logics/useReceiveRoutes.js index 3e47507f..d23f07e5 100644 --- a/src-ui/logics/useReceiveRoutes.js +++ b/src-ui/logics/useReceiveRoutes.js @@ -2,6 +2,7 @@ import { translator_status } from "@ui_configs"; import { arrayToObject } from "@utils"; import { + useIsVrctAvailable, useNotificationStatus, useHandleNetworkConnection, @@ -74,6 +75,7 @@ import { } from "@logics_configs"; export const useReceiveRoutes = () => { + const { updateIsVrctAvailable } = useIsVrctAvailable(); const { updateComputeMode } = useComputeMode(); const { updateInitProgress } = useInitProgress(); const { updateIsBackendReady } = useIsBackendReady(); @@ -184,6 +186,12 @@ export const useReceiveRoutes = () => { // Common "/run/feed_watchdog": () => {}, "/run/initialization_progress": updateInitProgress, + "/run/enable_ai_models": (is_ai_models_available) => { + if (is_ai_models_available === false) { + updateIsVrctAvailable(false); + showNotification_Error("AI models have not been detected. Check the network connection and restart VRCT (it will download automatically, normally).", { hide_duration: null }); + } + }, "/get/data/compute_mode": updateComputeMode, "/get/data/main_window_geometry": restoreWindowGeometry, "/set/data/main_window_geometry": () => {}, @@ -481,6 +489,7 @@ export const useReceiveRoutes = () => { "/get/data/speaker_no_speech_prob": ()=>{}, // Not implemented on UI yet "/get/data/convert_message_to_romaji": ()=>{}, // Not implemented on UI yet "/get/data/convert_message_to_hiragana": ()=>{}, // Not implemented on UI yet + "/get/data/transcription_engines": ()=>{}, // Not implemented on UI yet. (if ai_models has not been detected, this will be blank array[]. if the ai_models are ok but just network has not connected, it'l be only ["Whisper"]) }; const error_routes = { diff --git a/src-ui/store.js b/src-ui/store.js index 3f8391f0..17c74d20 100644 --- a/src-ui/store.js +++ b/src-ui/store.js @@ -106,6 +106,7 @@ const createAtomWithHook = (initialValue, base_name, options) => { // Common export const { atomInstance: Atom_IsBackendReady, useHook: useStore_IsBackendReady } = createAtomWithHook(false, "IsBackendReady"); +export const { atomInstance: Atom_IsVrctAvailable, useHook: useStore_IsVrctAvailable } = createAtomWithHook(true, "IsVrctAvailable"); export const { atomInstance: Atom_ComputeMode, useHook: useStore_ComputeMode } = createAtomWithHook("", "ComputeMode"); export const { atomInstance: Atom_IsOpenedConfigPage, useHook: useStore_IsOpenedConfigPage } = createAtomWithHook(false, "IsOpenedConfigPage"); export const { atomInstance: Atom_MainFunctionsStateMemory, useHook: useStore_MainFunctionsStateMemory } = createAtomWithHook({
{currentNotificationStatus.data.message}
{settings.message}