diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 00000000..ff2362a1 --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,92 @@ +name: Release VRCT + +on: + push: + tags: + - 'v*' # タグが 'v' で始まる場合にトリガー (例: v1.0.0) + +jobs: + release: + name: Build VRCT + runs-on: windows-latest + permissions: + contents: write + steps: + - name: Checkout code + uses: actions/checkout@v4 + + - name: Set up Node.js + uses: actions/setup-node@v4 + with: + node-version: '22.15.0' + + - name: Set up Python + uses: actions/setup-python@v5 + with: + python-version: '3.11' + + - name: Set up Rust + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + profile: minimal + override: true + + - name: Install dependencies + run: npm install + + - name: Setup Python environment + run: npm run setup-python + + - name: Install Python script dependencies + run: pip install tqdm + + - name: Build and package + run: npm run release-all + + - name: Get version from tag + id: get_version + shell: pwsh + run: | + $TAG_WITH_V = $env:GITHUB_REF -replace "^refs/tags/", "" + $VERSION_NUM = $TAG_WITH_V -replace "^v", "" + echo "VERSION=$VERSION_NUM" | Out-File -FilePath $env:GITHUB_ENV -Encoding utf8 -Append + + - name: Upload to Hugging Face Hub + env: + HF_TOKEN: ${{ secrets.HF_TOKEN }} + shell: pwsh # Explicitly use PowerShell for file operations + run: | + pip install huggingface_hub + + $UPLOAD_DIR = "./hf_upload_temp" + New-Item -ItemType Directory -Force -Path $UPLOAD_DIR + Copy-Item -Path ./VRCT.zip -Destination "$UPLOAD_DIR/VRCT.zip" + Copy-Item -Path ./VRCT_cuda.zip -Destination "$UPLOAD_DIR/VRCT_cuda.zip" + + huggingface-cli upload ms-software/VRCT $UPLOAD_DIR . --repo-type model --commit-message "👍️[Update] ${{ env.VERSION }} Release" + + huggingface-cli tag ms-software/VRCT ${{ github.ref_name }} --repo-type model --message "Release ${{ github.ref_name }}" + + Remove-Item -Recurse -Force $UPLOAD_DIR + + - name: Create GitHub Release + id: create_release + uses: actions/create-release@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + tag_name: ${{ github.ref }} + release_name: ${{ env.VERSION }} + draft: false + prerelease: false + + - name: Upload Release Asset (NSIS Installer) + uses: actions/upload-release-asset@v1 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + with: + upload_url: ${{ steps.create_release.outputs.upload_url }} + asset_path: ./src-tauri/target/release/bundle/nsis/VRCT_${{ env.VERSION }}_x64-setup.exe + asset_name: VRCT_${{ env.VERSION }}_x64-setup.exe + asset_content_type: application/octet-stream diff --git a/locales/en.yml b/locales/en.yml index 5138f697..05e5601d 100644 --- a/locales/en.yml +++ b/locales/en.yml @@ -50,7 +50,6 @@ main_page: received: "Received" system: "System" - show_resend_button: "Show Resend Button" resend_button_on_hover_desc: "Press And Hold To Send" state_text_enabled: "Enabled" @@ -120,6 +119,9 @@ config_page: hide: "Hide (Use Enter key to send)" show: "Show" show_and_disable_enter_key: "Show and disable sending using the Enter key." + show_resend_button: + label: "Show Resend Button" + desc: "When hovering over a sent message log, the resend button appears. Click to edit, long press to resend." font_family: label: "Font Family" ui_language: @@ -267,6 +269,9 @@ config_page: websocket_port: label: "WebSocket Port" + notifications: + save_success: "Settings have been saved." + plugin_notifications: downloading: Downloading the plugin. downloaded_success: Downloaded successfully. @@ -277,6 +282,7 @@ plugin_notifications: updated_error: Update failed. disabled_out_of_support: The plugin has been disabled. It's not supported on this VRCT version. + disabled_due_to_an_error: "An error was detected while running the plugin. Please report this to the plugin developer." is_enabled: The plugin has enabled. is_disabled: The plugin has disabled. \ No newline at end of file diff --git a/locales/ja.yml b/locales/ja.yml index a9a6901b..d36bec89 100644 --- a/locales/ja.yml +++ b/locales/ja.yml @@ -50,7 +50,6 @@ main_page: received: "受信" system: "システム" - show_resend_button: "再送信ボタンを表示する" resend_button_on_hover_desc: "長押しで送信" state_text_enabled: "有効" @@ -120,6 +119,9 @@ config_page: hide: "非表示 (エンターキーを使って送信)" show: "表示" show_and_disable_enter_key: "表示し、エンターキーでの送信を無効" + show_resend_button: + label: "再送信ボタンを表示する" + desc: "送信済メッセージログにマウスホバーすると、再送信ボタンが表示されます。クリックで編集モード、長押しで再送信します。" font_family: label: "使用フォント" ui_language: @@ -267,6 +269,9 @@ config_page: websocket_port: label: "WebSocket Port" + notifications: + save_success: "設定を保存しました。" + plugin_notifications: downloading: プラグインをダウンロード中。 downloaded_success: プラグインのダウンロードが完了しました。 @@ -277,6 +282,7 @@ plugin_notifications: updated_error: プラグインのアップデートに失敗しました。 disabled_out_of_support: 現在のバージョンとの互換性がありません。プラグインを無効にしました。 + disabled_due_to_an_error: プラグイン実行中にエラーを検知しました。プラグイン開発者に報告してください。 is_enabled: プラグインを有効にしました。 is_disabled: プラグインを無効にしました。 \ No newline at end of file diff --git a/locales/ko.yml b/locales/ko.yml index 139f41a7..39df6d4a 100644 --- a/locales/ko.yml +++ b/locales/ko.yml @@ -47,7 +47,6 @@ main_page: received: "수신" system: "시스템" - show_resend_button: resend_button_on_hover_desc: state_text_enabled: "Enabled" diff --git a/locales/useI18n.js b/locales/useI18n.js new file mode 100644 index 00000000..d006367c --- /dev/null +++ b/locales/useI18n.js @@ -0,0 +1,11 @@ +// To avoid a name conflict with our own `useTranslation` function, +// rename the one from `react-i18next` to `useI18n`. +// This is aliased via `vite.config.js`, so it can be imported using `@useI18n`. +// Example: +// import { useI18n } from "@useI18n"; +// +// export const useTranslation = () => { +// const { t } = useI18n(); +// ... +// }; +export { useTranslation as useI18n } from "react-i18next"; \ No newline at end of file diff --git a/locales/zh-Hans.yml b/locales/zh-Hans.yml index 0a13c7f8..dd1dafc7 100644 --- a/locales/zh-Hans.yml +++ b/locales/zh-Hans.yml @@ -47,7 +47,6 @@ main_page: received: "接受" system: "系统" - show_resend_button: resend_button_on_hover_desc: state_text_enabled: "启用" diff --git a/locales/zh-Hant.yml b/locales/zh-Hant.yml index 4fd2fce4..08210a7d 100644 --- a/locales/zh-Hant.yml +++ b/locales/zh-Hant.yml @@ -47,7 +47,6 @@ main_page: received: "已接收" system: "系統" - show_resend_button: resend_button_on_hover_desc: state_text_enabled: "啟用" diff --git a/package-lock.json b/package-lock.json index f131d4a8..cbe6e142 100644 --- a/package-lock.json +++ b/package-lock.json @@ -28,6 +28,7 @@ "react-error-boundary": "5.0.0", "react-i18next": "15.5.1", "react-resizable-layout": "0.7.2", + "react-toastify": "11.0.5", "sass": "1.79.4", "semver": "7.7.1" }, @@ -5534,6 +5535,19 @@ "react-dom": ">=17.0.0" } }, + "node_modules/react-toastify": { + "version": "11.0.5", + "resolved": "https://registry.npmjs.org/react-toastify/-/react-toastify-11.0.5.tgz", + "integrity": "sha512-EpqHBGvnSTtHYhCPLxML05NLY2ZX0JURbAdNYa6BUkk+amz4wbKBQvoKQAB0ardvSarUBuY4Q4s1sluAzZwkmA==", + "license": "MIT", + "dependencies": { + "clsx": "^2.1.1" + }, + "peerDependencies": { + "react": "^18 || ^19", + "react-dom": "^18 || ^19" + } + }, "node_modules/react-transition-group": { "version": "4.4.5", "resolved": "https://registry.npmjs.org/react-transition-group/-/react-transition-group-4.4.5.tgz", diff --git a/package.json b/package.json index a2d9030f..c15471e5 100644 --- a/package.json +++ b/package.json @@ -43,6 +43,7 @@ "react-error-boundary": "5.0.0", "react-i18next": "15.5.1", "react-resizable-layout": "0.7.2", + "react-toastify": "11.0.5", "sass": "1.79.4", "semver": "7.7.1" }, diff --git a/src-python/config.py b/src-python/config.py index 64c09440..a9b2785a 100644 --- a/src-python/config.py +++ b/src-python/config.py @@ -407,6 +407,29 @@ class Config: self._MESSAGE_BOX_RATIO = value self.saveConfig(inspect.currentframe().f_code.co_name, value, immediate_save=True) + @property + @json_serializable('SEND_MESSAGE_BUTTON_TYPE') + def SEND_MESSAGE_BUTTON_TYPE(self): + return self._SEND_MESSAGE_BUTTON_TYPE + + @SEND_MESSAGE_BUTTON_TYPE.setter + def SEND_MESSAGE_BUTTON_TYPE(self, value): + if isinstance(value, str): + if value in self.SEND_MESSAGE_BUTTON_TYPE_LIST: + self._SEND_MESSAGE_BUTTON_TYPE = value + self.saveConfig(inspect.currentframe().f_code.co_name, value) + + @property + @json_serializable('SHOW_RESEND_BUTTON') + def SHOW_RESEND_BUTTON(self): + return self._SHOW_RESEND_BUTTON + + @SHOW_RESEND_BUTTON.setter + def SHOW_RESEND_BUTTON(self, value): + if isinstance(value, bool): + self._SHOW_RESEND_BUTTON = value + self.saveConfig(inspect.currentframe().f_code.co_name, value) + @property @json_serializable('FONT_FAMILY') def FONT_FAMILY(self): @@ -804,18 +827,6 @@ class Config: self._SEND_ONLY_TRANSLATED_MESSAGES = value self.saveConfig(inspect.currentframe().f_code.co_name, value) - @property - @json_serializable('SEND_MESSAGE_BUTTON_TYPE') - def SEND_MESSAGE_BUTTON_TYPE(self): - return self._SEND_MESSAGE_BUTTON_TYPE - - @SEND_MESSAGE_BUTTON_TYPE.setter - def SEND_MESSAGE_BUTTON_TYPE(self, value): - if isinstance(value, str): - if value in self.SEND_MESSAGE_BUTTON_TYPE_LIST: - self._SEND_MESSAGE_BUTTON_TYPE = value - self.saveConfig(inspect.currentframe().f_code.co_name, value) - @property @json_serializable('OVERLAY_SMALL_LOG') def OVERLAY_SMALL_LOG(self): @@ -989,7 +1000,7 @@ class Config: def init_config(self): # Read Only - self._VERSION = "3.2.0" + self._VERSION = "3.2.1" if getattr(sys, 'frozen', False): self._PATH_LOCAL = os_path.dirname(sys.executable) else: @@ -1090,6 +1101,8 @@ class Config: self._UI_SCALING = 100 self._TEXTBOX_UI_SCALING = 100 self._MESSAGE_BOX_RATIO = 10 + self._SEND_MESSAGE_BUTTON_TYPE = "show" + self._SHOW_RESEND_BUTTON = False self._FONT_FAMILY = "Yu Gothic UI" self._UI_LANGUAGE = "en" self._MAIN_WINDOW_GEOMETRY = { @@ -1137,7 +1150,6 @@ class Config: self._WHISPER_WEIGHT_TYPE = "base" self._AUTO_CLEAR_MESSAGE_BOX = True self._SEND_ONLY_TRANSLATED_MESSAGES = False - self._SEND_MESSAGE_BUTTON_TYPE = "show" self._OVERLAY_SMALL_LOG = False self._OVERLAY_SMALL_LOG_SETTINGS = { "x_pos": 0.0, diff --git a/src-python/controller.py b/src-python/controller.py index 89a07d3a..f0c3d55b 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -259,17 +259,44 @@ class Controller: elif config.ENABLE_TRANSLATION is False: pass else: - translation, success = model.getInputTranslate(message, source_language=language) - if all(success) is not True: - self.changeToCTranslate2Process() - self.run( - 400, - self.run_mapping["error_translation_engine"], - { - "message":"Translation engine limit error", - "data": None - }, - ) + try: + translation, success = model.getInputTranslate(message, source_language=language) + if all(success) is not True: + self.changeToCTranslate2Process() + self.run( + 400, + self.run_mapping["error_translation_engine"], + { + "message":"Translation engine limit error", + "data": None + }, + ) + except Exception as e: + # VRAM不足エラーの検出 + is_vram_error, error_message = model.detectVRAMError(e) + if is_vram_error: + self.run( + 400, + self.run_mapping["error_translation_mic_vram_overflow"], + { + "message":"VRAM out of memory during translation of mic", + "data": error_message + }, + ) + # 翻訳機能をOFFにする + self.setDisableTranslation() + self.run( + 400, + self.run_mapping["enable_translation"], + { + "message":"Translation disabled due to VRAM overflow", + "data": False + }, + ) + return + else: + # その他のエラーは通常通り処理 + raise if config.CONVERT_MESSAGE_TO_ROMAJI is True or config.CONVERT_MESSAGE_TO_HIRAGANA is True: if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese": @@ -295,6 +322,27 @@ class Controller: "transliteration":transliteration }) + if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: + if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True: + if len(translation) > 0: + overlay_image = model.createOverlayImageLargeLog( + "send", + None, + None, + translation, + config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO] + ) + model.updateOverlayLargeLog(overlay_image) + else: + overlay_image = model.createOverlayImageLargeLog( + "send", + message, + config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"], + translation, + config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO] + ) + model.updateOverlayLargeLog(overlay_image) + if model.checkWebSocketServerAlive() is True: model.websocketSendMessage( { @@ -308,16 +356,8 @@ class Controller: ) if config.LOGGER_FEATURE is True: - if len(translation) > 0: - translation = " (" + "/".join(translation) + ")" - model.logger.info(f"[SENT] {message}{translation}") - - if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: - if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0: - overlay_image = model.createOverlayImageLargeLog("send", translation[0], "") - else: - overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "") - model.updateOverlayLargeLog(overlay_image) + translation_text = f" ({'/'.join(translation)})" if translation else "" + model.logger.info(f"[SENT] {message}{translation_text}") def speakerMessage(self, result:dict) -> None: message = result["text"] @@ -346,17 +386,44 @@ class Controller: elif config.ENABLE_TRANSLATION is False: pass else: - translation, success = model.getOutputTranslate(message, source_language=language) - if all(success) is not True: - self.changeToCTranslate2Process() - self.run( - 400, - self.run_mapping["error_translation_engine"], - { - "message":"Translation engine limit error", - "data": None - }, - ) + try: + translation, success = model.getOutputTranslate(message, source_language=language) + if all(success) is not True: + self.changeToCTranslate2Process() + self.run( + 400, + self.run_mapping["error_translation_engine"], + { + "message":"Translation engine limit error", + "data": None + }, + ) + except Exception as e: + # VRAM不足エラーの検出 + is_vram_error, error_message = model.detectVRAMError(e) + if is_vram_error: + self.run( + 400, + self.run_mapping["error_translation_speaker_vram_overflow"], + { + "message":"VRAM out of memory during translation of speaker", + "data": error_message + }, + ) + # 翻訳機能をOFFにする + self.setDisableTranslation() + self.run( + 400, + self.run_mapping["enable_translation"], + { + "message":"Translation disabled due to VRAM overflow", + "data": False + }, + ) + return + else: + # その他のエラーは通常通り処理 + raise if config.CONVERT_MESSAGE_TO_ROMAJI is True or config.CONVERT_MESSAGE_TO_HIRAGANA is True: if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese": @@ -364,18 +431,43 @@ class Controller: if config.ENABLE_TRANSCRIPTION_RECEIVE is True: if config.OVERLAY_SMALL_LOG is True and model.overlay.initialized is True: - if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0: - overlay_image = model.createOverlayImageSmallLog(translation[0], "") + if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True: + if len(translation) > 0: + overlay_image = model.createOverlayImageSmallLog( + None, + None, + translation, + config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO], + ) + model.updateOverlaySmallLog(overlay_image) else: - overlay_image = model.createOverlayImageSmallLog(message, translation[0] if len(translation) > 0 else "") - model.updateOverlaySmallLog(overlay_image) + overlay_image = model.createOverlayImageSmallLog( + message, + language, + translation, + config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO], + ) + model.updateOverlaySmallLog(overlay_image) if config.OVERLAY_LARGE_LOG is True and model.overlay.initialized is True: - if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0: - overlay_image = model.createOverlayImageLargeLog("receive", translation[0], "") + if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True: + if len(translation) > 0: + overlay_image = model.createOverlayImageLargeLog( + "receive", + None, + None, + translation, + ) + model.updateOverlayLargeLog(overlay_image) else: - overlay_image = model.createOverlayImageLargeLog("receive", message, translation[0] if len(translation) > 0 else "") - model.updateOverlayLargeLog(overlay_image) + overlay_image = model.createOverlayImageLargeLog( + "receive", + message, + language, + translation, + config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO] + ) + model.updateOverlayLargeLog(overlay_image) if config.SEND_RECEIVED_MESSAGE_TO_VRC is True: osc_message = self.messageFormatter("RECEIVED", translation, [message]) @@ -404,9 +496,8 @@ class Controller: ) if config.LOGGER_FEATURE is True: - if len(translation) > 0: - translation = " (" + "/".join(translation) + ")" - model.logger.info(f"[RECEIVED] {message}{translation}") + translation_text = f" ({'/'.join(translation)})" if translation else "" + model.logger.info(f"[RECEIVED] {message}{translation_text}") def chatMessage(self, data) -> None: id = data["id"] @@ -417,26 +508,62 @@ class Controller: if config.ENABLE_TRANSLATION is False: pass else: - if config.USE_EXCLUDE_WORDS is True: - replacement_message, replacement_dict = self.replaceExclamationsWithRandom(message) - translation, success = model.getInputTranslate(replacement_message) + try: + if config.USE_EXCLUDE_WORDS is True: + replacement_message, replacement_dict = self.replaceExclamationsWithRandom(message) + translation, success = model.getInputTranslate(replacement_message) - message = self.removeExclamations(message) - for i in range(len(translation)): - translation[i] = self.restoreText(translation[i], replacement_dict) - else: - translation, success = model.getInputTranslate(message) + message = self.removeExclamations(message) + for i in range(len(translation)): + translation[i] = self.restoreText(translation[i], replacement_dict) + else: + translation, success = model.getInputTranslate(message) - if all(success) is not True: - self.changeToCTranslate2Process() - self.run( - 400, - self.run_mapping["error_translation_engine"], - { - "message":"Translation engine limit error", - "data": None - }, - ) + if all(success) is not True: + self.changeToCTranslate2Process() + self.run( + 400, + self.run_mapping["error_translation_engine"], + { + "message":"Translation engine limit error", + "data": None + }, + ) + except Exception as e: + # VRAM不足エラーの検出 + is_vram_error, error_message = model.detectVRAMError(e) + if is_vram_error: + self.run( + 400, + self.run_mapping["error_translation_chat_vram_overflow"], + { + "message":"VRAM out of memory during translation of chat", + "data": error_message + }, + ) + # 翻訳機能をOFFにする + self.setDisableTranslation() + self.run( + 400, + self.run_mapping["enable_translation"], + { + "message":"Translation disabled due to VRAM overflow", + "data": False + }, + ) + # エラー時は翻訳なしで返す + return {"status":200, + "result": + { + "id":id, + "message":message, + "translation":[], + "transliteration":[], + }, + } + else: + # その他のエラーは通常通り処理 + raise if config.CONVERT_MESSAGE_TO_ROMAJI is True or config.CONVERT_MESSAGE_TO_HIRAGANA is True: if config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] == "Japanese": @@ -454,11 +581,25 @@ class Controller: model.oscSendMessage(osc_message) if config.OVERLAY_LARGE_LOG is True: - if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True and len(translation) > 0: - overlay_image = model.createOverlayImageLargeLog("send", translation[0], "") + if config.OVERLAY_SHOW_ONLY_TRANSLATED_MESSAGES is True: + if len(translation) > 0: + overlay_image = model.createOverlayImageLargeLog( + "send", + None, + None, + translation, + config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO], + ) + model.updateOverlayLargeLog(overlay_image) else: - overlay_image = model.createOverlayImageLargeLog("send", message, translation[0] if len(translation) > 0 else "") - model.updateOverlayLargeLog(overlay_image) + overlay_image = model.createOverlayImageLargeLog( + "send", + message, + config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"], + translation, + config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO], + ) + model.updateOverlayLargeLog(overlay_image) if model.checkWebSocketServerAlive() is True: model.websocketSendMessage( @@ -472,10 +613,8 @@ class Controller: } ) - # update textbox message log (Chat) if config.LOGGER_FEATURE is True: - if len(translation) > 0: - translation_text = " (" + "/".join(translation) + ")" + translation_text = f" ({'/'.join(translation)})" if translation else "" model.logger.info(f"[CHAT] {message}{translation_text}") return {"status":200, @@ -514,8 +653,21 @@ class Controller: @staticmethod def setSelectedTranslationComputeDevice(device:str, *args, **kwargs) -> dict: printLog("setSelectedTranslationComputeDevice", device) + pre_device = config.SELECTED_TRANSLATION_COMPUTE_DEVICE config.SELECTED_TRANSLATION_COMPUTE_DEVICE = device - model.changeTranslatorCTranslate2Model() + try: + model.changeTranslatorCTranslate2Model() + except Exception as e: + # VRAM不足エラーの検出(デバイス切り替え時) + is_vram_error, error_message = model.detectVRAMError(e) + if is_vram_error: + # 前のデバイス設定に戻す + printLog("VRAM error detected, reverting device setting") + config.SELECTED_TRANSLATION_COMPUTE_DEVICE = pre_device + model.changeTranslatorCTranslate2Model() + else: + # その他のエラーは通常通り処理 + errorLogging() return {"status":200,"result":config.SELECTED_TRANSLATION_COMPUTE_DEVICE} @staticmethod @@ -729,6 +881,29 @@ class Controller: config.MESSAGE_BOX_RATIO = data return {"status":200, "result":config.MESSAGE_BOX_RATIO} + @staticmethod + def getSendMessageButtonType(*args, **kwargs) -> dict: + return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE} + + @staticmethod + def setSendMessageButtonType(data, *args, **kwargs) -> dict: + config.SEND_MESSAGE_BUTTON_TYPE = data + return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE} + + @staticmethod + def getShowResendButton(*args, **kwargs) -> dict: + return {"status":200, "result":config.SHOW_RESEND_BUTTON} + + @staticmethod + def setEnableShowResendButton(*args, **kwargs) -> dict: + config.SHOW_RESEND_BUTTON = True + return {"status":200, "result":config.SHOW_RESEND_BUTTON} + + @staticmethod + def setDisableShowResendButton(*args, **kwargs) -> dict: + config.SHOW_RESEND_BUTTON = False + return {"status":200, "result":config.SHOW_RESEND_BUTTON} + @staticmethod def getFontFamily(*args, **kwargs) -> dict: return {"status":200, "result":config.FONT_FAMILY} @@ -1153,8 +1328,12 @@ class Controller: if model.getIsOscQueryEnabled() is True: self.enableOscQuery() else: - self.setDisableVrcMicMuteSync() - self.disableOscQuery() + mute_sync_info_flag = False + if config.VRC_MIC_MUTE_SYNC is True: + self.setDisableVrcMicMuteSync() + mute_sync_info_flag = True + self.disableOscQuery(mute_sync_info=mute_sync_info_flag) + response = {"status":200, "result":config.OSC_IP_ADDRESS} except Exception: model.setOscIpAddress(config.OSC_IP_ADDRESS) @@ -1299,15 +1478,6 @@ class Controller: config.SEND_ONLY_TRANSLATED_MESSAGES = False return {"status":200, "result":config.SEND_ONLY_TRANSLATED_MESSAGES} - @staticmethod - def getSendMessageButtonType(*args, **kwargs) -> dict: - return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE} - - @staticmethod - def setSendMessageButtonType(data, *args, **kwargs) -> dict: - config.SEND_MESSAGE_BUTTON_TYPE = data - return {"status":200, "result":config.SEND_MESSAGE_BUTTON_TYPE} - @staticmethod def getOverlaySmallLog(*args, **kwargs) -> dict: return {"status":200, "result":config.OVERLAY_SMALL_LOG} @@ -1628,8 +1798,35 @@ class Controller: while self.device_access_status is False: sleep(1) self.device_access_status = False - model.startMicTranscript(self.micMessage) - self.device_access_status = True + try: + model.startMicTranscript(self.micMessage) + except Exception as e: + # VRAM不足エラーの検出 + is_vram_error, error_message = model.detectVRAMError(e) + if is_vram_error: + self.run( + 400, + self.run_mapping["error_transcription_mic_vram_overflow"], + { + "message":"VRAM out of memory during mic transcription", + "data": error_message + }, + ) + # ここでマイクの音声認識を停止 + self.stopTranscriptionSendMessage() + self.run( + 400, + self.run_mapping["enable_transcription_send"], + { + "message":"Transcription send disabled due to VRAM overflow", + "data": False + }, + ) + else: + # その他のエラーは通常通り処理 + errorLogging() + finally: + self.device_access_status = True @staticmethod def stopTranscriptionSendMessage() -> None: @@ -1650,8 +1847,35 @@ class Controller: while self.device_access_status is False: sleep(1) self.device_access_status = False - model.startSpeakerTranscript(self.speakerMessage) - self.device_access_status = True + try: + model.startSpeakerTranscript(self.speakerMessage) + except Exception as e: + # VRAM不足エラーの検出 + is_vram_error, error_message = model.detectVRAMError(e) + if is_vram_error: + self.run( + 400, + self.run_mapping["error_transcription_speaker_vram_overflow"], + { + "message":"VRAM out of memory during speaker transcription", + "data": error_message + }, + ) + # ここでスピーカーの音声認識を停止 + self.stopTranscriptionReceiveMessage() + self.run( + 400, + self.run_mapping["enable_transcription_receive"], + { + "message":"Transcription receive disabled due to VRAM overflow", + "data": False + }, + ) + else: + # その他のエラーは通常通り処理 + errorLogging() + finally: + self.device_access_status = True @staticmethod def stopTranscriptionReceiveMessage() -> None: @@ -1933,12 +2157,13 @@ class Controller: } ) - def disableOscQuery(self): + def disableOscQuery(self, mute_sync_info:bool=False): + disabled_functions = [] + if mute_sync_info is True: + disabled_functions.append("vrc_mic_mute_sync") self.run(200, self.run_mapping["enable_osc_query"], { "data": False, - "disabled_functions": [ - "vrc_mic_mute_sync", - ] + "disabled_functions": disabled_functions }) def init(self, *args, **kwargs) -> None: @@ -2055,13 +2280,15 @@ class Controller: osc_query_enabled = model.getIsOscQueryEnabled() if osc_query_enabled is True: self.enableOscQuery() + if config.VRC_MIC_MUTE_SYNC is True: + self.setEnableVrcMicMuteSync() else: # OSC Query is disabled, so disable VRC some features - config.VRC_MIC_MUTE_SYNC = False - self.disableOscQuery() - - if config.VRC_MIC_MUTE_SYNC is True: - self.setEnableVrcMicMuteSync() + mute_sync_info_flag = False + if config.VRC_MIC_MUTE_SYNC is True: + self.setDisableVrcMicMuteSync() + mute_sync_info_flag = True + self.disableOscQuery(mute_sync_info=mute_sync_info_flag) # init Auto device selection printLog("Init Device Manager") diff --git a/src-python/mainloop.py b/src-python/mainloop.py index 00bc8cb5..61040535 100644 --- a/src-python/mainloop.py +++ b/src-python/mainloop.py @@ -11,6 +11,10 @@ from utils import printLog, printResponse, errorLogging, encodeBase64 # noqa: E4 logging.getLogger("huggingface_hub").setLevel(logging.ERROR) run_mapping = { + "enable_translation":"/run/enable_translation", + "enable_transcription_send":"/run/enable_transcription_send", + "enable_transcription_receive":"/run/enable_transcription_receive", + "connected_network":"/run/connected_network", "enable_ai_models":"/run/enable_ai_models", @@ -22,6 +26,13 @@ run_mapping = { "error_device":"/run/error_device", "error_translation_engine":"/run/error_translation_engine", + + "error_translation_chat_vram_overflow":"/run/error_translation_chat_vram_overflow", + "error_translation_mic_vram_overflow":"/run/error_translation_mic_vram_overflow", + "error_translation_speaker_vram_overflow":"/run/error_translation_speaker_vram_overflow", + "error_transcription_mic_vram_overflow":"/run/error_transcription_mic_vram_overflow", + "error_transcription_speaker_vram_overflow":"/run/error_transcription_speaker_vram_overflow", + "word_filter":"/run/word_filter", "download_progress_ctranslate2_weight":"/run/download_progress_ctranslate2_weight", @@ -120,6 +131,13 @@ mapping = { "/get/data/message_box_ratio": {"status": True, "variable":controller.getMessageBoxRatio}, "/set/data/message_box_ratio": {"status": True, "variable":controller.setMessageBoxRatio}, + "/get/data/send_message_button_type": {"status": True, "variable":controller.getSendMessageButtonType}, + "/set/data/send_message_button_type": {"status": True, "variable":controller.setSendMessageButtonType}, + + "/get/data/show_resend_button": {"status": True, "variable":controller.getShowResendButton}, + "/set/enable/show_resend_button": {"status": True, "variable":controller.setEnableShowResendButton}, + "/set/disable/show_resend_button": {"status": True, "variable":controller.setDisableShowResendButton}, + "/get/data/font_family": {"status": True, "variable":controller.getFontFamily}, "/set/data/font_family": {"status": True, "variable":controller.setFontFamily}, @@ -275,9 +293,6 @@ mapping = { "/set/enable/send_only_translated_messages": {"status": True, "variable":controller.setEnableSendOnlyTranslatedMessages}, "/set/disable/send_only_translated_messages": {"status": True, "variable":controller.setDisableSendOnlyTranslatedMessages}, - "/get/data/send_message_button_type": {"status": True, "variable":controller.getSendMessageButtonType}, - "/set/data/send_message_button_type": {"status": True, "variable":controller.setSendMessageButtonType}, - "/get/data/logger_feature": {"status": True, "variable":controller.getLoggerFeature}, "/set/enable/logger_feature": {"status": True, "variable":controller.setEnableLoggerFeature}, "/set/disable/logger_feature": {"status": True, "variable":controller.setDisableLoggerFeature}, @@ -524,6 +539,8 @@ if __name__ == "__main__": data = 1.5 case "/set/data/message_box_ratio": data = 0.5 + case "/set/data/send_message_button_type": + data = "show" case "/set/data/font_family": data = "Yu Gothic UI" case "/set/data/ui_language": @@ -544,7 +561,7 @@ if __name__ == "__main__": data = 5 case "/set/data/mic_max_phrases": data = 5 - case "/set//data/mic_word_filter": + case "/set/data/mic_word_filter": data = "test0, test1, test2" case "/set/data/selected_speaker_device": data = "スピーカー (Realtek High Definition Audio)" @@ -574,8 +591,6 @@ if __name__ == "__main__": "display_duration": 5, "fadeout_duration": 0.5, } - case "/set/data/send_message_button_type": - data = "show" case "/set/data/send_message_format": data = "[message]" case "/set/data/send_message_format_with_t": diff --git a/src-python/model.py b/src-python/model.py index 3b4e51b6..333f1394 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -96,7 +96,7 @@ class Model: "large": overlay_large_log_settings, } self.overlay = Overlay(overlay_settings) - self.overlay_image = OverlayImage() + self.overlay_image = OverlayImage(config.PATH_LOCAL) self.mic_audio_queue = None self.mic_mute_status = None self.kks = kakasi() @@ -452,9 +452,9 @@ class Model: config.MIC_AVG_LOGPROB, config.MIC_NO_SPEECH_PROB ) - if res: - result = self.mic_transcriber.getTranscript() - fnc(result) + if res: + result = self.mic_transcriber.getTranscript() + fnc(result) except Exception: errorLogging() @@ -509,6 +509,15 @@ class Model: if isinstance(self.mic_audio_recorder, SelectedMicEnergyAndAudioRecorder): self.mic_audio_recorder.pause() + # VRAM 不足エラーを検出するメソッドを追加 + def detectVRAMError(self, error): + error_str = str(error) + if isinstance(error, ValueError) and len(error.args) > 0 and error.args[0] == "VRAM_OUT_OF_MEMORY": + return True, error.args[1] if len(error.args) > 1 else "VRAM out of memory" + if "CUDA out of memory" in error_str or "CUBLAS_STATUS_ALLOC_FAILED" in error_str: + return True, error_str + return False, None + def changeMicTranscriptStatus(self): if config.VRC_MIC_MUTE_SYNC is True: match self.mic_mute_status: @@ -626,9 +635,9 @@ class Model: config.SPEAKER_AVG_LOGPROB, config.SPEAKER_NO_SPEECH_PROB ) - if res: - result = self.speaker_transcriber.getTranscript() - fnc(result) + if res: + result = self.speaker_transcriber.getTranscript() + fnc(result) except Exception: errorLogging() @@ -708,21 +717,20 @@ class Model: self.speaker_energy_recorder.stop() self.speaker_energy_recorder = None - def createOverlayImageSmallLog(self, message, translation): - your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] - target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] + def createOverlayImageSmallLog(self, message:str, your_language:str, translation:list, target_language:dict): + target_language = [data["language"] for data in target_language.values() if data["enable"] is True] return self.overlay_image.createOverlayImageSmallLog(message, your_language, translation, target_language) def createOverlayImageSmallMessage(self, message): ui_language = config.UI_LANGUAGE convert_languages = { - "en": "Japanese", + "en": "Default", "jp": "Japanese", "ko":"Korean", "zh-Hans":"Chinese Simplified", "zh-Hant":"Chinese Traditional", } - language = convert_languages.get(ui_language, "Japanese") + language = convert_languages.get(ui_language, "Default") return self.overlay_image.createOverlayImageSmallLog(message, language) def clearOverlayImageSmallLog(self): @@ -760,22 +768,21 @@ class Model: if (self.overlay.settings[size]["ui_scaling"] != config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"]): self.overlay.updateUiScaling(config.OVERLAY_SMALL_LOG_SETTINGS["ui_scaling"], size) - def createOverlayImageLargeLog(self, message_type:str, message:str, translation:str): - your_language = config.SELECTED_TARGET_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] - target_language = config.SELECTED_YOUR_LANGUAGES[config.SELECTED_TAB_NO]["1"]["language"] + def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:list, target_language:dict): + target_language = [data["language"] for data in target_language.values() if data["enable"] is True] return self.overlay_image.createOverlayImageLargeLog(message_type, message, your_language, translation, target_language) def createOverlayImageLargeMessage(self, message): ui_language = config.UI_LANGUAGE convert_languages = { - "en": "Japanese", + "en": "Default", "jp": "Japanese", "ko":"Korean", "zh-Hans":"Chinese Simplified", "zh-Hant":"Chinese Traditional", } - language = convert_languages.get(ui_language, "Japanese") - overlay_image = OverlayImage() + language = convert_languages.get(ui_language, "Default") + overlay_image = OverlayImage(config.PATH_LOCAL) for _ in range(2): overlay_image.createOverlayImageLargeLog("send", message, language) diff --git a/src-python/models/osc/osc.py b/src-python/models/osc/osc.py index ef4e1152..a47f1f8d 100644 --- a/src-python/models/osc/osc.py +++ b/src-python/models/osc/osc.py @@ -90,8 +90,10 @@ class OSCHandler: # エラー発生時にbrowserをリセットして次回再初期化 if self.browser is not None: try: - self.browser.zc.close() - self.browser.browser.cancel() + if hasattr(self.browser, 'zc') and self.browser.zc is not None: + self.browser.zc.close() + if hasattr(self.browser, 'browser') and self.browser.browser is not None: + self.browser.browser.cancel() except Exception: pass self.browser = None @@ -140,8 +142,10 @@ class OSCHandler: # browserがある場合はクリーンアップ if self.browser is not None: try: - self.browser.zc.close() - self.browser.browser.cancel() + if hasattr(self.browser, 'zc') and self.browser.zc is not None: + self.browser.zc.close() + if hasattr(self.browser, 'browser') and self.browser.browser is not None: + self.browser.browser.cancel() except Exception: pass self.browser = None diff --git a/src-python/models/overlay/overlay_image.py b/src-python/models/overlay/overlay_image.py index 52fd242d..2be5b0af 100644 --- a/src-python/models/overlay/overlay_image.py +++ b/src-python/models/overlay/overlay_image.py @@ -11,14 +11,19 @@ except ImportError: class OverlayImage: LANGUAGES = { - "Japanese": "NotoSansJP-Regular", - "Korean": "NotoSansKR-Regular", - "Chinese Simplified": "NotoSansSC-Regular", - "Chinese Traditional": "NotoSansTC-Regular", + "Default": "NotoSansJP-Regular.ttf", + "Japanese": "NotoSansJP-Regular.ttf", + "Korean": "NotoSansKR-Regular.ttf", + "Chinese Simplified": "NotoSansSC-Regular.ttf", + "Chinese Traditional": "NotoSansTC-Regular.ttf", } - def __init__(self): + def __init__(self, root_path: str=None): self.message_log = [] + if root_path is None: + self.root_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts") + else: + self.root_path = os_path.join(root_path, "_internal", "fonts") @staticmethod def concatenateImagesVertically(img1: Image, img2: Image, margin: int = 0) -> Image: @@ -54,16 +59,16 @@ class OverlayImage: return colors def createTextboxSmallLog(self, text:str, language:str, text_color:tuple, base_width:int, base_height:int, font_size:int) -> Image: - font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular") + font_family = self.LANGUAGES.get(language, self.LANGUAGES["Default"]) img = Image.new("RGBA", (base_width, base_height), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) try: - font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf") + font_path = os_path.join(self.root_path, font_family) font = ImageFont.truetype(font_path, font_size) except Exception: errorLogging() - font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf") + font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family) font = ImageFont.truetype(font_path, font_size) text_width = draw.textlength(text, font) @@ -80,7 +85,8 @@ class OverlayImage: draw.text((text_x, text_y), text, text_color, anchor="mm", stroke_width=0, font=font, align="center") return img - def createOverlayImageSmallLog(self, message:str, your_language:str, translation:str="", target_language:str=None) -> Image: + def createOverlayImageSmallLog(self, message: str, your_language: str, translation: list = [], target_language: list = []) -> Image: + # UI設定を取得 ui_size = self.getUiSizeSmallLog() width, height, font_size = ui_size["width"], ui_size["height"], ui_size["font_size"] @@ -89,16 +95,41 @@ class OverlayImage: background_color = ui_colors["background_color"] background_outline_color = ui_colors["background_outline_color"] - img = self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size) - if translation and target_language: - translation_img = self.createTextboxSmallLog(translation, target_language, text_color, width, height, font_size) - img = self.concatenateImagesVertically(img, translation_img) + # テキストボックス画像のリストを作成 + textbox_images = [] + # 翻訳がある場合 + if translation and target_language: + # 元のメッセージがある場合は追加 + if message: + textbox_images.append( + self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size) + ) + + # 翻訳をすべて追加 + for trans, lang in zip(translation, target_language): + textbox_images.append( + self.createTextboxSmallLog(trans, lang, text_color, width, height, font_size) + ) + else: + # 翻訳がない場合は元のメッセージのみ + textbox_images.append( + self.createTextboxSmallLog(message, your_language, text_color, width, height, font_size) + ) + + # すべてのテキストボックスを縦に結合 + img = textbox_images[0] + for textbox_img in textbox_images[1:]: + img = self.concatenateImagesVertically(img, textbox_img) + + # 角丸背景を作成 background = Image.new("RGBA", img.size, (0, 0, 0, 0)) draw = ImageDraw.Draw(background) draw.rounded_rectangle([(0, 0), img.size], radius=50, fill=background_color, outline=background_outline_color, width=5) - return Image.alpha_composite(background, img) + # 背景とテキストを合成 + img = Image.alpha_composite(background, img) + return img @staticmethod def getUiSizeLargeLog() -> dict: @@ -131,17 +162,17 @@ class OverlayImage: anchor = "lm" if message_type == "receive" else "rm" text_x = 0 if message_type == "receive" else ui_size["width"] align = "left" if message_type == "receive" else "right" - font_family = self.LANGUAGES.get(language, "NotoSansJP-Regular") + font_family = self.LANGUAGES.get(language, self.LANGUAGES["Default"]) img = Image.new("RGBA", (0, 0), (0, 0, 0, 0)) draw = ImageDraw.Draw(img) try: - font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", f"{font_family}.ttf") + font_path = os_path.join(self.root_path, font_family) font = ImageFont.truetype(font_path, font_size) except Exception: errorLogging() - font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", f"{font_family}.ttf") + font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", font_family) font = ImageFont.truetype(font_path, font_size) text_width = draw.textlength(text, font) @@ -172,11 +203,11 @@ class OverlayImage: draw = ImageDraw.Draw(img) try: - font_path = os_path.join(os_path.dirname(os_path.dirname(os_path.dirname(__file__))), "fonts", "NotoSansJP-Regular.ttf") + font_path = os_path.join(self.root_path, self.LANGUAGES["Default"]) font = ImageFont.truetype(font_path, font_size) except Exception: errorLogging() - font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", "NotoSansJP-Regular.ttf") + font_path = os_path.join(os_path.dirname(__file__), "..", "..", "..", "fonts", self.LANGUAGES["Default"]) font = ImageFont.truetype(font_path, font_size) text_height = font_size + ui_padding @@ -191,17 +222,37 @@ class OverlayImage: draw.text((text_x, text_y), text, text_color, anchor=anchor, stroke_width=0, font=font) return img - def createTextboxLargeLog(self, message_type:str, message:str, your_language:str, translation:str, target_language:str, date_time:str) -> Image: - message_type_img = self.createTextImageMessageType(message_type, date_time) - if translation and target_language: - img = self.createTextImageLargeLog(message_type, "small", message, your_language) - translation_img = self.createTextImageLargeLog(message_type, "large", translation, target_language) - img = self.concatenateImagesVertically(img, translation_img) - else: - img = self.createTextImageLargeLog(message_type, "large", message, your_language) - return self.concatenateImagesVertically(message_type_img, img) + def createTextboxLargeLog(self, message_type: str, message: str = None, your_language: str = None, translation: list = [], target_language: list = [], date_time: str = None) -> Image: + # テキスト画像のリストを作成 + images = [self.createTextImageMessageType(message_type, date_time)] - def createOverlayImageLargeLog(self, message_type:str, message:str, your_language:str, translation:str="", target_language:str=None) -> Image: + # 翻訳がある場合 + if translation and target_language: + # 元のメッセージがある場合は小さいサイズで追加 + if message is not None: + images.append( + self.createTextImageLargeLog(message_type, "small", message, your_language) + ) + + # 翻訳をすべて大きいサイズで追加 + for trans, lang in zip(translation, target_language): + images.append( + self.createTextImageLargeLog(message_type, "large", trans, lang) + ) + else: + # 翻訳がない場合は元のメッセージのみ + images.append( + self.createTextImageLargeLog(message_type, "large", message, your_language) + ) + + # すべてのテキスト画像を縦に結合 + combined_img = images[0] + for img in images[1:]: + combined_img = self.concatenateImagesVertically(combined_img, img) + + return combined_img + + def createOverlayImageLargeLog(self, message_type:str, message:str=None, your_language:str=None, translation:list=[], target_language:list=[]) -> Image: ui_color = self.getUiColorLargeLog() background_color = ui_color["background_color"] background_outline_color = ui_color["background_outline_color"] @@ -242,7 +293,8 @@ class OverlayImage: background = Image.new("RGBA", (width, height), (0, 0, 0, 0)) draw = ImageDraw.Draw(background) draw.rounded_rectangle([(0, 0), (width, height)], radius=ui_radius, fill=background_color, outline=background_outline_color, width=5) - return Image.alpha_composite(background, img) + img = Image.alpha_composite(background, img) + return img if __name__ == "__main__": overlay = OverlayImage() diff --git a/src-python/models/transcription/transcription_whisper.py b/src-python/models/transcription/transcription_whisper.py index 69499260..04f89626 100644 --- a/src-python/models/transcription/transcription_whisper.py +++ b/src-python/models/transcription/transcription_whisper.py @@ -77,15 +77,24 @@ def downloadWhisperWeight(root, weight_type, callback=None, end_callback=None): def getWhisperModel(root, weight_type, device="cpu", device_index=0): path = os_path.join(root, "weights", "whisper", weight_type) compute_type = getBestComputeType(device, device_index) - return WhisperModel( - path, - device=device, - device_index=device_index, - compute_type=compute_type, - cpu_threads=4, - num_workers=1, - local_files_only=True, - ) + try: + model = WhisperModel( + path, + device=device, + device_index=device_index, + compute_type=compute_type, + cpu_threads=4, + num_workers=1, + local_files_only=True, + ) + return model + except RuntimeError as e: + # VRAM不足エラーの検出 + error_message = str(e) + if "CUDA out of memory" in error_message or "CUBLAS_STATUS_ALLOC_FAILED" in error_message: + raise ValueError("VRAM_OUT_OF_MEMORY", error_message) + # その他のエラーは通常通り再送出 + raise if __name__ == "__main__": def callback(value): diff --git a/src-python/models/websocket/websocket_server.py b/src-python/models/websocket/websocket_server.py index 34762e55..299e7032 100644 --- a/src-python/models/websocket/websocket_server.py +++ b/src-python/models/websocket/websocket_server.py @@ -138,7 +138,8 @@ class WebSocketServer: finally: # 停止指示が出たらすべての接続を閉じ、イベントループを終了 self._loop.run_until_complete(self._shutdown()) - self._loop.close() + if self._loop is not None: + self._loop.close() async def _shutdown(self): """ diff --git a/src-python/utils.py b/src-python/utils.py index 7bc0997b..2676d591 100644 --- a/src-python/utils.py +++ b/src-python/utils.py @@ -115,9 +115,24 @@ def printResponse(status:int, endpoint:str, result:Any=None) -> None: "endpoint": endpoint, "result": result, } - process_logger.info(response) - response = json.dumps(response) - print(response, flush=True) + process_logger.info(response) # Log the unserialized response + + try: + serialized_response = json.dumps(response) + except OSError as e: + errorLogging() # Log the full traceback of the OSError + process_logger.error(f"Problematic response object before json.dumps: {response}") + process_logger.error(f"OSError during json.dumps: {e}") + # Optionally, print a generic error JSON to stdout if needed, or re-raise + # For now, we'll print a simple error message to stdout as a fallback + error_json = json.dumps({ + "status": 500, + "endpoint": endpoint, + "result": {"error": "Failed to serialize response due to OSError", "details": str(e)} + }) + print(error_json, flush=True) + else: + print(serialized_response, flush=True) error_logger = None def errorLogging() -> None: diff --git a/src-tauri/tauri.conf.json b/src-tauri/tauri.conf.json index 4d519488..898312d6 100644 --- a/src-tauri/tauri.conf.json +++ b/src-tauri/tauri.conf.json @@ -1,7 +1,7 @@ { "$schema": "https://schema.tauri.app/config/2", "productName": "VRCT", - "version": "3.0.0", + "version": "3.2.1", "identifier": "com.vrct.app", "build": { "beforeDevCommand": "", diff --git a/test_data.js b/src-ui/_test_data.js similarity index 95% rename from test_data.js rename to src-ui/_test_data.js index ba53cb7e..d2e1723c 100644 --- a/test_data.js +++ b/src-ui/_test_data.js @@ -1,4 +1,4 @@ -export const generateTestData = (num) => { +export const generateTestConversationData = (num) => { const testDataArray = []; const messagesJa = [ "今日はとてもいい天気ですね。", diff --git a/src-ui/app/App.jsx b/src-ui/app/App.jsx index 7dc99689..8280a857 100644 --- a/src-ui/app/App.jsx +++ b/src-ui/app/App.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { KeyEventController, @@ -11,23 +11,28 @@ import { TransparencyController, CornerRadiusController, PluginsController, -} from "./_app_controllers/index.js"; +} from "./_app_controllers"; + +import styles from "./App.module.scss"; -import { WindowTitleBar } from "./window_title_bar/WindowTitleBar"; import { MainPage } from "./main_page/MainPage"; import { ConfigPage } from "./config_page/ConfigPage"; -import { SplashComponent } from "./splash_component/SplashComponent"; -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 { + WindowTitleBar, + SplashComponent, + UpdatingComponent, + ModalController, + SnackbarController, + AppErrorBoundary, +} from "./others"; + import { useIsBackendReady, useIsSoftwareUpdating, useIsVrctAvailable, useWindow } from "@logics_common"; -import { AppErrorBoundary } from "./error_boundary/AppErrorBoundary"; export const App = () => { const { currentIsVrctAvailable } = useIsVrctAvailable(); const { currentIsBackendReady } = useIsBackendReady(); - const { i18n } = useTranslation(); + const { i18n } = useI18n(); return (
diff --git a/src-ui/app/_app_controllers/FontFamilyController.jsx b/src-ui/app/_app_controllers/FontFamilyController.jsx index f7110d1d..7d46425f 100644 --- a/src-ui/app/_app_controllers/FontFamilyController.jsx +++ b/src-ui/app/_app_controllers/FontFamilyController.jsx @@ -1,8 +1,8 @@ import { useEffect } from "react"; -import { useSelectedFontFamily } from "@logics_configs"; +import { useAppearance } from "@logics_configs"; export const FontFamilyController = () => { - const { currentSelectedFontFamily } = useSelectedFontFamily(); + const { currentSelectedFontFamily } = useAppearance(); useEffect(() => { document.documentElement.style.setProperty("--font_family", currentSelectedFontFamily.data); }, [currentSelectedFontFamily.data]); diff --git a/src-ui/app/_app_controllers/StartPythonController.jsx b/src-ui/app/_app_controllers/StartPythonController.jsx index c351120c..55824bc8 100644 --- a/src-ui/app/_app_controllers/StartPythonController.jsx +++ b/src-ui/app/_app_controllers/StartPythonController.jsx @@ -1,11 +1,16 @@ import { invoke } from "@tauri-apps/api/core"; +import { Command } from "@tauri-apps/plugin-shell"; import { useEffect, useRef } from "react"; -import { useStartPython } from "@logics/useStartPython"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; -import { useStore_SelectableFontFamilyList } from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { useReceiveRoutes } from "@useReceiveRoutes"; +import { store, useStore_SelectableFontFamilyList } from "@store"; import { arrayToObject } from "@utils"; +import { + useNotificationStatus, +} from "@logics_common"; + export const StartPythonController = () => { const { asyncStartPython } = useStartPython(); const hasRunRef = useRef(false); @@ -26,6 +31,34 @@ export const StartPythonController = () => { return null; }; +const useStartPython = () => { + const { receiveRoutes } = useReceiveRoutes(); + const { showNotification_Success, showNotification_Error } = useNotificationStatus(); + + const asyncStartPython = async () => { + const command = Command.sidecar("bin/VRCT-sidecar"); + command.on("error", error => console.error(`error: "${error}"`)); + command.stdout.on("data", (line) => { + let parsed_data = ""; + try { + parsed_data = JSON.parse(line); + receiveRoutes(parsed_data); + } catch (error) { + console.log(error, line); + } + }); + command.stderr.on("data", line => { + showNotification_Error( + `An error occurred. Please restart VRCT or contact the developers. The last line:${JSON.stringify(line)}`, { hide_duration: null }); + console.error("stderr", line); + }); + const backend_subprocess = await command.spawn(); + store.backend_subprocess = backend_subprocess; + }; + + return { asyncStartPython }; +}; + const useAsyncFetchFonts = () => { const { updateSelectableFontFamilyList } = useStore_SelectableFontFamilyList(); const asyncFetchFonts = async () => { diff --git a/src-ui/app/_app_controllers/TransparencyController.jsx b/src-ui/app/_app_controllers/TransparencyController.jsx index 46982413..0ddbc62e 100644 --- a/src-ui/app/_app_controllers/TransparencyController.jsx +++ b/src-ui/app/_app_controllers/TransparencyController.jsx @@ -1,8 +1,8 @@ import { useEffect } from "react"; -import { useTransparency } from "@logics_configs"; +import { useAppearance } from "@logics_configs"; export const TransparencyController = () => { - const { currentTransparency } = useTransparency(); + const { currentTransparency } = useAppearance(); useEffect(() => { document.documentElement.style.setProperty("opacity", `${currentTransparency.data / 100}`); }, [currentTransparency.data]); diff --git a/src-ui/app/_app_controllers/UiLanguageController.jsx b/src-ui/app/_app_controllers/UiLanguageController.jsx index 5b45c503..215874cb 100644 --- a/src-ui/app/_app_controllers/UiLanguageController.jsx +++ b/src-ui/app/_app_controllers/UiLanguageController.jsx @@ -1,11 +1,11 @@ import { useEffect } from "react"; -import { useTranslation } from "react-i18next"; -import { useUiLanguage } from "@logics_configs"; +import { useI18n } from "@useI18n"; +import { useAppearance } from "@logics_configs"; export const UiLanguageController = () => { - const { currentUiLanguage } = useUiLanguage(); - const { i18n } = useTranslation(); + const { currentUiLanguage } = useAppearance(); + const { i18n } = useI18n(); useEffect(() => { i18n.changeLanguage(currentUiLanguage.data); diff --git a/src-ui/app/_app_controllers/UiSizeController.jsx b/src-ui/app/_app_controllers/UiSizeController.jsx index 8b970c0f..5ad6aa3f 100644 --- a/src-ui/app/_app_controllers/UiSizeController.jsx +++ b/src-ui/app/_app_controllers/UiSizeController.jsx @@ -1,8 +1,8 @@ import { useEffect } from "react"; -import { useUiScaling } from "@logics_configs"; +import { useAppearance } from "@logics_configs"; export const UiSizeController = () => { - const { currentUiScaling } = useUiScaling(); + const { currentUiScaling } = useAppearance(); const font_size = 62.5 * currentUiScaling.data / 100; useEffect(() => { diff --git a/src-ui/app/_app_controllers/plugins_controllers/MergePluginsController.jsx b/src-ui/app/_app_controllers/plugins_controllers/MergePluginsController.jsx index 8d2c1b4f..71aee84f 100644 --- a/src-ui/app/_app_controllers/plugins_controllers/MergePluginsController.jsx +++ b/src-ui/app/_app_controllers/plugins_controllers/MergePluginsController.jsx @@ -1,12 +1,12 @@ import { useEffect, useRef } from "react"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { store } from "@store"; import { usePlugins } from "@logics_configs"; import { useSoftwareVersion } from "@logics_common"; import { useNotificationStatus } from "@logics_common"; export const MergePluginsController = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentLoadedPlugins, updatePluginsData, diff --git a/src-ui/app/_index_css/variables.css b/src-ui/app/_index_css/variables.css index ca2beca1..a5579afc 100644 --- a/src-ui/app/_index_css/variables.css +++ b/src-ui/app/_index_css/variables.css @@ -18,14 +18,15 @@ --primary_600_color_44: #36877744; + /* primary_300_color 61b4a7 as standard */ --sent_400_color: #6197b4; - --sent_300_color: #6197b4; --received_300_color: #a861b4; + --error_bc_color: #bb4448; --error_bc_active_color: #9c3938; - --success_bc_color: #368777; - --waring_color: #cb944f; - --waring_bc_color: #cf7b1b; + --success_bc_color: var(--primary_600_color); + --warning_color: #cb944f; + --warning_bc_color: #cf7b1b; --dark_basic_text_color: #f2f2f2; --dark_100_color: #f5f7fb; @@ -60,6 +61,8 @@ --dark_1000_color_aa: #151517aa; --dark_1000_color_dd: #151517dd; + /*sent_400_color + #000 10% = */ + --supporters_color_fuwa: #5788a2; --title_bar_height: 2rem; --main_page_topbar_height: 4.8rem; @@ -68,4 +71,5 @@ --font_family: "Yu Gothic UI"; } -/* https://m2.material.io/design/color/the-color-system.html#tools-for-picking-colors */ \ No newline at end of file +/* https://m2.material.io/design/color/the-color-system.html#tools-for-picking-colors */ +/* https://meyerweb.com/eric/tools/color-blend/#::1:hex */ \ No newline at end of file diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_download_button/_DownloadButton.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_download_button/_DownloadButton.jsx index edaf7fa5..ac17b759 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_download_button/_DownloadButton.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/_atoms/_download_button/_DownloadButton.jsx @@ -1,9 +1,9 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import CircularProgress from "@mui/material/CircularProgress"; import styles from "./_DownloadButton.module.scss"; export const _DownloadButton = ({option, ...props}) => { - const { t } = useTranslation(); + const { t } = useI18n(); const renderContent = () => { const circular_progress = Math.floor(option.progress / 10) * 10; diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx index e462998c..effdd2c9 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/deepl_auth_key/DeeplAuthKey.jsx @@ -1,5 +1,5 @@ import styles from "./DeeplAuthKey.module.scss"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import CircularProgress from "@mui/material/CircularProgress"; import ExternalLink from "@images/external_link.svg?react"; @@ -8,7 +8,7 @@ import { useState, useRef } from "react"; import { useEffect } from "react"; export const DeeplAuthKey = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const [is_editable, seIsEditable] = useState(false); const entryRef = useRef(null); @@ -60,7 +60,7 @@ export const DeeplAuthKey = (props) => { export const OpenWebpage_DeeplAuthKey = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (
diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/entry_with_save_button/EntryWithSaveButton.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/entry_with_save_button/EntryWithSaveButton.jsx index 487d0e04..ca7d1a10 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/entry_with_save_button/EntryWithSaveButton.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/entry_with_save_button/EntryWithSaveButton.jsx @@ -1,11 +1,11 @@ import styles from "./EntryWithSaveButton.module.scss"; import { _Entry } from "../_atoms/_entry/_Entry"; import CircularProgress from "@mui/material/CircularProgress"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { clsx } from "clsx"; export const EntryWithSaveButton = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const onChangeFunction = (e) => { props.onChangeFunction?.(e.target.value); }; diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/index.js b/src-ui/app/config_page/setting_section/setting_box/_components/index.js index 178dbcec..7b695b35 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/index.js +++ b/src-ui/app/config_page/setting_section/setting_box/_components/index.js @@ -12,5 +12,4 @@ export { Slider } from "./slider/Slider"; export { SwitchBox } from "./switch_box/SwitchBox"; export { ThresholdComponent } from "./threshold_component/ThresholdComponent"; export { WordFilter, WordFilterListToggleComponent } from "./word_filter/WordFilter"; -export { DownloadModels } from "./download_models/DownloadModels"; -export { PluginsControlComponent } from "./plugins_control_component/PluginsControlComponent"; \ No newline at end of file +export { DownloadModels } from "./download_models/DownloadModels"; \ No newline at end of file diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx index 018f3845..e9fb29fb 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/ThresholdComponent.jsx @@ -7,8 +7,7 @@ import { useVolume } from "@logics_common"; import MicSvg from "@images/mic.svg?react"; import HeadphonesSvg from "@images/headphones.svg?react"; import { - useMicThreshold, - useSpeakerThreshold, + useDevice, } from "@logics_configs"; export const ThresholdComponent = (props) => { @@ -27,7 +26,7 @@ const MicComponent = (props) => { currentMicThreshold, setMicThreshold, currentEnableAutomaticMicThreshold, - } = useMicThreshold(); + } = useDevice(); const [ui_threshold, setUiThreshold] = useState(currentMicThreshold.data); const { volumeCheckStart_Mic, @@ -84,7 +83,7 @@ const SpeakerComponent = (props) => { currentSpeakerThreshold, setSpeakerThreshold, currentEnableAutomaticSpeakerThreshold, - } = useSpeakerThreshold(); + } = useDevice(); const [ui_threshold, setUiThreshold] = useState(currentSpeakerThreshold.data); const { volumeCheckStart_Speaker, diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx index 8c67637c..475f2410 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/slider_and_meter/SliderAndMeter.jsx @@ -4,8 +4,7 @@ import { useStore_SpeakerVolume, } from "@store"; import { - useMicThreshold, - useSpeakerThreshold, + useDevice, } from "@logics_configs"; export const SliderAndMeter = (props) => { @@ -24,7 +23,7 @@ export const SliderAndMeter = (props) => { const ThresholdVolumeMeter_Mic = (props) => { const { currentMicVolume } = useStore_MicVolume(); - const { currentEnableAutomaticMicThreshold } = useMicThreshold(); + const { currentEnableAutomaticMicThreshold } = useDevice(); const currentVolumeVariable = Math.min(currentMicVolume.data, props.max); const volume_width_percentage = (currentVolumeVariable / props.max) * 100; @@ -50,7 +49,7 @@ const ThresholdVolumeMeter_Mic = (props) => { const ThresholdVolumeMeter_Speaker = (props) => { const { currentSpeakerVolume } = useStore_SpeakerVolume(); - const { currentEnableAutomaticSpeakerThreshold } = useSpeakerThreshold(); + const { currentEnableAutomaticSpeakerThreshold } = useDevice(); const currentVolumeVariable = Math.min(currentSpeakerVolume.data, props.max); const volume_width_percentage = (currentVolumeVariable / props.max) * 100; diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/volume_check_button/VolumeCheckButton.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/volume_check_button/VolumeCheckButton.jsx index 0f733b48..d3943bc0 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/volume_check_button/VolumeCheckButton.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/threshold_component/volume_check_button/VolumeCheckButton.jsx @@ -1,10 +1,10 @@ import React from "react"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import styles from "./VolumeCheckButton.module.scss"; export const VolumeCheckButton = React.memo((props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const getClassNames = (baseClass) => clsx(baseClass, { [styles.is_active]: (props.isChecking?.data === true), [styles.is_pending]: (props.isChecking.state === "pending"), diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx b/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx index bc338d4b..fbc0bd05 100644 --- a/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/_components/word_filter/WordFilter.jsx @@ -1,15 +1,15 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./WordFilter.module.scss"; import { _Entry } from "../_atoms/_entry/_Entry"; import { useState } from "react"; import { useStore_IsOpenedMicWordFilterList } from "@store"; -import { useMicWordFilterList } from "@logics_configs"; +import { useTranscription } from "@logics_configs"; export const WordFilter = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const [input_value, setInputValue] = useState(""); - const { currentMicWordFilterList, updateMicWordFilterList, setMicWordFilterList } = useMicWordFilterList(); + const { currentMicWordFilterList, updateMicWordFilterList, setMicWordFilterList } = useTranscription(); const { currentIsOpenedMicWordFilterList, updateIsOpenedMicWordFilterList } = useStore_IsOpenedMicWordFilterList(); const extractRedoableFalseItem = (updated_list) => { @@ -126,9 +126,9 @@ const WordFilterItem = (props) => { import ArrowLeftSvg from "@images/arrow_left.svg?react"; export const WordFilterListToggleComponent = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentIsOpenedMicWordFilterList, updateIsOpenedMicWordFilterList } = useStore_IsOpenedMicWordFilterList(); - const { currentMicWordFilterList } = useMicWordFilterList(); + const { currentMicWordFilterList } = useTranscription(); const svg_class_names = clsx(styles["arrow_left_svg"], { diff --git a/src-ui/app/config_page/setting_section/setting_box/about_vrct/AboutVrct.jsx b/src-ui/app/config_page/setting_section/setting_box/about_vrct/AboutVrct.jsx index d64f4e3c..a04c02bd 100644 --- a/src-ui/app/config_page/setting_section/setting_box/about_vrct/AboutVrct.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/about_vrct/AboutVrct.jsx @@ -27,12 +27,12 @@ import special_thanks_message_ja from "@images/about_vrct/special_thanks_message import poster_showcase_section_title from "@images/about_vrct/poster_showcase_section_title.png"; import clsx from "clsx"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { useStore_UiLanguage } from "@store"; import { PosterShowcaseContents } from "./poster_showcase_contents/PosterShowcaseContents"; export const AboutVrct = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentUiLanguage } = useStore_UiLanguage(); return (
diff --git a/src-ui/app/config_page/setting_section/setting_box/advanced_settings/AdvancedSettings.jsx b/src-ui/app/config_page/setting_section/setting_box/advanced_settings/AdvancedSettings.jsx index 2f4c15cd..df6f012a 100644 --- a/src-ui/app/config_page/setting_section/setting_box/advanced_settings/AdvancedSettings.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/advanced_settings/AdvancedSettings.jsx @@ -1,12 +1,10 @@ import { useEffect, useState } from "react"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./AdvancedSettings.module.scss"; import { useOpenFolder } from "@logics_common"; import { - useOscIpAddress, - useOscPort, - useWebsocket, + useAdvancedSettings, } from "@logics_configs"; import { @@ -37,8 +35,8 @@ export const AdvancedSettings = () => { }; const OscIpAddressContainer = () => { - const { t } = useTranslation(); - const { currentOscIpAddress, setOscIpAddress } = useOscIpAddress(); + const { t } = useI18n(); + const { currentOscIpAddress, setOscIpAddress } = useAdvancedSettings(); const [input_value, setInputValue] = useState(currentOscIpAddress.data); const onChangeFunction = (value) => { @@ -50,6 +48,7 @@ const OscIpAddressContainer = () => { }; useEffect(()=> { + if (currentOscIpAddress.state === "pending") return; setInputValue(currentOscIpAddress.data); }, [currentOscIpAddress]); @@ -66,8 +65,8 @@ const OscIpAddressContainer = () => { }; const OscPortContainer = () => { - const { t } = useTranslation(); - const { currentOscPort, setOscPort } = useOscPort(); + const { t } = useI18n(); + const { currentOscPort, setOscPort } = useAdvancedSettings(); const [input_value, setInputValue] = useState(currentOscPort.data); const onChangeFunction = (value) => { @@ -80,6 +79,7 @@ const OscPortContainer = () => { }; useEffect(()=> { + if (currentOscPort.state === "pending") return; setInputValue(currentOscPort.data); }, [currentOscPort]); @@ -96,7 +96,7 @@ const OscPortContainer = () => { }; const OpenConfigFolderContainer = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { openFolder_ConfigFile } = useOpenFolder(); return ( @@ -113,7 +113,7 @@ const OpenConfigFolderContainer = () => { // Duplicate import { useStore_OpenedQuickSetting } from "@store"; const OpenSwitchComputeDeviceModalContainer = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateOpenedQuickSetting } = useStore_OpenedQuickSetting(); const onClickFunction = () => { updateOpenedQuickSetting("update_software"); @@ -143,8 +143,8 @@ const WebsocketContainer = () => { }; const EnableWebsocketContainer = () => { - const { t } = useTranslation(); - const { currentEnableWebsocket, toggleEnableWebsocket } = useWebsocket(); + const { t } = useI18n(); + const { currentEnableWebsocket, toggleEnableWebsocket } = useAdvancedSettings(); return ( { }; const WebsocketHostContainer = () => { - const { t } = useTranslation(); - const { currentWebsocketHost, setWebsocketHost } = useWebsocket(); + const { t } = useI18n(); + const { currentWebsocketHost, setWebsocketHost } = useAdvancedSettings(); const [input_value, setInputValue] = useState(currentWebsocketHost.data); const onChangeFunction = (value) => { @@ -169,6 +169,7 @@ const WebsocketHostContainer = () => { }; useEffect(()=> { + if (currentWebsocketHost.state === "pending") return; setInputValue(currentWebsocketHost.data); }, [currentWebsocketHost]); @@ -185,8 +186,8 @@ const WebsocketHostContainer = () => { }; const WebsocketPortContainer = () => { - const { t } = useTranslation(); - const { currentWebsocketPort, setWebsocketPort } = useWebsocket(); + const { t } = useI18n(); + const { currentWebsocketPort, setWebsocketPort } = useAdvancedSettings(); const [input_value, setInputValue] = useState(currentWebsocketPort.data); const onChangeFunction = (value) => { @@ -199,6 +200,7 @@ const WebsocketPortContainer = () => { }; useEffect(()=> { + if (currentWebsocketPort.state === "pending") return; setInputValue(currentWebsocketPort.data); }, [currentWebsocketPort]); diff --git a/src-ui/app/config_page/setting_section/setting_box/appearance/Appearance.jsx b/src-ui/app/config_page/setting_section/setting_box/appearance/Appearance.jsx index d9ecb7c6..1f2f9eb4 100644 --- a/src-ui/app/config_page/setting_section/setting_box/appearance/Appearance.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/appearance/Appearance.jsx @@ -1,6 +1,6 @@ import clsx from "clsx"; import { useEffect, useState } from "react"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./Appearance.module.scss"; import { ui_configs } from "@ui_configs"; import { useStore_SelectableFontFamilyList } from "@store"; @@ -10,18 +10,14 @@ import { } from "@logics_common"; import { - useUiLanguage, - useUiScaling, - useMessageLogUiScaling, - useSendMessageButtonType, - useSelectedFontFamily, - useTransparency, + useAppearance, } from "@logics_configs"; import { SliderContainer, DropdownMenuContainer, RadioButtonContainer, + CheckboxContainer, } from "../_templates/Templates"; export const Appearance = () => { @@ -31,6 +27,7 @@ export const Appearance = () => { + @@ -38,8 +35,8 @@ export const Appearance = () => { }; const UiLanguageContainer = () => { - const { t } = useTranslation(); - const { currentUiLanguage, setUiLanguage } = useUiLanguage(); + const { t } = useI18n(); + const { currentUiLanguage, setUiLanguage } = useAppearance(); const is_not_en_lang = currentUiLanguage.data !== "en" && currentUiLanguage.data !== undefined; return ( @@ -55,8 +52,8 @@ const UiLanguageContainer = () => { }; const UiScalingContainer = () => { - const { t } = useTranslation(); - const { currentUiScaling, setUiScaling } = useUiScaling(); + const { t } = useI18n(); + const { currentUiScaling, setUiScaling } = useAppearance(); const { asyncUpdateBreakPoint } = useWindow(); const [ui_ui_scaling, setUiUiScaling] = useState(currentUiScaling.data); @@ -100,8 +97,8 @@ const UiScalingContainer = () => { export const MessageLogUiScalingContainer = () => { - const { t } = useTranslation(); - const { currentMessageLogUiScaling, setMessageLogUiScaling } = useMessageLogUiScaling(); + const { t } = useI18n(); + const { currentMessageLogUiScaling, setMessageLogUiScaling } = useAppearance(); const [ui_message_log_ui_scaling, setUiMessageLogUiScaling] = useState(currentMessageLogUiScaling.data); const onchangeFunction = (value) => { @@ -141,8 +138,8 @@ export const MessageLogUiScalingContainer = () => { }; const SendMessageButtonTypeContainer = () => { - const { t } = useTranslation(); - const { currentSendMessageButtonType, setSendMessageButtonType } = useSendMessageButtonType(); + const { t } = useI18n(); + const { currentSendMessageButtonType, setSendMessageButtonType } = useAppearance(); return ( { ); }; +const ShowResendButtonContainer = () => { + const { t } = useI18n(); + const { currentShowResendButton, toggleShowResendButton } = useAppearance(); + + return ( + + ); +}; + const FontFamilyContainer = () => { - const { t } = useTranslation(); - const { currentSelectedFontFamily, setSelectedFontFamily } = useSelectedFontFamily(); + const { t } = useI18n(); + const { currentSelectedFontFamily, setSelectedFontFamily } = useAppearance(); const selectFunction = (selected_data) => { setSelectedFontFamily(selected_data.selected_id); @@ -182,8 +193,8 @@ const FontFamilyContainer = () => { }; const TransparencyContainer = () => { - const { t } = useTranslation(); - const { currentTransparency, setTransparency } = useTransparency(); + const { t } = useI18n(); + const { currentTransparency, setTransparency } = useAppearance(); const [ui_message_log_ui_scaling, setUiTransparency] = useState(currentTransparency.data); const onchangeFunction = (value) => { diff --git a/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx b/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx index 56b11398..28240452 100644 --- a/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/device/Device.jsx @@ -1,19 +1,10 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./Device.module.scss"; import clsx from "clsx"; import { useStore_IsBreakPoint } from "@store"; import { ui_configs } from "@ui_configs"; import { - useEnableAutoMicSelect, - useMicHostList, - useSelectedMicHost, - useMicDeviceList, - useSelectedMicDevice, - useMicThreshold, - useEnableAutoSpeakerSelect, - useSpeakerDeviceList, - useSelectedSpeakerDevice, - useSpeakerThreshold, + useDevice, } from "@logics_configs"; import { @@ -37,14 +28,22 @@ export const Device = () => { }; const Mic_Container = () => { - const { t } = useTranslation(); - const { currentEnableAutoMicSelect, toggleEnableAutoMicSelect } = useEnableAutoMicSelect(); - const { currentSelectedMicHost, setSelectedMicHost } = useSelectedMicHost(); - const { currentMicHostList } = useMicHostList(); - const { currentSelectedMicDevice, setSelectedMicDevice } = useSelectedMicDevice(); - const { currentMicDeviceList } = useMicDeviceList(); + const { t } = useI18n(); + const { + currentEnableAutoMicSelect, + toggleEnableAutoMicSelect, + currentMicDeviceList, + currentMicHostList, + + currentSelectedMicHost, + setSelectedMicHost, + currentSelectedMicDevice, + setSelectedMicDevice, + + currentEnableAutomaticMicThreshold, + toggleEnableAutomaticMicThreshold, + } = useDevice(); const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu(); - const { currentEnableAutomaticMicThreshold, toggleEnableAutomaticMicThreshold } = useMicThreshold(); const selectFunction_host = (selected_data) => { setSelectedMicHost(selected_data.selected_id); @@ -138,12 +137,17 @@ const Mic_Container = () => { }; const Speaker_Container = () => { - const { t } = useTranslation(); - const { currentEnableAutoSpeakerSelect, toggleEnableAutoSpeakerSelect } = useEnableAutoSpeakerSelect(); - const { currentSelectedSpeakerDevice, setSelectedSpeakerDevice } = useSelectedSpeakerDevice(); - const { currentSpeakerDeviceList } = useSpeakerDeviceList(); + const { t } = useI18n(); + const { + currentEnableAutoSpeakerSelect, + toggleEnableAutoSpeakerSelect, + currentSpeakerDeviceList, + currentSelectedSpeakerDevice, + setSelectedSpeakerDevice, + currentEnableAutomaticSpeakerThreshold, + toggleEnableAutomaticSpeakerThreshold, + } = useDevice(); const { onMouseLeaveFunction } = useOnMouseLeaveDropdownMenu(); - const { currentEnableAutomaticSpeakerThreshold, toggleEnableAutomaticSpeakerThreshold } = useSpeakerThreshold(); const selectFunction = (selected_data) => { setSelectedSpeakerDevice(selected_data.selected_id); diff --git a/src-ui/app/config_page/setting_section/setting_box/hotkeys/Hotkeys.jsx b/src-ui/app/config_page/setting_section/setting_box/hotkeys/Hotkeys.jsx index 33d57923..66cf893c 100644 --- a/src-ui/app/config_page/setting_section/setting_box/hotkeys/Hotkeys.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/hotkeys/Hotkeys.jsx @@ -1,7 +1,7 @@ import { useHotkeys } from "@logics_configs"; import styles from "./Hotkeys.module.scss"; import { HotkeysEntryContainer } from "../_templates/Templates"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; export const Hotkeys = () => { return (
@@ -11,7 +11,7 @@ export const Hotkeys = () => { }; const HotkeysBoxContainer = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentHotkeys, setHotkeys } = useHotkeys(); return ( diff --git a/src-ui/app/config_page/setting_section/setting_box/others/Others.jsx b/src-ui/app/config_page/setting_section/setting_box/others/Others.jsx index b6c9c9b6..1baf00a5 100644 --- a/src-ui/app/config_page/setting_section/setting_box/others/Others.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/others/Others.jsx @@ -1,15 +1,9 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./Others.module.scss"; import { useOpenFolder } from "@logics_common"; import { - useEnableAutoClearMessageInputBox, - useEnableSendOnlyTranslatedMessages, - useEnableAutoExportMessageLogs, - useEnableVrcMicMuteSync, - useEnableSendMessageToVrc, - useEnableSendReceivedMessageToVrc, - useEnableNotificationVrcSfx, + useOthers, } from "@logics_configs"; import { @@ -26,7 +20,7 @@ import { Checkbox } from "@common_components"; import OpenFolderSvg from "@images/open_folder.svg?react"; export const Others = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (
@@ -50,8 +44,8 @@ export const Others = () => { }; const AutoClearMessageInputBoxContainer = () => { - const { t } = useTranslation(); - const { currentEnableAutoClearMessageInputBox, toggleEnableAutoClearMessageInputBox } = useEnableAutoClearMessageInputBox(); + const { t } = useI18n(); + const { currentEnableAutoClearMessageInputBox, toggleEnableAutoClearMessageInputBox } = useOthers(); return ( { ); }; const SendOnlyTranslatedMessagesContainer = () => { - const { t } = useTranslation(); - const { currentEnableSendOnlyTranslatedMessages, toggleEnableSendOnlyTranslatedMessages } = useEnableSendOnlyTranslatedMessages(); + const { t } = useI18n(); + const { currentEnableSendOnlyTranslatedMessages, toggleEnableSendOnlyTranslatedMessages } = useOthers(); return ( { ); }; const AutoExportMessageLogsContainer = () => { - const { t } = useTranslation(); - const { currentEnableAutoExportMessageLogs, toggleEnableAutoExportMessageLogs } = useEnableAutoExportMessageLogs(); + const { t } = useI18n(); + const { currentEnableAutoExportMessageLogs, toggleEnableAutoExportMessageLogs } = useOthers(); const { openFolder_MessageLogs } = useOpenFolder(); return ( @@ -98,8 +92,8 @@ const AutoExportMessageLogsContainer = () => { ); }; export const VrcMicMuteSyncContainer = () => { - const { t } = useTranslation(); - const { currentEnableVrcMicMuteSync, toggleEnableVrcMicMuteSync } = useEnableVrcMicMuteSync(); + const { t } = useI18n(); + const { currentEnableVrcMicMuteSync, toggleEnableVrcMicMuteSync } = useOthers(); const variable = { state: currentEnableVrcMicMuteSync.state, @@ -117,8 +111,8 @@ export const VrcMicMuteSyncContainer = () => { ); }; const SendMessageToVrcContainer = () => { - const { t } = useTranslation(); - const { currentEnableSendMessageToVrc, toggleEnableSendMessageToVrc } = useEnableSendMessageToVrc(); + const { t } = useI18n(); + const { currentEnableSendMessageToVrc, toggleEnableSendMessageToVrc } = useOthers(); return ( { const EnableNotificationVrcSfxContainer = () => { - const { t } = useTranslation(); - const { currentEnableNotificationVrcSfx, toggleEnableNotificationVrcSfx } = useEnableNotificationVrcSfx(); + const { t } = useI18n(); + const { currentEnableNotificationVrcSfx, toggleEnableNotificationVrcSfx } = useOthers(); return ( { }; const SendReceivedMessageToVrcContainer = () => { - const { t } = useTranslation(); - const { currentEnableSendReceivedMessageToVrc, toggleEnableSendReceivedMessageToVrc } = useEnableSendReceivedMessageToVrc(); + const { t } = useI18n(); + const { currentEnableSendReceivedMessageToVrc, toggleEnableSendReceivedMessageToVrc } = useOthers(); return ( { }; const PluginDownloadContainer = () => { - const { t, i18n } = useTranslation(); + const { t, i18n } = useI18n(); const { downloadAndExtractPlugin, currentPluginsData, @@ -105,7 +105,12 @@ const PluginDownloadContainer = () => {
{plugin.is_error ? ( -

Error: {plugin.error_message}

+
+

{t(`plugin_notifications.${plugin.error_message_type}`)}

+

plugin_version: {plugin.downloaded_plugin_info.plugin_version}

+

min_supported_vrct_version: {plugin.downloaded_plugin_info.min_supported_vrct_version}

+

max_supported_vrct_version: {plugin.downloaded_plugin_info.max_supported_vrct_version}

+
) : ( { - const { t } = useTranslation(); + const { t } = useI18n(); const option = { id: plugin_status.plugin_id, @@ -65,7 +64,7 @@ const DownloadedPluginControl = ({ downloaded_version_label, latest_version_label, }) => { - const { t } = useTranslation(); + const { t } = useI18n(); const togglePlugin = () => { toggleFunction(plugin_status.plugin_id); @@ -129,7 +128,7 @@ const NotDownloadedPluginControl = ({ downloaded_version_label, latest_version_label, }) => { - const { t } = useTranslation(); + const { t } = useI18n(); if (plugin_status.is_latest_version_available) { return ( diff --git a/src-ui/app/config_page/setting_section/setting_box/_components/plugins_control_component/PluginsControlComponent.module.scss b/src-ui/app/config_page/setting_section/setting_box/plugins/plugins_control_component/PluginsControlComponent.module.scss similarity index 100% rename from src-ui/app/config_page/setting_section/setting_box/_components/plugins_control_component/PluginsControlComponent.module.scss rename to src-ui/app/config_page/setting_section/setting_box/plugins/plugins_control_component/PluginsControlComponent.module.scss diff --git a/src-ui/app/config_page/setting_section/setting_box/supporters/support_us_container/SupportUsContainer.module.scss b/src-ui/app/config_page/setting_section/setting_box/supporters/support_us_container/SupportUsContainer.module.scss index ef7ef6fc..1ef360b4 100644 --- a/src-ui/app/config_page/setting_section/setting_box/supporters/support_us_container/SupportUsContainer.module.scss +++ b/src-ui/app/config_page/setting_section/setting_box/supporters/support_us_container/SupportUsContainer.module.scss @@ -86,7 +86,7 @@ $progress_ease: cubic-bezier(0, 1, 0.75, 1); } .line_fuwa { - background-color: #5788a2; + background-color: var(--supporters_color_fuwa); animation: expandWidth 1s $progress_ease 0.6s forwards; } @@ -150,8 +150,8 @@ $progress_ease: cubic-bezier(0, 1, 0.75, 1); box-shadow: 0 0 0.4rem 0 var(--dark_800_color); } .spiral_top::after { - background: #5788a2; - box-shadow: 0 0 0.4rem 0 #5788a2; + background: var(--supporters_color_fuwa); + box-shadow: 0 0 0.4rem 0 var(--supporters_color_fuwa); } .spiral_bottom::before { background: var(--received_300_color); diff --git a/src-ui/app/config_page/setting_section/setting_box/supporters/supporters_container/supporters_wrapper/SupportersWrapper.module.scss b/src-ui/app/config_page/setting_section/setting_box/supporters/supporters_container/supporters_wrapper/SupportersWrapper.module.scss index 3d392642..73c28ea5 100644 --- a/src-ui/app/config_page/setting_section/setting_box/supporters/supporters_container/supporters_wrapper/SupportersWrapper.module.scss +++ b/src-ui/app/config_page/setting_section/setting_box/supporters/supporters_container/supporters_wrapper/SupportersWrapper.module.scss @@ -62,7 +62,7 @@ $progress_ease: cubic-bezier(0, 1, 0.75, 1); height: 4rem; aspect-ratio: 1 /1; border-radius: 50%; - background-color: #ffffff; + background-color: var(--dark_basic_text_color); overflow: hidden; position: relative; transition: transform 0.6s $progress_ease; @@ -236,7 +236,7 @@ $progress_ease: cubic-bezier(0, 1, 0.75, 1); background-color: var(--received_300_color); } &.fuwa_bar { - background-color: #5788a2; + background-color: var(--supporters_color_fuwa); } &.basic_bar { background-color: var(--dark_800_color); diff --git a/src-ui/app/config_page/setting_section/setting_box/transcription/Transcription.jsx b/src-ui/app/config_page/setting_section/setting_box/transcription/Transcription.jsx index d881b330..279c1d9d 100644 --- a/src-ui/app/config_page/setting_section/setting_box/transcription/Transcription.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/transcription/Transcription.jsx @@ -1,22 +1,9 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./Transcription.module.scss"; import { updateLabelsById, genNumObjArray } from "@utils"; import { - useMicRecordTimeout, - useMicPhraseTimeout, - useMicMaxWords, - - useSpeakerRecordTimeout, - useSpeakerPhraseTimeout, - useSpeakerMaxWords, - - useSelectedTranscriptionEngine, - useWhisperWeightTypeStatus, - useSelectedWhisperWeightType, - - useSelectedWhisperComputeDevice, - useSelectableWhisperComputeDeviceList, + useTranscription, } from "@logics_configs"; import { @@ -43,7 +30,7 @@ export const Transcription = () => { const Mic_Container = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (
@@ -56,8 +43,8 @@ const Mic_Container = () => { }; const MicRecordTimeout_Box = () => { - const { t } = useTranslation(); - const { currentMicRecordTimeout, setMicRecordTimeout } = useMicRecordTimeout(); + const { t } = useI18n(); + const { currentMicRecordTimeout, setMicRecordTimeout } = useTranscription(); const selectFunction = (selected_data) => { setMicRecordTimeout(selected_data.selected_id); @@ -76,8 +63,8 @@ const MicRecordTimeout_Box = () => { ); }; const MicPhraseTimeout_Box = () => { - const { t } = useTranslation(); - const { currentMicPhraseTimeout, setMicPhraseTimeout } = useMicPhraseTimeout(); + const { t } = useI18n(); + const { currentMicPhraseTimeout, setMicPhraseTimeout } = useTranscription(); const selectFunction = (selected_data) => { setMicPhraseTimeout(selected_data.selected_id); @@ -96,8 +83,8 @@ const MicPhraseTimeout_Box = () => { ); }; const MicMaxWords_Box = () => { - const { t } = useTranslation(); - const { currentMicMaxWords, setMicMaxWords } = useMicMaxWords(); + const { t } = useI18n(); + const { currentMicMaxWords, setMicMaxWords } = useTranscription(); const selectFunction = (selected_data) => { setMicMaxWords(selected_data.selected_id); @@ -117,7 +104,7 @@ const MicMaxWords_Box = () => { }; const MicWordFilter_Box = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return ( { const Speaker_Container = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (
@@ -143,8 +130,8 @@ const Speaker_Container = () => { }; const SpeakerRecordTimeout_Box = () => { - const { t } = useTranslation(); - const { currentSpeakerRecordTimeout, setSpeakerRecordTimeout } = useSpeakerRecordTimeout(); + const { t } = useI18n(); + const { currentSpeakerRecordTimeout, setSpeakerRecordTimeout } = useTranscription(); const selectFunction = (selected_data) => { setSpeakerRecordTimeout(selected_data.selected_id); @@ -163,8 +150,8 @@ const SpeakerRecordTimeout_Box = () => { ); }; const SpeakerPhraseTimeout_Box = () => { - const { t } = useTranslation(); - const { currentSpeakerPhraseTimeout, setSpeakerPhraseTimeout } = useSpeakerPhraseTimeout(); + const { t } = useI18n(); + const { currentSpeakerPhraseTimeout, setSpeakerPhraseTimeout } = useTranscription(); const selectFunction = (selected_data) => { setSpeakerPhraseTimeout(selected_data.selected_id); @@ -182,8 +169,8 @@ const SpeakerPhraseTimeout_Box = () => { ); }; const SpeakerMaxWords_Box = () => { - const { t } = useTranslation(); - const { currentSpeakerMaxWords, setSpeakerMaxWords } = useSpeakerMaxWords(); + const { t } = useI18n(); + const { currentSpeakerMaxWords, setSpeakerMaxWords } = useTranscription(); const selectFunction = (selected_data) => { setSpeakerMaxWords(selected_data.selected_id); @@ -205,7 +192,7 @@ const SpeakerMaxWords_Box = () => { const TranscriptionEngine_Container = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (
@@ -217,8 +204,8 @@ const TranscriptionEngine_Container = () => { }; const TranscriptionEngine_Box = () => { - const { t } = useTranslation(); - const { currentSelectedTranscriptionEngine, setSelectedTranscriptionEngine } = useSelectedTranscriptionEngine(); + const { t } = useI18n(); + const { currentSelectedTranscriptionEngine, setSelectedTranscriptionEngine } = useTranscription(); return ( { }; const WhisperWeightType_Box = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentWhisperWeightTypeStatus, pendingWhisperWeightType, downloadWhisperWeight, - } = useWhisperWeightTypeStatus(); - const { currentSelectedWhisperWeightType, setSelectedWhisperWeightType } = useSelectedWhisperWeightType(); + } = useTranscription(); + const { currentSelectedWhisperWeightType, setSelectedWhisperWeightType } = useTranscription(); const selectFunction = (id) => { setSelectedWhisperWeightType(id); @@ -288,9 +275,9 @@ const WhisperWeightType_Box = () => { // Duplicate import { useComputeMode } from "@logics_common"; const WhisperComputeDevice_Box = () => { - const { t } = useTranslation(); - const { currentSelectedWhisperComputeDevice, setSelectedWhisperComputeDevice } = useSelectedWhisperComputeDevice(); - const { currentSelectableWhisperComputeDeviceList } = useSelectableWhisperComputeDeviceList(); + const { t } = useI18n(); + const { currentSelectedWhisperComputeDevice, setSelectedWhisperComputeDevice } = useTranscription(); + const { currentSelectableWhisperComputeDeviceList } = useTranscription(); const selectFunction = (selected_data) => { const target_obj = currentSelectableWhisperComputeDeviceList.data[selected_data.selected_id]; diff --git a/src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx b/src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx index 5c4dfa51..38c5a1e3 100644 --- a/src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/translation/Translation.jsx @@ -1,14 +1,10 @@ import { useEffect, useState } from "react"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./Translation.module.scss"; import { updateLabelsById } from "@utils"; import { - useDeepLAuthKey, - useCTranslate2WeightTypeStatus, - useSelectedCTranslate2WeightType, - useSelectedCTranslate2ComputeDevice, - useSelectableCTranslate2ComputeDeviceList, + useTranslation, } from "@logics_configs"; import { @@ -29,13 +25,15 @@ export const Translation = () => { }; const CTranslate2WeightType_Box = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentCTranslate2WeightTypeStatus, pendingCTranslate2WeightType, downloadCTranslate2Weight, - } = useCTranslate2WeightTypeStatus(); - const { currentSelectedCTranslate2WeightType, setSelectedCTranslate2WeightType } = useSelectedCTranslate2WeightType(); + + currentSelectedCTranslate2WeightType, + setSelectedCTranslate2WeightType, + } = useTranslation(); const selectFunction = (id) => { setSelectedCTranslate2WeightType(id); @@ -77,9 +75,9 @@ const CTranslate2WeightType_Box = () => { // Duplicate import { useComputeMode } from "@logics_common"; const CTranslation2ComputeDevice_Box = () => { - const { t } = useTranslation(); - const { currentSelectedCTranslate2ComputeDevice, setSelectedCTranslate2ComputeDevice } = useSelectedCTranslate2ComputeDevice(); - const { currentSelectableCTranslate2ComputeDeviceList } = useSelectableCTranslate2ComputeDeviceList(); + const { t } = useI18n(); + const { currentSelectedCTranslate2ComputeDevice, setSelectedCTranslate2ComputeDevice } = useTranslation(); + const { currentSelectableCTranslate2ComputeDeviceList } = useTranslation(); const selectFunction = (selected_data) => { const target_obj = currentSelectableCTranslate2ComputeDeviceList.data[selected_data.selected_id]; @@ -120,8 +118,8 @@ const CTranslation2ComputeDevice_Box = () => { }; const DeeplAuthKey_Box = () => { - const { t } = useTranslation(); - const { currentDeepLAuthKey, setDeepLAuthKey, deleteDeepLAuthKey } = useDeepLAuthKey(); + const { t } = useI18n(); + const { currentDeepLAuthKey, setDeepLAuthKey, deleteDeepLAuthKey } = useTranslation(); const [input_value, seInputValue] = useState(currentDeepLAuthKey.data); const onChangeFunction = (value) => { @@ -134,6 +132,7 @@ const DeeplAuthKey_Box = () => { }; useEffect(() => { + if (currentDeepLAuthKey.state === "pending") return; seInputValue(currentDeepLAuthKey.data); }, [currentDeepLAuthKey]); diff --git a/src-ui/app/config_page/setting_section/setting_box/vr/Vr.jsx b/src-ui/app/config_page/setting_section/setting_box/vr/Vr.jsx index b145bb44..31c38816 100644 --- a/src-ui/app/config_page/setting_section/setting_box/vr/Vr.jsx +++ b/src-ui/app/config_page/setting_section/setting_box/vr/Vr.jsx @@ -1,5 +1,5 @@ import React, { useState, useEffect, useRef } from "react"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import styles from "./Vr.module.scss"; import { ui_configs } from "@ui_configs"; @@ -15,12 +15,7 @@ import { } from "../_components/"; import { - useIsEnabledOverlaySmallLog, - useOverlaySmallLogSettings, - useIsEnabledOverlayLargeLog, - useOverlayLargeLogSettings, - useOverlayShowOnlyTranslatedMessages, - useSendTextToOverlay, + useVr, } from "@logics_configs"; import RedoSvg from "@images/redo.svg?react"; @@ -30,17 +25,23 @@ import TriangleSvg from "@images/triangle.svg?react"; import { randomIntMinMax } from "@utils"; export const Vr = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const [is_opened_small_settings, setIsOpenedSmallSettings] = useState(true); const toggleIsOpenedSmallSettings = () => { setIsOpenedSmallSettings(!is_opened_small_settings); }; - const { currentOverlaySmallLogSettings, setOverlaySmallLogSettings } = useOverlaySmallLogSettings(); - const { currentIsEnabledOverlaySmallLog, toggleIsEnabledOverlaySmallLog } = useIsEnabledOverlaySmallLog(); + const { + currentIsEnabledOverlayLargeLog, + toggleIsEnabledOverlayLargeLog, + currentIsEnabledOverlaySmallLog, + toggleIsEnabledOverlaySmallLog, + currentOverlayLargeLogSettings, + setOverlayLargeLogSettings, + currentOverlaySmallLogSettings, + setOverlaySmallLogSettings, + } = useVr(); - const { currentOverlayLargeLogSettings, setOverlayLargeLogSettings } = useOverlayLargeLogSettings(); - const { currentIsEnabledOverlayLargeLog, toggleIsEnabledOverlayLargeLog } = useIsEnabledOverlayLargeLog(); const restoreDefaultSettings = () => { setOverlaySmallLogSettings(ui_configs.overlay_small_log_default_settings); @@ -99,7 +100,7 @@ const OverlaySettingsContainer = ({ id }) => { - const { t } = useTranslation(); + const { t } = useI18n(); useEffect(() => { setSettings(current_overlay_settings); }, [current_overlay_settings]); @@ -193,7 +194,7 @@ const PageSwitcherContainer = (props) => { export const PositionControls = ({ settings, onchangeFunction, selectFunction, ui_configs, default_ui_configs }) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { variable_display: x_variable_display, @@ -302,7 +303,7 @@ export const PositionControls = ({ settings, onchangeFunction, selectFunction, u }; export const RotationControls = ({ settings, onchangeFunction, selectFunction, ui_configs, default_ui_configs }) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { variable_display: x_variable_display, @@ -443,7 +444,7 @@ const AdjustButtonContainer = ({ wrapper_class_name, is_max, is_min, countUp, co const OtherControls = ({settings, onchangeFunction, ui_configs}) => { - const { t } = useTranslation(); + const { t } = useI18n(); const ui_variable_opacity = (settings.opacity * 100).toFixed(0); const ui_variable_ui_scaling = (settings.ui_scaling * 100).toFixed(0); @@ -512,8 +513,8 @@ const OtherControls = ({settings, onchangeFunction, ui_configs}) => { const CommonSettingsContainer = () => { - const { t } = useTranslation(); - const { currentOverlayShowOnlyTranslatedMessages, toggleOverlayShowOnlyTranslatedMessages } = useOverlayShowOnlyTranslatedMessages(); + const { t } = useI18n(); + const { currentOverlayShowOnlyTranslatedMessages, toggleOverlayShowOnlyTranslatedMessages } = useVr(); return (
@@ -536,8 +537,8 @@ const ResetButton = ({onClickFunction}) => { }; const SendSampleTextToggleButton = () => { - const { t } = useTranslation(); - const { sendTextToOverlay } = useSendTextToOverlay(); + const { t } = useI18n(); + const { sendTextToOverlay } = useVr(); const [is_started, setIsStarted] = useState(false); useEffect(() => { diff --git a/src-ui/app/config_page/sidebar_section/SidebarSection.jsx b/src-ui/app/config_page/sidebar_section/SidebarSection.jsx index 341da4aa..b7d36272 100644 --- a/src-ui/app/config_page/sidebar_section/SidebarSection.jsx +++ b/src-ui/app/config_page/sidebar_section/SidebarSection.jsx @@ -26,11 +26,11 @@ export const SidebarSection = () => { import clsx from "clsx"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { useStore_SelectedConfigTabId } from "@store"; const Tab = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateSelectedConfigTabId, currentSelectedConfigTabId } = useStore_SelectedConfigTabId(); const onclickFunction = () => { updateSelectedConfigTabId(props.tab_id); diff --git a/src-ui/app/config_page/topbar/Topbar.jsx b/src-ui/app/config_page/topbar/Topbar.jsx index 64c8f593..9bc588d8 100644 --- a/src-ui/app/config_page/topbar/Topbar.jsx +++ b/src-ui/app/config_page/topbar/Topbar.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import styles from "./Topbar.module.scss"; @@ -10,7 +10,7 @@ import { SectionTitleBox } from "./section_title_box/SectionTitleBox"; import { CompactSwitchBox } from "./compact_switch_box/CompactSwitchBox"; export const Topbar = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentIsOpenedConfigPage, setIsOpenedConfigPage } = useIsOpenedConfigPage(); const closeConfigPage = () => { setIsOpenedConfigPage(false); diff --git a/src-ui/app/config_page/topbar/compact_switch_box/CompactSwitchBox.jsx b/src-ui/app/config_page/topbar/compact_switch_box/CompactSwitchBox.jsx index 4d36a1e5..5fad848e 100644 --- a/src-ui/app/config_page/topbar/compact_switch_box/CompactSwitchBox.jsx +++ b/src-ui/app/config_page/topbar/compact_switch_box/CompactSwitchBox.jsx @@ -1,9 +1,9 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./CompactSwitchBox.module.scss"; export const CompactSwitchBox = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (

{t("config_page.compact_mode")}

diff --git a/src-ui/app/config_page/topbar/section_title_box/SectionTitleBox.jsx b/src-ui/app/config_page/topbar/section_title_box/SectionTitleBox.jsx index 53bb6b16..df02935f 100644 --- a/src-ui/app/config_page/topbar/section_title_box/SectionTitleBox.jsx +++ b/src-ui/app/config_page/topbar/section_title_box/SectionTitleBox.jsx @@ -1,9 +1,9 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./SectionTitleBox.module.scss"; import { useStore_SelectedConfigTabId } from "@store"; export const SectionTitleBox = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentSelectedConfigTabId } = useStore_SelectedConfigTabId(); return (
diff --git a/src-ui/app/config_page/topbar/title_box/TitleBox.jsx b/src-ui/app/config_page/topbar/title_box/TitleBox.jsx index c2bb2355..61aad3eb 100644 --- a/src-ui/app/config_page/topbar/title_box/TitleBox.jsx +++ b/src-ui/app/config_page/topbar/title_box/TitleBox.jsx @@ -1,10 +1,10 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./TitleBox.module.scss"; import chato_img from "@images/chato_white.png"; export const TitleBox = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (
VRCT logo chato diff --git a/src-ui/app/config_page/version_label/VersionLabel.jsx b/src-ui/app/config_page/version_label/VersionLabel.jsx index 95abd94d..32540cc2 100644 --- a/src-ui/app/config_page/version_label/VersionLabel.jsx +++ b/src-ui/app/config_page/version_label/VersionLabel.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { useState } from "react"; import clsx from "clsx"; import styles from "./VersionLabel.module.scss"; @@ -10,7 +10,7 @@ import CheckMarkSvg from "@images/check_mark.svg?react"; export const VersionLabel = () => { const [is_copied, setIsCopied] = useState(false); - const { t } = useTranslation(); + const { t } = useI18n(); const { currentSoftwareVersion } = useSoftwareVersion(); const { currentComputeMode } = useComputeMode(); diff --git a/src-ui/app/main_page/main_section/MainSection.jsx b/src-ui/app/main_page/main_section/MainSection.jsx index b0ffb77c..5a9140df 100644 --- a/src-ui/app/main_page/main_section/MainSection.jsx +++ b/src-ui/app/main_page/main_section/MainSection.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./MainSection.module.scss"; import { TopBar } from "./top_bar/TopBar"; @@ -37,7 +37,7 @@ export const MainSection = () => { const HandleLanguageSelector = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentIsOpenedLanguageSelector, updateIsOpenedLanguageSelector } = useStore_IsOpenedLanguageSelector(); const { currentSelectedPresetTabNumber, diff --git a/src-ui/app/main_page/main_section/PluginHost.jsx b/src-ui/app/main_page/main_section/PluginHost.jsx index 071ac934..cedfe34e 100644 --- a/src-ui/app/main_page/main_section/PluginHost.jsx +++ b/src-ui/app/main_page/main_section/PluginHost.jsx @@ -1,14 +1,28 @@ -import React from "react"; +import { usePlugins } from "@logics_configs"; +import { ErrorBoundary } from "react-error-boundary"; -export const PluginHost = ({render_components}) => { +export const PluginHost = ({ render_components }) => { + const { setErrorPlugin } = usePlugins(); return ( <> - {render_components - .map((plugin, index) => { - const PluginComponent = plugin.component; - return PluginComponent ? : null; - })} + {render_components.map((plugin, index) => { + const PluginComponent = plugin.component; + const plugin_id = plugin.plugin_id; + + return PluginComponent ? ( + null} + onError={(_error, _info) => { + // Disable the plugin on error + setErrorPlugin(plugin_id, "disabled_due_to_an_error"); + }} + > + + + ) : null; + })} ); }; \ No newline at end of file diff --git a/src-ui/app/main_page/main_section/language_selector/LanguageSelector.jsx b/src-ui/app/main_page/main_section/language_selector/LanguageSelector.jsx index 8fce4e2d..6d4be514 100644 --- a/src-ui/app/main_page/main_section/language_selector/LanguageSelector.jsx +++ b/src-ui/app/main_page/main_section/language_selector/LanguageSelector.jsx @@ -1,12 +1,12 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; -import { useSelectableLanguageList } from "@logics_main"; +import { useLanguageSettings } from "@logics_main"; import styles from "./LanguageSelector.module.scss"; import { LanguageSelectorTopBar } from "./language_selector_top_bar/LanguageSelectorTopBar"; export const LanguageSelector = ({ title, onClickFunction }) => { - const { t } = useTranslation(); - const { currentSelectableLanguageList } = useSelectableLanguageList(); + const { t } = useI18n(); + const { currentSelectableLanguageList } = useLanguageSettings(); const groupLanguagesByFirstLetter = (languages) => { return languages.reduce((acc, { language, country }) => { diff --git a/src-ui/app/main_page/main_section/language_selector/language_selector_top_bar/LanguageSelectorTopBar.jsx b/src-ui/app/main_page/main_section/language_selector/language_selector_top_bar/LanguageSelectorTopBar.jsx index 1ea1c832..b0bdc8de 100644 --- a/src-ui/app/main_page/main_section/language_selector/language_selector_top_bar/LanguageSelectorTopBar.jsx +++ b/src-ui/app/main_page/main_section/language_selector/language_selector_top_bar/LanguageSelectorTopBar.jsx @@ -1,9 +1,9 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./LanguageSelectorTopBar.module.scss"; import { useStore_IsOpenedLanguageSelector } from "@store"; export const LanguageSelectorTopBar = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateIsOpenedLanguageSelector } = useStore_IsOpenedLanguageSelector(); const closeLanguageSelector = () => { updateIsOpenedLanguageSelector({ diff --git a/src-ui/app/main_page/main_section/message_container/log_box/LogBox.jsx b/src-ui/app/main_page/main_section/message_container/log_box/LogBox.jsx index 8aa8d2ec..aa37ac12 100644 --- a/src-ui/app/main_page/main_section/message_container/log_box/LogBox.jsx +++ b/src-ui/app/main_page/main_section/message_container/log_box/LogBox.jsx @@ -27,9 +27,9 @@ export const LogBox = () => { ); }; -import { useMessageLogUiScaling } from "@logics_configs"; +import { useAppearance } from "@logics_configs"; const MessageLogUiSizeController = () => { - const { currentMessageLogUiScaling } = useMessageLogUiScaling(); + const { currentMessageLogUiScaling } = useAppearance(); const font_size = currentMessageLogUiScaling.data / 100; useEffect(() => { diff --git a/src-ui/app/main_page/main_section/message_container/log_box/message_container/MessageContainer.jsx b/src-ui/app/main_page/main_section/message_container/log_box/message_container/MessageContainer.jsx index 1298c8da..d982f27c 100644 --- a/src-ui/app/main_page/main_section/message_container/log_box/message_container/MessageContainer.jsx +++ b/src-ui/app/main_page/main_section/message_container/log_box/message_container/MessageContainer.jsx @@ -1,18 +1,18 @@ import { useState } from "react"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import styles from "./MessageContainer.module.scss"; import { MessageSubMenuContainer } from "./message_sub_menu_container/MessageSubMenuContainer"; import { useMessage } from "@logics_common"; -import { useIsVisibleResendButton } from "@logics_main"; +import { useAppearance } from "@logics_configs"; export const MessageContainer = ({ messages, status, category, created_at }) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { sendMessage, updateMessageInputValue, } = useMessage(); - const { currentIsVisibleResendButton } = useIsVisibleResendButton(); + const { currentShowResendButton } = useAppearance(); const [is_hovered, setIsHovered] = useState(false); const [is_locked, setIsLocked] = useState(false); @@ -77,7 +77,7 @@ export const MessageContainer = ({ messages, status, category, created_at }) => )}
- {currentIsVisibleResendButton.data && is_sent_message && is_hovered ? ( + {currentShowResendButton.data && is_sent_message && is_hovered ? ( { }; const Title_p = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return

{t("main_page.message_log.resend_button_on_hover_desc")}

; }; diff --git a/src-ui/app/main_page/main_section/message_container/message_input_box/MessageInputBox.jsx b/src-ui/app/main_page/main_section/message_container/message_input_box/MessageInputBox.jsx index 765ea9e1..6aa32092 100644 --- a/src-ui/app/main_page/main_section/message_container/message_input_box/MessageInputBox.jsx +++ b/src-ui/app/main_page/main_section/message_container/message_input_box/MessageInputBox.jsx @@ -2,7 +2,7 @@ import { useState, useEffect, useLayoutEffect, useRef } from "react"; import styles from "./MessageInputBox.module.scss"; import SendMessageSvg from "@images/send_message.svg?react"; import { useMessage } from "@logics_common"; -import { useSendMessageButtonType, useEnableAutoClearMessageInputBox } from "@logics_configs"; +import { useAppearance, useOthers } from "@logics_configs"; import { useMessageLogScroll } from "@logics_main"; import { store } from "@store"; @@ -18,8 +18,8 @@ export const MessageInputBox = () => { stopTyping, } = useMessage(); - const { currentEnableAutoClearMessageInputBox } = useEnableAutoClearMessageInputBox(); - const { currentSendMessageButtonType } = useSendMessageButtonType(); + const { currentEnableAutoClearMessageInputBox } = useOthers(); + const { currentSendMessageButtonType } = useAppearance(); const { scrollToBottom } = useMessageLogScroll(); diff --git a/src-ui/app/main_page/main_section/message_container/message_log_settings_container/MessageLogSettingsContainer.jsx b/src-ui/app/main_page/main_section/message_container/message_log_settings_container/MessageLogSettingsContainer.jsx index 1d38fc28..ddff4a51 100644 --- a/src-ui/app/main_page/main_section/message_container/message_log_settings_container/MessageLogSettingsContainer.jsx +++ b/src-ui/app/main_page/main_section/message_container/message_log_settings_container/MessageLogSettingsContainer.jsx @@ -1,30 +1,22 @@ import { useState } from "react"; import styles from "./MessageLogSettingsContainer.module.scss"; import clsx from "clsx"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; -import { useIsVisibleResendButton } from "@logics_main"; import { MessageLogUiScalingContainer } from "@setting_box"; -import { Checkbox } from "@common_components"; import ConfigSvg from "@images/configuration.svg?react"; export const MessageLogSettingsContainer = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const [is_opened, setIsOpened] = useState(false); const [is_hovered, setIsHovered] = useState(false); - const { currentIsVisibleResendButton, toggleIsVisibleResendButton } = useIsVisibleResendButton(); - const container_class_name = clsx(styles.container, { [styles.to_visible_toggle_bar]: props.to_visible_toggle_bar, [styles.is_hovered]: is_hovered, [styles.is_opened]: is_opened }); - const toggleVisibleResendButton = () => { - toggleIsVisibleResendButton(); - }; - return (
setIsHovered(true)} @@ -38,15 +30,6 @@ export const MessageLogSettingsContainer = (props) => {
-
-

{t("main_page.message_log.show_resend_button")}

- -
); diff --git a/src-ui/app/main_page/main_section/top_bar/right_side_components/RightSideComponents.jsx b/src-ui/app/main_page/main_section/top_bar/right_side_components/RightSideComponents.jsx index 3f8be6e2..6c1ff7d3 100644 --- a/src-ui/app/main_page/main_section/top_bar/right_side_components/RightSideComponents.jsx +++ b/src-ui/app/main_page/main_section/top_bar/right_side_components/RightSideComponents.jsx @@ -1,11 +1,11 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./RightSideComponents.module.scss"; import RefreshSvg from "@images/refresh.svg?react"; import HelpSvg from "@images/help.svg?react"; import { useStore_OpenedQuickSetting } from "@store"; import { useSoftwareVersion } from "@logics_common"; -import { useIsEnabledOverlaySmallLog, useIsEnabledOverlayLargeLog, useEnableVrcMicMuteSync } from "@logics_configs"; +import { useVr, useOthers } from "@logics_configs"; import { OpenQuickSettingButton } from "./_buttons/OpenQuickSettingButton"; export const RightSideComponents = () => { @@ -30,10 +30,12 @@ export const RightSideComponents = () => { }; const OpenOverlayQuickSetting = () => { - // const { t } = useTranslation(); + // const { t } = useI18n(); const { updateOpenedQuickSetting } = useStore_OpenedQuickSetting(); - const { currentIsEnabledOverlaySmallLog } = useIsEnabledOverlaySmallLog(); - const { currentIsEnabledOverlayLargeLog } = useIsEnabledOverlayLargeLog(); + const { + currentIsEnabledOverlaySmallLog, + currentIsEnabledOverlayLargeLog, + } = useVr(); const onClickFunction = () => { updateOpenedQuickSetting("overlay"); @@ -50,7 +52,7 @@ const OpenOverlayQuickSetting = () => { ); }; const PluginsQuickSetting = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateOpenedQuickSetting } = useStore_OpenedQuickSetting(); const onClickFunction = () => { @@ -66,9 +68,9 @@ const PluginsQuickSetting = () => { }; const OpenVrcMicMuteSyncQuickSetting = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateOpenedQuickSetting } = useStore_OpenedQuickSetting(); - const { currentEnableVrcMicMuteSync } = useEnableVrcMicMuteSync(); + const { currentEnableVrcMicMuteSync } = useOthers(); const onClickFunction = () => { updateOpenedQuickSetting("vrc_mic_mute_sync"); @@ -85,7 +87,7 @@ const OpenVrcMicMuteSyncQuickSetting = () => { const SoftwareUpdateAvailableButton = () => { const { currentLatestSoftwareVersionInfo } = useSoftwareVersion(); - const { t } = useTranslation(); + const { t } = useI18n(); if (currentLatestSoftwareVersionInfo.data.is_update_available === false) return null; const { updateOpenedQuickSetting } = useStore_OpenedQuickSetting(); diff --git a/src-ui/app/main_page/main_section/top_bar/right_side_components/_buttons/OpenQuickSettingButton.jsx b/src-ui/app/main_page/main_section/top_bar/right_side_components/_buttons/OpenQuickSettingButton.jsx index abc779e3..c24f40f4 100644 --- a/src-ui/app/main_page/main_section/top_bar/right_side_components/_buttons/OpenQuickSettingButton.jsx +++ b/src-ui/app/main_page/main_section/top_bar/right_side_components/_buttons/OpenQuickSettingButton.jsx @@ -1,9 +1,9 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import styles from "./OpenQuickSettingButton.module.scss"; export const OpenQuickSettingButton = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const variable = (typeof props.variable === "boolean") ? props.variable : null; return (
diff --git a/src-ui/app/main_page/sidebar_section/language_settings/LanguageSettings.jsx b/src-ui/app/main_page/sidebar_section/language_settings/LanguageSettings.jsx index 7d90bdf4..4665896f 100644 --- a/src-ui/app/main_page/sidebar_section/language_settings/LanguageSettings.jsx +++ b/src-ui/app/main_page/sidebar_section/language_settings/LanguageSettings.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./LanguageSettings.module.scss"; import { PresetTabSelector } from "./preset_tab_selector/PresetTabSelector"; import { LanguageSelectorOpenButton } from "./language_selector_open_button/LanguageSelectorOpenButton"; @@ -8,7 +8,7 @@ import { AddRemoveTargetLanguageButtons } from "./add_remove_target_language_but import { useStore_IsOpenedTranslatorSelector } from "@store"; export const LanguageSettings = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateIsOpenedTranslatorSelector } = useStore_IsOpenedTranslatorSelector(); const closeTranslatorSelector = () => updateIsOpenedTranslatorSelector(false); @@ -26,7 +26,7 @@ import HeadphonesSvg from "@images/headphones.svg?react"; import { useMainFunction } from "@logics_main"; const PresetContainer = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentTranscriptionSendStatus, currentTranscriptionReceiveStatus } = useMainFunction(); const yourLanguageSettings = { diff --git a/src-ui/app/main_page/sidebar_section/language_settings/language_selector_open_button/LanguageSelectorOpenButton.jsx b/src-ui/app/main_page/sidebar_section/language_settings/language_selector_open_button/LanguageSelectorOpenButton.jsx index eacbf8f4..e6098a3f 100644 --- a/src-ui/app/main_page/sidebar_section/language_settings/language_selector_open_button/LanguageSelectorOpenButton.jsx +++ b/src-ui/app/main_page/sidebar_section/language_settings/language_selector_open_button/LanguageSelectorOpenButton.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import styles from "./LanguageSelectorOpenButton.module.scss"; import ArrowLeftSvg from "@images/arrow_left.svg?react"; @@ -8,7 +8,7 @@ import { } from "@logics_main"; export const LanguageSelectorOpenButton = ({ TurnedOnSvgComponent, is_turned_on, selector_key, target_key }) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateIsOpenedLanguageSelector, currentIsOpenedLanguageSelector } = useStore_IsOpenedLanguageSelector(); const { diff --git a/src-ui/app/main_page/sidebar_section/language_settings/language_swap_button/LanguageSwapButton.jsx b/src-ui/app/main_page/sidebar_section/language_settings/language_swap_button/LanguageSwapButton.jsx index dd479a65..0c953f96 100644 --- a/src-ui/app/main_page/sidebar_section/language_settings/language_swap_button/LanguageSwapButton.jsx +++ b/src-ui/app/main_page/sidebar_section/language_settings/language_swap_button/LanguageSwapButton.jsx @@ -1,6 +1,6 @@ import { useState } from "react"; import clsx from "clsx"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import styles from "./LanguageSwapButton.module.scss"; @@ -9,8 +9,8 @@ import { useLanguageSettings } from "@logics_main"; export const LanguageSwapButton = () => { const [isHovered, setIsHovered] = useState(false); - const { t } = useTranslation(); - const { runLanguageSwap } = useLanguageSettings(); + const { t } = useI18n(); + const { swapSelectedLanguages } = useLanguageSettings(); const label = isHovered ? t("main_page.swap_button_label") @@ -29,7 +29,7 @@ export const LanguageSwapButton = () => { className={styles.swap_button_wrapper} onMouseEnter={handleMouseEnter} onMouseLeave={handleMouseLeave} - onClick={runLanguageSwap} + onClick={swapSelectedLanguages} >

{label}

diff --git a/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.jsx b/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.jsx index 7a869e8a..773aab96 100644 --- a/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.jsx +++ b/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { updateLabelsById } from "@utils"; import styles from "./TranslatorSelectorOpenButton.module.scss"; import { TranslatorSelector } from "./translator_selector/TranslatorSelector"; @@ -7,7 +7,7 @@ import { useLanguageSettings } from "@logics_main"; import WarningSvg from "@images/warning.svg?react"; export const TranslatorSelectorOpenButton = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { currentSelectedYourLanguages, currentSelectedTargetLanguages, diff --git a/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.module.scss b/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.module.scss index 6549c5b3..ed8a1ab7 100644 --- a/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.module.scss +++ b/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/TranslatorSelectorOpenButton.module.scss @@ -31,5 +31,5 @@ margin-left: 0.2rem; padding-bottom: 0.2rem; width: 1.8rem; - color: var(--waring_color); + color: var(--warning_color); } \ No newline at end of file diff --git a/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/translator_selector/TranslatorSelector.jsx b/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/translator_selector/TranslatorSelector.jsx index cdbc159e..094c9255 100644 --- a/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/translator_selector/TranslatorSelector.jsx +++ b/src-ui/app/main_page/sidebar_section/language_settings/translator_selector_open_button/translator_selector/TranslatorSelector.jsx @@ -1,12 +1,13 @@ import clsx from "clsx"; import styles from "./TranslatorSelector.module.scss"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { chunkArray } from "@utils"; import { useStore_IsOpenedTranslatorSelector } from "@store"; import { useLanguageSettings } from "@logics_main"; -export const TranslatorSelector = ({selected_id, translation_engines, is_selected_same_language}) => { const { t } = useTranslation(); +export const TranslatorSelector = ({selected_id, translation_engines, is_selected_same_language}) => { + const { t } = useI18n(); const columns = chunkArray(translation_engines, 2); return ( @@ -46,7 +47,7 @@ export const TranslatorSelector = ({selected_id, translation_engines, is_selecte }; const TranslatorBox = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); const { setSelectedTranslationEngines} = useLanguageSettings(); const { updateIsOpenedTranslatorSelector} = useStore_IsOpenedTranslatorSelector(); diff --git a/src-ui/app/main_page/sidebar_section/main_function_switch/MainFunctionSwitch.jsx b/src-ui/app/main_page/sidebar_section/main_function_switch/MainFunctionSwitch.jsx index 991239f8..b3f031b6 100644 --- a/src-ui/app/main_page/sidebar_section/main_function_switch/MainFunctionSwitch.jsx +++ b/src-ui/app/main_page/sidebar_section/main_function_switch/MainFunctionSwitch.jsx @@ -1,4 +1,4 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import clsx from "clsx"; import styles from "./MainFunctionSwitch.module.scss"; import TranslationSvg from "@images/translation.svg?react"; @@ -11,7 +11,7 @@ import { } from "@logics_main"; export const MainFunctionSwitch = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { toggleTranslation, currentTranslationStatus, diff --git a/src-ui/app/error_boundary/AppErrorBoundary.jsx b/src-ui/app/others/error_boundary/AppErrorBoundary.jsx similarity index 96% rename from src-ui/app/error_boundary/AppErrorBoundary.jsx rename to src-ui/app/others/error_boundary/AppErrorBoundary.jsx index 4aeb34a2..37a1cc23 100644 --- a/src-ui/app/error_boundary/AppErrorBoundary.jsx +++ b/src-ui/app/others/error_boundary/AppErrorBoundary.jsx @@ -65,6 +65,7 @@ const ErrorContainer = ({error}) => { ); }; +// Duplicated const CloseButtonContainer = () => { const { asyncCloseApp } = useWindow(); return ( diff --git a/src-ui/app/error_boundary/AppErrorBoundary.module.scss b/src-ui/app/others/error_boundary/AppErrorBoundary.module.scss similarity index 94% rename from src-ui/app/error_boundary/AppErrorBoundary.module.scss rename to src-ui/app/others/error_boundary/AppErrorBoundary.module.scss index 2abb2710..2ff85390 100644 --- a/src-ui/app/error_boundary/AppErrorBoundary.module.scss +++ b/src-ui/app/others/error_boundary/AppErrorBoundary.module.scss @@ -72,6 +72,7 @@ +// Duplicated .close_button_wrapper { position: absolute; top: 0; diff --git a/src-ui/app/error_boundary/contacts_container/ContactsContainer.jsx b/src-ui/app/others/error_boundary/contacts_container/ContactsContainer.jsx similarity index 100% rename from src-ui/app/error_boundary/contacts_container/ContactsContainer.jsx rename to src-ui/app/others/error_boundary/contacts_container/ContactsContainer.jsx diff --git a/src-ui/app/error_boundary/contacts_container/ContactsContainer.module.scss b/src-ui/app/others/error_boundary/contacts_container/ContactsContainer.module.scss similarity index 100% rename from src-ui/app/error_boundary/contacts_container/ContactsContainer.module.scss rename to src-ui/app/others/error_boundary/contacts_container/ContactsContainer.module.scss diff --git a/src-ui/app/others/index.js b/src-ui/app/others/index.js new file mode 100644 index 00000000..80d702e7 --- /dev/null +++ b/src-ui/app/others/index.js @@ -0,0 +1,6 @@ +export { WindowTitleBar } from "./window_title_bar/WindowTitleBar.jsx"; +export { SplashComponent } from "./splash_component/SplashComponent.jsx"; +export { UpdatingComponent } from "./updating_component/UpdatingComponent.jsx"; +export { ModalController } from "./modal_controller/ModalController.jsx"; +export { SnackbarController } from "./snackbar_controller/SnackbarController.jsx"; +export { AppErrorBoundary } from "./error_boundary/AppErrorBoundary.jsx"; \ No newline at end of file diff --git a/src-ui/app/modal_controller/ModalController.jsx b/src-ui/app/others/modal_controller/ModalController.jsx similarity index 100% rename from src-ui/app/modal_controller/ModalController.jsx rename to src-ui/app/others/modal_controller/ModalController.jsx diff --git a/src-ui/app/modal_controller/ModalController.module.scss b/src-ui/app/others/modal_controller/ModalController.module.scss similarity index 100% rename from src-ui/app/modal_controller/ModalController.module.scss rename to src-ui/app/others/modal_controller/ModalController.module.scss diff --git a/src-ui/app/modal_controller/update_modal/UpdateModal.jsx b/src-ui/app/others/modal_controller/update_modal/UpdateModal.jsx similarity index 95% rename from src-ui/app/modal_controller/update_modal/UpdateModal.jsx rename to src-ui/app/others/modal_controller/update_modal/UpdateModal.jsx index dd8f0f43..11198da7 100644 --- a/src-ui/app/modal_controller/update_modal/UpdateModal.jsx +++ b/src-ui/app/others/modal_controller/update_modal/UpdateModal.jsx @@ -1,6 +1,6 @@ import clsx from "clsx"; import styles from "./UpdateModal.module.scss"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { useStore_OpenedQuickSetting } from "@store"; import { usePlugins } from "@logics_configs"; import { @@ -13,7 +13,7 @@ import { import { PluginCompatibilityList } from "./plugins_compatibility_list/PluginCompatibilityList"; export const UpdateModal = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { updateOpenedQuickSetting } = useStore_OpenedQuickSetting(); const { updateSoftware, updateSoftware_CUDA } = useUpdateSoftware(); const { updateIsSoftwareUpdating } = useIsSoftwareUpdating(); @@ -91,7 +91,7 @@ const VersionDescComponent = (props) => { }; const CurrentVersionLabel = (props) => { - const { t } = useTranslation(); + const { t } = useI18n(); if (props.is_latest_version_already) { return

{t("update_modal.is_latest_version_already")}

; diff --git a/src-ui/app/modal_controller/update_modal/UpdateModal.module.scss b/src-ui/app/others/modal_controller/update_modal/UpdateModal.module.scss similarity index 100% rename from src-ui/app/modal_controller/update_modal/UpdateModal.module.scss rename to src-ui/app/others/modal_controller/update_modal/UpdateModal.module.scss diff --git a/src-ui/app/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.jsx b/src-ui/app/others/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.jsx similarity index 100% rename from src-ui/app/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.jsx rename to src-ui/app/others/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.jsx diff --git a/src-ui/app/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.module.scss b/src-ui/app/others/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.module.scss similarity index 91% rename from src-ui/app/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.module.scss rename to src-ui/app/others/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.module.scss index 0b439619..a82112e1 100644 --- a/src-ui/app/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.module.scss +++ b/src-ui/app/others/modal_controller/update_modal/plugins_compatibility_list/PluginCompatibilityList.module.scss @@ -54,7 +54,7 @@ .warning_svg { padding-bottom: 0.4rem; width: 2.4rem; - color: var(--waring_color); + color: var(--warning_color); flex-shrink: 0; } diff --git a/src-ui/app/others/snackbar_controller/ReactToastifyOverrideClass.scss b/src-ui/app/others/snackbar_controller/ReactToastifyOverrideClass.scss new file mode 100644 index 00000000..5e0a2539 --- /dev/null +++ b/src-ui/app/others/snackbar_controller/ReactToastifyOverrideClass.scss @@ -0,0 +1,144 @@ +:root { + --toastify-color-light: #fff; + --toastify-color-dark: var(--dark_950_color); + --toastify-color-info: var(--sent_400_color); + --toastify-color-success: var(--primary_400_color); + --toastify-color-warning: var(--warning_bc_color); + --toastify-color-error: var(--error_bc_color); + --toastify-color-transparent: rgba(255, 255, 255, 0.7); + + --toastify-icon-color-info: var(--toastify-color-info); + --toastify-icon-color-success: var(--toastify-color-success); + --toastify-icon-color-warning: var(--toastify-color-warning); + --toastify-icon-color-error: var(--toastify-color-error); + + --toastify-container-width: fit-content; + --toastify-toast-width: 32rem; + --toastify-toast-offset: 1.6rem; + --toastify-toast-top: max(var(--toastify-toast-offset), env(safe-area-inset-top)); + --toastify-toast-right: max(var(--toastify-toast-offset), env(safe-area-inset-right)); + --toastify-toast-left: max(var(--toastify-toast-offset), env(safe-area-inset-left)); + --toastify-toast-bottom: max(var(--toastify-toast-offset), env(safe-area-inset-bottom)); + --toastify-toast-background: #fff; + --toastify-toast-padding: 1.4rem; + --toastify-toast-min-height: 6.4rem; + --toastify-toast-max-height: 80rem; + --toastify-toast-bd-radius: 0.6rem; + --toastify-toast-shadow: .0 0.4rem 1.2rem rgba(0, 0, 0, 0.1); + --toastify-font-family: var(--font_family); + --toastify-z-index: 9999; + --toastify-text-color-light: #757575; + --toastify-text-color-dark: var(--dark_basic_text_color); + + /* Used only for colored theme */ + --toastify-text-color-info: var(--dark_basic_text_color); + --toastify-text-color-success: var(--dark_basic_text_color); + --toastify-text-color-warning: var(--dark_basic_text_color); + --toastify-text-color-error: var(--dark_basic_text_color); + + --toastify-spinner-color: #616161; + --toastify-spinner-color-empty-area: #e0e0e0; + --toastify-color-progress-light: linear-gradient(to right, #4cd964, #5ac8fa, #007aff, #34aadc, #5856d6, #ff2d55); + --toastify-color-progress-dark: #bb86fc; + --toastify-color-progress-info: var(--toastify-color-info); + --toastify-color-progress-success: var(--toastify-color-success); + --toastify-color-progress-warning: var(--toastify-color-warning); + --toastify-color-progress-error: var(--toastify-color-error); + /* used to control the opacity of the progress trail */ + --toastify-color-progress-bgo: 0.2; +} + + +.Toastify__toast { + // -------------------------------------------------------- + // Default Settings + // -------------------------------------------------------- + position: relative; + touch-action: none; + // width: var(--toastify-toast-width); + min-height: var(--toastify-toast-min-height); + box-sizing: border-box; + margin-bottom: 1rem; + // padding: var(--toastify-toast-padding); + border-radius: 0.6rem; + box-shadow: none; + max-height: var(--toastify-toast-max-height); + // font-family: "Yu Gothic UI"; + // font-family: var(--toastify-font-family); + // z-index: 0; + // display: flex; + // flex: 1 auto; + // align-items: center; + word-break: break-word; + // -------------------------------------------------------- + // -------------------------------------------------------- + + + // Comment out above and override. Commented out is just for memorization. + overflow: hidden; + display: flex; + justify-content: start; + align-items: center; + font-size: 1.4rem; + width: fit-content; + max-width: 70vw; + padding-right: 4rem; + background-color: var(--dark_950_color); + gap: 0.6rem; + white-space: pre-wrap; +} + +.Toastify__progress-bar--wrp { + height: 0.4rem; +} +.Toastify__progress-bar--success { + background: var(--success_bc_color); +} + +.Toastify__progress-bar--warning { + background: var(--warning_bc_color); +} + +.Toastify__progress-bar--error { + background: var(--error_bc_color); +} + + +.Toastify__toast-icon { + width: fit-content; + max-width: 2.8rem; + min-width: 2.8rem; + justify-content: center; + align-items: center; +} + +@keyframes fade_in { + 0% { + opacity: 0; + } + 100% { + opacity: 1; + } +} +@keyframes fade_out { + 0% { + opacity: 1; + } + 100% { + opacity: 0; + } +} +.fade_in { + opacity: 0; + animation-name: fade_in; + animation-duration: 0.1s; + animation-timing-function: ease-out; + animation-fill-mode: forwards; +} +.fade_out { + opacity: 1; + animation-name: fade_out; + animation-duration: 0.1s; + animation-timing-function: ease-in; + animation-fill-mode: forwards; +} \ No newline at end of file diff --git a/src-ui/app/others/snackbar_controller/SnackbarController.jsx b/src-ui/app/others/snackbar_controller/SnackbarController.jsx new file mode 100644 index 00000000..60edac1f --- /dev/null +++ b/src-ui/app/others/snackbar_controller/SnackbarController.jsx @@ -0,0 +1,115 @@ +import React, { useEffect, useState } from "react"; +import { ToastContainer, toast, cssTransition } from "react-toastify"; +import clsx from "clsx"; + +import "./ReactToastifyOverrideClass.scss"; +import styles from "./SnackbarController.module.scss"; + +import XMarkSvg from "@images/cancel.svg?react"; +import WarningSvg from "@images/warning.svg?react"; +import MegaphoneSvg from "@images/megaphone.svg?react"; +import CheckMarkSvg from "@images/check_mark.svg?react"; +import ErrorSvg from "@images/error.svg?react"; + +import { useNotificationStatus } from "@logics_common"; + +const CustomTransition = cssTransition({ + enter: "fade_in", + exit: "fade_out", + collapse: false, +}); + + +export const SnackbarController = () => { + const { currentNotificationStatus, closeNotification } = useNotificationStatus(); + const [containerKey, setContainerKey] = useState(0); + + const settings = currentNotificationStatus.data; + + const snackbar_classname = clsx( + styles.snackbar_content, + { + [styles.is_success]: settings.status === "success", + [styles.is_warning]: settings.status === "warning", + [styles.is_error]: settings.status === "error", + } + ); + + let hide_duration = 5000; + if (settings.options?.hide_duration === null) { + hide_duration = false; + } else if (Number(settings.options?.hide_duration)) { + hide_duration = Number(settings.options?.hide_duration); + } + + + useEffect(() => { + if (!settings.is_open) return; + + const message_text = settings.message; + const category_id = settings.category_id ? settings.category_id : message_text; + + const to_hide_progress_bar = (settings.options?.to_hide_progress_bar === true) ? true : false; + + const asyncShowNotification = async () => { + setTimeout(() => { + toast(message_text, { + toastId: category_id, + type: settings.status, + autoClose: hide_duration, + transition: CustomTransition, + toastClassName: snackbar_classname, + hideProgressBar: to_hide_progress_bar, + progressClassName: styles.toast_progress, + closeButton: , + onClose: () => { + closeNotification(); + }, + }); + }, 100); + }; + + // setContainerKey(prevKey => prevKey + 1); + asyncShowNotification(); + + }, [settings]); + + return ( + { + switch (type) { + case "info": + return ; + case "error": + return ; + case "success": + return ; + case "warning": + return ; + default: + return null; + } + }} + /> + ); +}; + +const CloseButtonContainer = ({ closeToast }) => { + return ( + + ); +}; \ No newline at end of file diff --git a/src-ui/app/others/snackbar_controller/SnackbarController.module.scss b/src-ui/app/others/snackbar_controller/SnackbarController.module.scss new file mode 100644 index 00000000..ebb18798 --- /dev/null +++ b/src-ui/app/others/snackbar_controller/SnackbarController.module.scss @@ -0,0 +1,75 @@ +.snackbar_content { + position: relative; + padding: 1.2rem 1.6rem; + border-radius: 0.8rem; + font-size: 1.4rem; + box-shadow: 0 0.2rem 0.8rem rgba(0, 0, 0, 0.5); +} + +// .is_success { +// background-color: var(--success_bc_color); +// } + +// .is_warning { +// background-color: var(--warning_bc_color); +// } + +// .is_error { +// background-color: var(--error_bc_color); +// } + + +.megaphone_svg { + color: var(--dark_200_color); + width: 2.4rem; +} +.error_svg { + color: var(--error_bc_color); + width: 2.4rem; +} +.check_mark_svg { + color: var(--primary_400_color); + width: 2rem; +} +.warning_svg { + color: var(--warning_color); + width: 2.4rem; +} + + + +// Duplicated (Customized) +.close_button_wrapper { + position: absolute; + top: 0; + left: 100%; + transform: translate(-50%, -50%) rotate(45deg); + display: flex; + justify-content: center; + align-items: end; + width: 5.6rem; + aspect-ratio: 1 / 1; + &:hover { + background-color: var(--error_bc_color); + & .x_mark_svg { + color: var(--dark_200_color); + transform: rotate(45deg); + } + } + &:active { + background-color: var(--error_bc_active_color); + } + transition: all 0.1s ease; +} + +.close_button { + // width: 100%; + // height: 100%; +} + +.x_mark_svg { + width: 2rem; + transform: rotate(-45deg); + color: var(--dark_700_color); + transition: transform 0.3s ease; +} \ No newline at end of file diff --git a/src-ui/app/splash_component/SplashComponent.jsx b/src-ui/app/others/splash_component/SplashComponent.jsx similarity index 94% rename from src-ui/app/splash_component/SplashComponent.jsx rename to src-ui/app/others/splash_component/SplashComponent.jsx index 2943bad0..a9ac4aeb 100644 --- a/src-ui/app/splash_component/SplashComponent.jsx +++ b/src-ui/app/others/splash_component/SplashComponent.jsx @@ -1,7 +1,7 @@ import { useState, useEffect } from "react"; import styles from "./SplashComponent.module.scss"; -import { StartUpProgressContainer } from "./start_up_progress_container/StartUpProgressContainer/"; -import { DownloadModelsContainer } from "./download_models_container/DownloadModelsContainer/"; +import { StartUpProgressContainer } from "./start_up_progress_container/StartUpProgressContainer"; +import { DownloadModelsContainer } from "./download_models_container/DownloadModelsContainer"; import MegaphoneSvg from "@images/megaphone.svg?react"; import XMarkSvg from "@images/cancel.svg?react"; import { useWindow } from "@logics_common"; @@ -71,7 +71,7 @@ const AnnouncementsContainer = () => { }; - +// Duplicated const CloseButtonContainer = () => { const { asyncCloseApp } = useWindow(); diff --git a/src-ui/app/splash_component/SplashComponent.module.scss b/src-ui/app/others/splash_component/SplashComponent.module.scss similarity index 94% rename from src-ui/app/splash_component/SplashComponent.module.scss rename to src-ui/app/others/splash_component/SplashComponent.module.scss index f279b21b..bae69063 100644 --- a/src-ui/app/splash_component/SplashComponent.module.scss +++ b/src-ui/app/others/splash_component/SplashComponent.module.scss @@ -67,7 +67,7 @@ } - +// Duplicated .close_button_wrapper { position: absolute; top: 0; diff --git a/src-ui/app/splash_component/download_models_container/DownloadModelsContainer.jsx b/src-ui/app/others/splash_component/download_models_container/DownloadModelsContainer.jsx similarity index 89% rename from src-ui/app/splash_component/download_models_container/DownloadModelsContainer.jsx rename to src-ui/app/others/splash_component/download_models_container/DownloadModelsContainer.jsx index 9e3d8e67..9f1768f1 100644 --- a/src-ui/app/splash_component/download_models_container/DownloadModelsContainer.jsx +++ b/src-ui/app/others/splash_component/download_models_container/DownloadModelsContainer.jsx @@ -3,13 +3,13 @@ import vrct_logo_for_dark_mode from "@images/vrct_logo_for_dark_mode.png"; import vrct_now_downloading from "@images/VRCT_now_downloading.png"; import { - useCTranslate2WeightTypeStatus, - useWhisperWeightTypeStatus, + useTranslation, + useTranscription, } from "@logics_configs"; export const DownloadModelsContainer = () => { - const { currentCTranslate2WeightTypeStatus } = useCTranslate2WeightTypeStatus(); - const { currentWhisperWeightTypeStatus } = useWhisperWeightTypeStatus(); + const { currentCTranslate2WeightTypeStatus } = useTranslation(); + const { currentWhisperWeightTypeStatus } = useTranscription(); const c_translate_2 = currentCTranslate2WeightTypeStatus.data.find(d => d.id === "small"); const whisper = currentWhisperWeightTypeStatus.data.find(d => d.id === "base"); diff --git a/src-ui/app/splash_component/download_models_container/DownloadModelsContainer.module.scss b/src-ui/app/others/splash_component/download_models_container/DownloadModelsContainer.module.scss similarity index 100% rename from src-ui/app/splash_component/download_models_container/DownloadModelsContainer.module.scss rename to src-ui/app/others/splash_component/download_models_container/DownloadModelsContainer.module.scss diff --git a/src-ui/app/splash_component/start_up_progress_container/StartUpProgressContainer.jsx b/src-ui/app/others/splash_component/start_up_progress_container/StartUpProgressContainer.jsx similarity index 100% rename from src-ui/app/splash_component/start_up_progress_container/StartUpProgressContainer.jsx rename to src-ui/app/others/splash_component/start_up_progress_container/StartUpProgressContainer.jsx diff --git a/src-ui/app/splash_component/start_up_progress_container/StartUpProgressContainer.module.scss b/src-ui/app/others/splash_component/start_up_progress_container/StartUpProgressContainer.module.scss similarity index 100% rename from src-ui/app/splash_component/start_up_progress_container/StartUpProgressContainer.module.scss rename to src-ui/app/others/splash_component/start_up_progress_container/StartUpProgressContainer.module.scss diff --git a/src-ui/app/updating_component/UpdatingComponent.jsx b/src-ui/app/others/updating_component/UpdatingComponent.jsx similarity index 87% rename from src-ui/app/updating_component/UpdatingComponent.jsx rename to src-ui/app/others/updating_component/UpdatingComponent.jsx index 5dce4765..df362623 100644 --- a/src-ui/app/updating_component/UpdatingComponent.jsx +++ b/src-ui/app/others/updating_component/UpdatingComponent.jsx @@ -1,10 +1,10 @@ import styles from "./UpdatingComponent.module.scss"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import CircularProgress from "@mui/material/CircularProgress"; import chat_white_square from "@images/chato_white_square.png"; export const UpdatingComponent = () => { - const { t } = useTranslation(); + const { t } = useI18n(); return (
diff --git a/src-ui/app/updating_component/UpdatingComponent.module.scss b/src-ui/app/others/updating_component/UpdatingComponent.module.scss similarity index 100% rename from src-ui/app/updating_component/UpdatingComponent.module.scss rename to src-ui/app/others/updating_component/UpdatingComponent.module.scss diff --git a/src-ui/app/window_title_bar/WindowTitleBar.jsx b/src-ui/app/others/window_title_bar/WindowTitleBar.jsx similarity index 100% rename from src-ui/app/window_title_bar/WindowTitleBar.jsx rename to src-ui/app/others/window_title_bar/WindowTitleBar.jsx diff --git a/src-ui/app/window_title_bar/WindowTitleBar.module.scss b/src-ui/app/others/window_title_bar/WindowTitleBar.module.scss similarity index 100% rename from src-ui/app/window_title_bar/WindowTitleBar.module.scss rename to src-ui/app/others/window_title_bar/WindowTitleBar.module.scss diff --git a/src-ui/app/snackbar_controller/SnackbarController.jsx b/src-ui/app/snackbar_controller/SnackbarController.jsx deleted file mode 100644 index e503e695..00000000 --- a/src-ui/app/snackbar_controller/SnackbarController.jsx +++ /dev/null @@ -1,46 +0,0 @@ -import clsx from "clsx"; -import Snackbar from "@mui/material/Snackbar"; -import Slide from "@mui/material/Slide"; - -import styles from "./SnackbarController.module.scss"; -import { useNotificationStatus } from "@logics_common"; - -export const SnackbarController = () => { - const { currentNotificationStatus, closeNotification } = useNotificationStatus(); - - const handleClose = (event, reason) => { - closeNotification(event, reason); - }; - - const snackbar_classname = clsx(styles.snackbar_content, { - [styles.is_success]: currentNotificationStatus.data.status === "success", - [styles.is_warning]: currentNotificationStatus.data.status === "warning", - [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 ( -
- -
-

{settings.message}

-
-
-
- ); -}; - -const SlideTransition = (props) => { - return ; -}; diff --git a/src-ui/app/snackbar_controller/SnackbarController.module.scss b/src-ui/app/snackbar_controller/SnackbarController.module.scss deleted file mode 100644 index 075e4419..00000000 --- a/src-ui/app/snackbar_controller/SnackbarController.module.scss +++ /dev/null @@ -1,19 +0,0 @@ -.snackbar_content { - width: 100%; - height: 100%; - padding: 2rem; - color: #fff; - &.is_success { - background-color: var(--success_bc_color); - } - &.is_warning { - background-color: var(--waring_bc_color); - } - &.is_error { - background-color: var(--error_bc_color); - } -} - -.snackbar_message { - font-size: 1.4rem; -} \ No newline at end of file diff --git a/src-ui/assets/error.svg b/src-ui/assets/error.svg new file mode 100644 index 00000000..4842a2a7 --- /dev/null +++ b/src-ui/assets/error.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src-ui/logics/_useBackendErrorHandling.js b/src-ui/logics/_useBackendErrorHandling.js index d5987a1b..3af72764 100644 --- a/src-ui/logics/_useBackendErrorHandling.js +++ b/src-ui/logics/_useBackendErrorHandling.js @@ -1,41 +1,50 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { useNotificationStatus, } from "@logics_common"; import { - useMicRecordTimeout, - useMicPhraseTimeout, - useMicMaxWords, + useMainFunction, +} from "@logics_main"; - useSpeakerRecordTimeout, - useSpeakerPhraseTimeout, - useSpeakerMaxWords, +import { + useTranscription, - useDeepLAuthKey, + useTranslation, - useOscIpAddress, - useWebsocket, + useOthers, + + useAdvancedSettings, } from "@logics_configs"; import { ui_configs } from "../ui_configs"; export const _useBackendErrorHandling = () => { - const { t } = useTranslation(); + const { t } = useI18n(); const { showNotification_Error } = useNotificationStatus(); - const { updateMicRecordTimeout } = useMicRecordTimeout(); - const { updateMicPhraseTimeout } = useMicPhraseTimeout(); - const { updateMicMaxWords } = useMicMaxWords(); + const { + updateMicRecordTimeout, + updateMicPhraseTimeout, + updateMicMaxWords, - const { updateSpeakerRecordTimeout } = useSpeakerRecordTimeout(); - const { updateSpeakerPhraseTimeout } = useSpeakerPhraseTimeout(); - const { updateSpeakerMaxWords } = useSpeakerMaxWords(); + updateSpeakerRecordTimeout, + updateSpeakerPhraseTimeout, + updateSpeakerMaxWords, + } = useTranscription(); - const { updateDeepLAuthKey } = useDeepLAuthKey(); + const { updateTranslationStatus, updateTranscriptionSendStatus, updateTranscriptionReceiveStatus } = useMainFunction(); - const { updateOscIpAddress } = useOscIpAddress(); - const { updateEnableWebsocket, updateWebsocketHost, updateWebsocketPort } = useWebsocket(); + const { updateDeepLAuthKey } = useTranslation(); + + const { updateEnableVrcMicMuteSync } = useOthers(); + + const { + updateOscIpAddress, + updateEnableWebsocket, + updateWebsocketHost, + updateWebsocketPort, + } = useAdvancedSettings(); const errorHandling_Backend = ({message, data, endpoint, result}) => { switch (endpoint) { @@ -70,16 +79,53 @@ export const _useBackendErrorHandling = () => { if (message === "Translation engine limit error") showNotification_Error(t("common_error.translation_limit")); return; + case "/run/enable_translation": + if (message === "Translation disabled due to VRAM overflow") { + updateTranslationStatus(data); + showNotification_Error("Translation disabled due to VRAM overflow"); + } + return; + + case "/run/enable_transcription_send": + if (message === "Transcription send disabled due to VRAM overflow") { + updateTranscriptionSendStatus(data); + showNotification_Error("Transcription send disabled due to VRAM overflow"); + } + return; + + case "/run/enable_transcription_send": + if (message === "Transcription receive disabled due to VRAM overflow") { + updateTranscriptionReceiveStatus(data); + showNotification_Error("Transcription receive disabled due to VRAM overflow"); + } + return; + + case "/run/error_translation_chat_vram_overflow": + if (message === "VRAM out of memory during translation of chat") showNotification_Error("VRAM out of memory during translation of chat"); + return; + case "/run/error_translation_mic_vram_overflow": + if (message === "VRAM out of memory during translation of mic") showNotification_Error("VRAM out of memory during translation of mic"); + return; + case "/run/error_translation_speaker_vram_overflow": + if (message === "VRAM out of memory during translation of speaker") showNotification_Error("VRAM out of memory during translation of speaker"); + return; + case "/run/error_transcription_mic_vram_overflow": + if (message === "VRAM out of memory during mic transcription") showNotification_Error("VRAM out of memory during mic transcription"); + return; + case "/run/error_transcription_speaker_vram_overflow": + if (message === "VRAM out of memory during speaker transcription") showNotification_Error("VRAM out of memory during speaker transcription"); + return; + case "/set/data/deepl_auth_key": if (message === "DeepL auth key length is not correct") { updateDeepLAuthKey(data); - showNotification_Error(t("common_error.deepl_auth_key_invalid_length")); + showNotification_Error(t("common_error.deepl_auth_key_invalid_length"), { category_id: "deepl_auth_key" }); } else if (message === "Authentication failure of deepL auth key") { updateDeepLAuthKey(data); - showNotification_Error(t("common_error.deepl_auth_key_failed_authentication")); + showNotification_Error(t("common_error.deepl_auth_key_failed_authentication"), { category_id: "deepl_auth_key" }); } else { // Exception updateDeepLAuthKey(data); - showNotification_Error(message); + showNotification_Error(message, { category_id: "deepl_auth_key" }); } return; @@ -130,6 +176,14 @@ export const _useBackendErrorHandling = () => { } return; + case "/set/enable/vrc_mic_mute_sync": + // Normally, this path shouldn't happen because VRC Mic Mute Sync is disabled and can't be turned on from the UI. + if (message === "Cannot enable VRC mic mute sync while OSC query is disabled") { + updateEnableVrcMicMuteSync(data); + showNotification_Error("Cannot enable VRC Mic Mute Sync while OSC query is disabled"); + } + return; + // Advanced Settings, error messages are set by Backend (EN only) case "/set/data/osc_ip_address": diff --git a/src-ui/logics/common/useHandleOscQuery.js b/src-ui/logics/common/useHandleOscQuery.js index 2e6b1681..f952aaac 100644 --- a/src-ui/logics/common/useHandleOscQuery.js +++ b/src-ui/logics/common/useHandleOscQuery.js @@ -1,44 +1,47 @@ -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { useNotificationStatus } from "@logics_common"; -import { - useEnableVrcMicMuteSync, -} from "@logics_configs"; +import { useOthers } from "@logics_configs"; export const useHandleOscQuery = () => { - const { t } = useTranslation(); - + const { t } = useI18n(); const { showNotification_Warning } = useNotificationStatus(); - const { updateEnableVrcMicMuteSync } = useEnableVrcMicMuteSync(); + const { updateEnableVrcMicMuteSync } = useOthers(); - const handleOscQuery = ({is_osc_query_enabled, disabled_functions}) => { - if (!is_osc_query_enabled && disabled_functions.length > 0) { - const BASE_LABEL = t("common_warning.unable_to_use_osc_query"); - let items_label = ""; + const handleOscQuery = (payload) => { + const is_osc_query_enabled = payload.data; + const disabled_functions = payload.disabled_functions; - for (const disabled_function of disabled_functions) { - if (disabled_function === "vrc_mic_mute_sync") { - updateEnableVrcMicMuteSync({ - is_enabled: false, - is_available: false, - }); - const item = `- ${t("config_page.others.vrc_mic_mute_sync.label")}`; - items_label = `${items_label}\n${item}`; - } - } - const label = `${BASE_LABEL}${items_label}`; - showNotification_Warning( - label, - { hide_duration: 10000, } - ); - } else if (is_osc_query_enabled) { - updateEnableVrcMicMuteSync((old_value) => ({ - ...old_value.data, + if (is_osc_query_enabled) { + updateEnableVrcMicMuteSync(prev => ({ + ...prev.data, is_available: true, })); + return; + } + + if (!disabled_functions.length) { + updateEnableVrcMicMuteSync(prev => ({ + ...prev.data, + is_available: false, + })); + return; + } + + const items_label = disabled_functions + .filter(fn => fn === "vrc_mic_mute_sync") + .map(() => `- ${t("config_page.others.vrc_mic_mute_sync.label")}`) + .join("\n"); + + updateEnableVrcMicMuteSync({ + is_enabled: false, + is_available: false, + }); + + if (items_label) { + const message = `${t("common_warning.unable_to_use_osc_query")}\n${items_label}`; + showNotification_Warning(message, { hide_duration: 10000 }); } }; - return { - handleOscQuery, - }; + return { handleOscQuery }; }; \ No newline at end of file diff --git a/src-ui/logics/common/useIsVrctAvailable.js b/src-ui/logics/common/useIsVrctAvailable.js index dae8911e..569a0210 100644 --- a/src-ui/logics/common/useIsVrctAvailable.js +++ b/src-ui/logics/common/useIsVrctAvailable.js @@ -1,10 +1,21 @@ import { useStore_IsVrctAvailable } from "@store"; +import { useNotificationStatus } from "@logics_common"; export const useIsVrctAvailable = () => { const { currentIsVrctAvailable, updateIsVrctAvailable } = useStore_IsVrctAvailable(); + const { showNotification_Success, showNotification_Error } = useNotificationStatus(); + + const handleAiModelsAvailability = (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 }); + } + }; return { currentIsVrctAvailable, updateIsVrctAvailable, + + handleAiModelsAvailability, }; }; \ No newline at end of file diff --git a/src-ui/logics/common/useMessage.js b/src-ui/logics/common/useMessage.js index 416555a6..78986b55 100644 --- a/src-ui/logics/common/useMessage.js +++ b/src-ui/logics/common/useMessage.js @@ -3,7 +3,7 @@ import { useStore_MessageInputValue, } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; export const useMessage = () => { const { currentMessageLogs, addMessageLogs, updateMessageLogs } = useStore_MessageLogs(); @@ -42,6 +42,9 @@ export const useMessage = () => { messages: {message: message}, }); }; + const addSystemMessageLog_FromBackend = (payload) => { + addSystemMessageLog(payload.message); + }; const updateSentMessageLogById = (payload) => { updateMessageLogs(updateItemById(payload.id, payload.translation)); @@ -66,6 +69,7 @@ export const useMessage = () => { currentMessageLogs, sendMessage, addSystemMessageLog, + addSystemMessageLog_FromBackend, updateSentMessageLogById, addSentMessageLog, addReceivedMessageLog, diff --git a/src-ui/logics/common/useNotificationStatus.js b/src-ui/logics/common/useNotificationStatus.js index f4aab3ed..9667aaba 100644 --- a/src-ui/logics/common/useNotificationStatus.js +++ b/src-ui/logics/common/useNotificationStatus.js @@ -1,15 +1,15 @@ import { useStore_NotificationStatus } from "@store"; +import { useI18n } from "@useI18n"; export const useNotificationStatus = () => { const { currentNotificationStatus, updateNotificationStatus } = useStore_NotificationStatus(); - - const generateRandomKey = () => Math.random(); + const { t } = useI18n(); const showNotification_Warning = (message, options = {}) => { updateNotificationStatus({ status: "warning", is_open: true, - key: generateRandomKey(), + category_id: (options.category_id) ? options.category_id : null, message: message, options: options, }); @@ -19,7 +19,7 @@ export const useNotificationStatus = () => { updateNotificationStatus({ status: "error", is_open: true, - key: generateRandomKey(), + category_id: (options.category_id) ? options.category_id : null, message: message, options: options, }); @@ -29,14 +29,24 @@ export const useNotificationStatus = () => { updateNotificationStatus({ status: "success", is_open: true, - key: generateRandomKey(), + category_id: (options.category_id) ? options.category_id : null, message: message, options: options, }); }; - const closeNotification = (event, reason) => { - if (reason === "clickaway") return; + const showNotification_SaveSuccess = (options = {}) => { + options = { hide_duration: 1000, to_hide_progress_bar: true, ...options }; + updateNotificationStatus({ + status: "success", + is_open: true, + category_id: "save_success", + message: t("config_page.notifications.save_success"), + options: options, + }); + }; + + const closeNotification = () => { updateNotificationStatus((prev) => ({ ...prev.data, is_open: false, @@ -50,6 +60,7 @@ export const useNotificationStatus = () => { showNotification_Warning, showNotification_Error, showNotification_Success, + showNotification_SaveSuccess, closeNotification, }; }; \ No newline at end of file diff --git a/src-ui/logics/common/useOpenFolder.js b/src-ui/logics/common/useOpenFolder.js index 202ef5ad..6ecfd6bd 100644 --- a/src-ui/logics/common/useOpenFolder.js +++ b/src-ui/logics/common/useOpenFolder.js @@ -1,17 +1,27 @@ -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; export const useOpenFolder = () => { const { asyncStdoutToPython } = useStdoutToPython(); + const openFolder_MessageLogs = () => { asyncStdoutToPython("/run/open_filepath_logs"); }; + const openedFolder_MessageLogs = () => { + console.log("Opened Directory, Message Logs"); + }; const openFolder_ConfigFile = () => { asyncStdoutToPython("/run/open_filepath_config_file"); }; + const openedFolder_ConfigFile = () => { + console.log("Opened Directory, Config File"); + }; return { openFolder_MessageLogs, openFolder_ConfigFile, + + openedFolder_MessageLogs, + openedFolder_ConfigFile, }; }; \ No newline at end of file diff --git a/src-ui/logics/common/useSoftwareVersion.js b/src-ui/logics/common/useSoftwareVersion.js index 18f24a7f..ea6e99ad 100644 --- a/src-ui/logics/common/useSoftwareVersion.js +++ b/src-ui/logics/common/useSoftwareVersion.js @@ -1,7 +1,7 @@ import semver from "semver"; import { useStore_SoftwareVersion, useStore_LatestSoftwareVersionInfo } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; export const useSoftwareVersion = () => { const { asyncStdoutToPython } = useStdoutToPython(); @@ -13,6 +13,13 @@ export const useSoftwareVersion = () => { asyncStdoutToPython("/get/data/version"); }; + const updateSoftwareVersionInfo = (payload) => { + updateLatestSoftwareVersionInfo(prev => ({ + is_update_available: payload.is_update_available, + new_version: payload.new_version || prev.data.new_version, + })); + }; + const isPluginCompatible = (main_version, lower_version, upper_version) => { // lower_version 以上かつ upper_version 以下なら互換性ありと判定 return semver.gte(main_version, lower_version) && semver.lte(main_version, upper_version); @@ -32,6 +39,7 @@ export const useSoftwareVersion = () => { getSoftwareVersion, updateSoftwareVersion, + updateSoftwareVersionInfo, currentLatestSoftwareVersionInfo, updateLatestSoftwareVersionInfo, diff --git a/src-ui/logics/common/useUpdateSoftware.js b/src-ui/logics/common/useUpdateSoftware.js index f3d2f1cf..208cbf30 100644 --- a/src-ui/logics/common/useUpdateSoftware.js +++ b/src-ui/logics/common/useUpdateSoftware.js @@ -1,4 +1,4 @@ -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; export const useUpdateSoftware = () => { const { asyncStdoutToPython } = useStdoutToPython(); diff --git a/src-ui/logics/common/useVolume.js b/src-ui/logics/common/useVolume.js index b3e2165b..ce94a391 100644 --- a/src-ui/logics/common/useVolume.js +++ b/src-ui/logics/common/useVolume.js @@ -5,7 +5,7 @@ import { useStore_SpeakerThresholdCheckStatus, } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; export const useVolume = () => { const { asyncStdoutToPython } = useStdoutToPython(); diff --git a/src-ui/logics/common/useWindow.js b/src-ui/logics/common/useWindow.js index 88182dd6..3e7f4059 100644 --- a/src-ui/logics/common/useWindow.js +++ b/src-ui/logics/common/useWindow.js @@ -1,13 +1,13 @@ import { useEffect, useRef } from "react"; import { currentMonitor, availableMonitors, PhysicalPosition, PhysicalSize } from "@tauri-apps/api/window"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; import { useStore_IsBreakPoint } from "@store"; -import { useUiScaling } from "@logics_configs"; +import { useAppearance } from "@logics_configs"; import { store } from "@store"; export const useWindow = () => { const { asyncStdoutToPython } = useStdoutToPython(); - const { currentUiScaling } = useUiScaling(); + const { currentUiScaling } = useAppearance(); const { updateIsBreakPoint } = useStore_IsBreakPoint(); const appWindow = store.appWindow; diff --git a/src-ui/logics/configs/advanced_settings/useAdvancedSettings.js b/src-ui/logics/configs/advanced_settings/useAdvancedSettings.js new file mode 100644 index 00000000..7bf5652e --- /dev/null +++ b/src-ui/logics/configs/advanced_settings/useAdvancedSettings.js @@ -0,0 +1,150 @@ +import { + useStore_OscIpAddress, + useStore_OscPort, + useStore_EnableWebsocket, + useStore_WebsocketHost, + useStore_WebsocketPort, +} from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { useNotificationStatus } from "@logics_common"; + +export const useAdvancedSettings = () => { + const { asyncStdoutToPython } = useStdoutToPython(); + const { showNotification_Error, showNotification_SaveSuccess } = useNotificationStatus(); + + // OSC IP Address + const { currentOscIpAddress, updateOscIpAddress, pendingOscIpAddress } = useStore_OscIpAddress(); + // OSC Port + const { currentOscPort, updateOscPort, pendingOscPort } = useStore_OscPort(); + // WebSocket + const { currentEnableWebsocket, updateEnableWebsocket, pendingEnableWebsocket } = useStore_EnableWebsocket(); + const { currentWebsocketHost, updateWebsocketHost, pendingWebsocketHost } = useStore_WebsocketHost(); + const { currentWebsocketPort, updateWebsocketPort, pendingWebsocketPort } = useStore_WebsocketPort(); + + // OSC IP Address + const getOscIpAddress = () => { + pendingOscIpAddress(); + asyncStdoutToPython("/get/data/osc_ip_address"); + }; + + const setOscIpAddress = (osc_ip_address) => { + pendingOscIpAddress(); + asyncStdoutToPython("/set/data/osc_ip_address", osc_ip_address); + }; + + const setSuccessOscIpAddress = (osc_ip_address) => { + updateOscIpAddress(osc_ip_address); + showNotification_SaveSuccess(); + }; + + // OSC Port + const getOscPort = () => { + pendingOscPort(); + asyncStdoutToPython("/get/data/osc_port"); + }; + + const setOscPort = (osc_port) => { + pendingOscPort(); + asyncStdoutToPython("/set/data/osc_port", osc_port); + }; + + const setSuccessOscPort = (osc_port) => { + updateOscPort(osc_port); + showNotification_SaveSuccess(); + }; + + const saveErrorOscPort = ({ data, message, _result }) => { + updateOscPort(d => d.data); + showNotification_Error(_result); + }; + + // WebSocket Enable + const getEnableWebsocket = () => { + pendingEnableWebsocket(); + asyncStdoutToPython("/get/data/websocket_server"); + }; + + const toggleEnableWebsocket = () => { + pendingEnableWebsocket(); + if (currentEnableWebsocket.data) { + asyncStdoutToPython("/set/disable/websocket_server"); + } else { + asyncStdoutToPython("/set/enable/websocket_server"); + } + }; + + const setSuccessEnableWebsocket = (is_enabled) => { + updateEnableWebsocket(is_enabled); + showNotification_SaveSuccess(); + }; + + // WebSocket Host + const getWebsocketHost = () => { + pendingWebsocketHost(); + asyncStdoutToPython("/get/data/websocket_host"); + }; + + const setWebsocketHost = (websocket_host) => { + pendingWebsocketHost(); + asyncStdoutToPython("/set/data/websocket_host", websocket_host); + }; + + const setSuccessWebsocketHost = (websocket_host) => { + updateWebsocketHost(websocket_host); + showNotification_SaveSuccess(); + }; + + // WebSocket Port + const getWebsocketPort = () => { + pendingWebsocketPort(); + asyncStdoutToPython("/get/data/websocket_port"); + }; + + const setWebsocketPort = (websocket_port) => { + pendingWebsocketPort(); + asyncStdoutToPython("/set/data/websocket_port", websocket_port); + }; + + const setSuccessWebsocketPort = (websocket_port) => { + updateWebsocketPort(websocket_port); + showNotification_SaveSuccess(); + }; + + return { + // OSC IP Address + currentOscIpAddress, + getOscIpAddress, + updateOscIpAddress, + setOscIpAddress, + setSuccessOscIpAddress, + + // OSC Port + currentOscPort, + getOscPort, + updateOscPort, + setOscPort, + setSuccessOscPort, + saveErrorOscPort, + + // WebSocket Enable + currentEnableWebsocket, + getEnableWebsocket, + updateEnableWebsocket, + toggleEnableWebsocket, + setSuccessEnableWebsocket, + + // WebSocket Host + currentWebsocketHost, + getWebsocketHost, + updateWebsocketHost, + setWebsocketHost, + setSuccessWebsocketHost, + + // WebSocket Port + currentWebsocketPort, + getWebsocketPort, + updateWebsocketPort, + setWebsocketPort, + setSuccessWebsocketPort, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/configs/advanced_settings/useOscIpAddress.js b/src-ui/logics/configs/advanced_settings/useOscIpAddress.js deleted file mode 100644 index 702a6d98..00000000 --- a/src-ui/logics/configs/advanced_settings/useOscIpAddress.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_OscIpAddress } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useOscIpAddress = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentOscIpAddress, updateOscIpAddress, pendingOscIpAddress } = useStore_OscIpAddress(); - - const getOscIpAddress = () => { - pendingOscIpAddress(); - asyncStdoutToPython("/get/data/osc_ip_address"); - }; - - const setOscIpAddress = (osc_ip_address) => { - pendingOscIpAddress(); - asyncStdoutToPython("/set/data/osc_ip_address", osc_ip_address); - }; - - return { - currentOscIpAddress, - getOscIpAddress, - updateOscIpAddress, - setOscIpAddress, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/advanced_settings/useOscPort.js b/src-ui/logics/configs/advanced_settings/useOscPort.js deleted file mode 100644 index d3e28557..00000000 --- a/src-ui/logics/configs/advanced_settings/useOscPort.js +++ /dev/null @@ -1,33 +0,0 @@ -import { useStore_OscPort } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; -import { useNotificationStatus } from "@logics_common"; - -export const useOscPort = () => { - const { showNotification_Error } = useNotificationStatus(); - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentOscPort, updateOscPort, pendingOscPort } = useStore_OscPort(); - - const getOscPort = () => { - pendingOscPort(); - asyncStdoutToPython("/get/data/osc_port"); - }; - - const setOscPort = (osc_port) => { - pendingOscPort(); - asyncStdoutToPython("/set/data/osc_port", osc_port); - }; - - const saveErrorOscPort = ({data, message, _result}) => { - updateOscPort(d => d.data); - showNotification_Error(_result); - }; - - return { - currentOscPort, - getOscPort, - updateOscPort, - setOscPort, - - saveErrorOscPort, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/advanced_settings/useWebsocket.js b/src-ui/logics/configs/advanced_settings/useWebsocket.js deleted file mode 100644 index 51361489..00000000 --- a/src-ui/logics/configs/advanced_settings/useWebsocket.js +++ /dev/null @@ -1,67 +0,0 @@ -import { - useStore_EnableWebsocket, - useStore_WebsocketHost, - useStore_WebsocketPort, -} from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useWebsocket = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableWebsocket, updateEnableWebsocket, pendingEnableWebsocket } = useStore_EnableWebsocket(); - const { currentWebsocketHost, updateWebsocketHost, pendingWebsocketHost } = useStore_WebsocketHost(); - const { currentWebsocketPort, updateWebsocketPort, pendingWebsocketPort } = useStore_WebsocketPort(); - - const getEnableWebsocket = () => { - pendingEnableWebsocket(); - asyncStdoutToPython("/get/data/websocket_server"); - }; - - const toggleEnableWebsocket = () => { - pendingEnableWebsocket(); - if (currentEnableWebsocket.data) { - asyncStdoutToPython("/set/disable/websocket_server"); - } else { - asyncStdoutToPython("/set/enable/websocket_server"); - } - }; - - - const getWebsocketHost = () => { - pendingWebsocketHost(); - asyncStdoutToPython("/get/data/websocket_host"); - }; - - const setWebsocketHost = (websocket_host) => { - pendingWebsocketHost(); - asyncStdoutToPython("/set/data/websocket_host", websocket_host); - }; - - - const getWebsocketPort = () => { - pendingWebsocketPort(); - asyncStdoutToPython("/get/data/websocket_port"); - }; - - const setWebsocketPort = (websocket_port) => { - pendingWebsocketPort(); - asyncStdoutToPython("/set/data/websocket_port", websocket_port); - }; - - return { - currentEnableWebsocket, - updateEnableWebsocket, - getEnableWebsocket, - toggleEnableWebsocket, - - currentWebsocketHost, - updateWebsocketHost, - getWebsocketHost, - setWebsocketHost, - - currentWebsocketPort, - updateWebsocketPort, - getWebsocketPort, - setWebsocketPort, - - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useAppearance.js b/src-ui/logics/configs/appearance/useAppearance.js new file mode 100644 index 00000000..dbf5c310 --- /dev/null +++ b/src-ui/logics/configs/appearance/useAppearance.js @@ -0,0 +1,201 @@ +import { + useStore_UiLanguage, + useStore_UiScaling, + useStore_MessageLogUiScaling, + useStore_SendMessageButtonType, + useStore_ShowResendButton, + useStore_SelectedFontFamily, + useStore_Transparency, +} from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { useI18n } from "@useI18n"; +import { useNotificationStatus } from "@logics_common"; + +export const useAppearance = () => { + const { t } = useI18n(); + const { asyncStdoutToPython } = useStdoutToPython(); + const { showNotification_SaveSuccess } = useNotificationStatus(); + + // UI Language + const { currentUiLanguage, updateUiLanguage, pendingUiLanguage } = useStore_UiLanguage(); + // UI Scaling + const { currentUiScaling, updateUiScaling, pendingUiScaling } = useStore_UiScaling(); + // Message Log Ui Scaling + const { currentMessageLogUiScaling, updateMessageLogUiScaling, pendingMessageLogUiScaling } = useStore_MessageLogUiScaling(); + // Send Message Button Type + const { currentSendMessageButtonType, updateSendMessageButtonType, pendingSendMessageButtonType } = useStore_SendMessageButtonType(); + // Show Resend Button + const { currentShowResendButton, updateShowResendButton, pendingShowResendButton } = useStore_ShowResendButton(); + // Selected Font Family + const { currentSelectedFontFamily, updateSelectedFontFamily, pendingSelectedFontFamily } = useStore_SelectedFontFamily(); + // Transparency + const { currentTransparency, updateTransparency, pendingTransparency } = useStore_Transparency(); + + + // UI Language + const getUiLanguage = () => { + pendingUiLanguage(); + asyncStdoutToPython("/get/data/ui_language"); + }; + + const setUiLanguage = (selected_ui_language) => { + pendingUiLanguage(); + asyncStdoutToPython("/set/data/ui_language", selected_ui_language); + }; + + const setSuccessUiLanguage = (selected_ui_language) => { + updateUiLanguage(selected_ui_language); + showNotification_SaveSuccess(); + }; + + // UI Scaling + const getUiScaling = () => { + pendingUiScaling(); + asyncStdoutToPython("/get/data/ui_scaling"); + }; + + const setUiScaling = (selected_ui_scaling) => { + pendingUiScaling(); + asyncStdoutToPython("/set/data/ui_scaling", selected_ui_scaling); + }; + + const setSuccessUiScaling = (selected_ui_scaling) => { + updateUiScaling(selected_ui_scaling); + showNotification_SaveSuccess(); + }; + + // Message Log Ui Scaling + const getMessageLogUiScaling = () => { + pendingMessageLogUiScaling(); + asyncStdoutToPython("/get/data/textbox_ui_scaling"); + }; + + const setMessageLogUiScaling = (selected_ui_scaling) => { + pendingMessageLogUiScaling(); + asyncStdoutToPython("/set/data/textbox_ui_scaling", selected_ui_scaling); + }; + + const setSuccessMessageLogUiScaling = (selected_ui_scaling) => { + updateMessageLogUiScaling(selected_ui_scaling); + showNotification_SaveSuccess(); + }; + + // Send Message Button Type + const getSendMessageButtonType = () => { + pendingSendMessageButtonType(); + asyncStdoutToPython("/get/data/send_message_button_type"); + }; + + const setSendMessageButtonType = (send_message_button_type) => { + pendingSendMessageButtonType(); + asyncStdoutToPython("/set/data/send_message_button_type", send_message_button_type); + }; + + const setSuccessSendMessageButtonType = (send_message_button_type) => { + updateSendMessageButtonType(send_message_button_type); + showNotification_SaveSuccess(); + }; + + // Show Resend Button + const getShowResendButton = () => { + pendingShowResendButton(); + asyncStdoutToPython("/get/data/show_resend_button"); + }; + + const toggleShowResendButton = () => { + pendingShowResendButton(); + if (currentShowResendButton.data) { + asyncStdoutToPython("/set/disable/show_resend_button"); + } else { + asyncStdoutToPython("/set/enable/show_resend_button"); + } + }; + const setSuccessShowResendButton = (to_show) => { + updateShowResendButton(to_show); + showNotification_SaveSuccess(); + }; + + // Selected Font Family + const getSelectedFontFamily = () => { + pendingSelectedFontFamily(); + asyncStdoutToPython("/get/data/font_family"); + }; + + const setSelectedFontFamily = (selected_font_family) => { + pendingSelectedFontFamily(); + asyncStdoutToPython("/set/data/font_family", selected_font_family); + }; + + const setSuccessSelectedFontFamily = (selected_font_family) => { + updateSelectedFontFamily(selected_font_family); + showNotification_SaveSuccess(); + }; + + // Transparency + const getTransparency = () => { + pendingTransparency(); + asyncStdoutToPython("/get/data/transparency"); + }; + + const setTransparency = (selected_transparency) => { + pendingTransparency(); + asyncStdoutToPython("/set/data/transparency", selected_transparency); + }; + + const setSuccessTransparency = (selected_transparency) => { + updateTransparency(selected_transparency); + showNotification_SaveSuccess(); + }; + + + return { + // UI Language + currentUiLanguage, + getUiLanguage, + updateUiLanguage, + setUiLanguage, + setSuccessUiLanguage, + + // UI Scaling + currentUiScaling, + getUiScaling, + updateUiScaling, + setUiScaling, + setSuccessUiScaling, + + // Message Log Ui Scaling + currentMessageLogUiScaling, + getMessageLogUiScaling, + updateMessageLogUiScaling, + setMessageLogUiScaling, + setSuccessMessageLogUiScaling, + + // Send Message Button Type + currentSendMessageButtonType, + getSendMessageButtonType, + setSendMessageButtonType, + setSuccessSendMessageButtonType, + updateSendMessageButtonType, + + // Show Resend Button + currentShowResendButton, + getShowResendButton, + updateShowResendButton, + toggleShowResendButton, + setSuccessShowResendButton, + + // Selected Font Family + currentSelectedFontFamily, + getSelectedFontFamily, + updateSelectedFontFamily, + setSelectedFontFamily, + setSuccessSelectedFontFamily, + + // Transparency + currentTransparency, + getTransparency, + updateTransparency, + setTransparency, + setSuccessTransparency, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useMessageLogUiScaling.js b/src-ui/logics/configs/appearance/useMessageLogUiScaling.js deleted file mode 100644 index 625f6263..00000000 --- a/src-ui/logics/configs/appearance/useMessageLogUiScaling.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_MessageLogUiScaling } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMessageLogUiScaling = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentMessageLogUiScaling, updateMessageLogUiScaling, pendingMessageLogUiScaling } = useStore_MessageLogUiScaling(); - - const getMessageLogUiScaling = () => { - pendingMessageLogUiScaling(); - asyncStdoutToPython("/get/data/textbox_ui_scaling"); - }; - - const setMessageLogUiScaling = (selected_ui_scaling) => { - pendingMessageLogUiScaling(); - asyncStdoutToPython("/set/data/textbox_ui_scaling", selected_ui_scaling); - }; - - return { - currentMessageLogUiScaling, - getMessageLogUiScaling, - updateMessageLogUiScaling, - setMessageLogUiScaling, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useRestoreWindowGeometry.js b/src-ui/logics/configs/appearance/useRestoreWindowGeometry.js deleted file mode 100644 index 2cc618be..00000000 --- a/src-ui/logics/configs/appearance/useRestoreWindowGeometry.js +++ /dev/null @@ -1,28 +0,0 @@ -// import { useStore_RestoreWindowGeometry } from "@store"; -// import { useStdoutToPython } from "@logics/useStdoutToPython"; - -// export const useRestoreWindowGeometry = () => { -// const { asyncStdoutToPython } = useStdoutToPython(); -// const { currentRestoreWindowGeometry, updateRestoreWindowGeometry, pendingRestoreWindowGeometry } = useStore_RestoreWindowGeometry(); - -// const getRestoreWindowGeometry = () => { -// pendingRestoreWindowGeometry(); -// asyncStdoutToPython("/get/data/restore_main_window_geometry"); -// }; - -// const toggleRestoreWindowGeometry = () => { -// pendingRestoreWindowGeometry(); -// if (currentRestoreWindowGeometry.data) { -// asyncStdoutToPython("/set/disable/restore_main_window_geometry"); -// } else { -// asyncStdoutToPython("/set/enable/restore_main_window_geometry"); -// } -// }; - -// return { -// currentRestoreWindowGeometry, -// getRestoreWindowGeometry, -// toggleRestoreWindowGeometry, -// updateRestoreWindowGeometry, -// }; -// }; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useSelectedFontFamily.js b/src-ui/logics/configs/appearance/useSelectedFontFamily.js deleted file mode 100644 index bfb43029..00000000 --- a/src-ui/logics/configs/appearance/useSelectedFontFamily.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedFontFamily } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedFontFamily = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedFontFamily, updateSelectedFontFamily, pendingSelectedFontFamily } = useStore_SelectedFontFamily(); - - const getSelectedFontFamily = () => { - pendingSelectedFontFamily(); - asyncStdoutToPython("/get/data/font_family"); - }; - - const setSelectedFontFamily = (selected_font_family) => { - pendingSelectedFontFamily(); - asyncStdoutToPython("/set/data/font_family", selected_font_family); - }; - - return { - currentSelectedFontFamily, - getSelectedFontFamily, - updateSelectedFontFamily, - setSelectedFontFamily, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useSendMessageButtonType.js b/src-ui/logics/configs/appearance/useSendMessageButtonType.js deleted file mode 100644 index f69a51f2..00000000 --- a/src-ui/logics/configs/appearance/useSendMessageButtonType.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SendMessageButtonType } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSendMessageButtonType = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSendMessageButtonType, updateSendMessageButtonType, pendingSendMessageButtonType } = useStore_SendMessageButtonType(); - - const getSendMessageButtonType = () => { - pendingSendMessageButtonType(); - asyncStdoutToPython("/get/data/send_message_button_type"); - }; - - const setSendMessageButtonType = (selected_type) => { - pendingSendMessageButtonType(); - asyncStdoutToPython("/set/data/send_message_button_type", selected_type); - }; - - return { - currentSendMessageButtonType, - getSendMessageButtonType, - setSendMessageButtonType, - updateSendMessageButtonType, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useTransparency.js b/src-ui/logics/configs/appearance/useTransparency.js deleted file mode 100644 index 9ab7429f..00000000 --- a/src-ui/logics/configs/appearance/useTransparency.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_Transparency } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useTransparency = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentTransparency, updateTransparency, pendingTransparency } = useStore_Transparency(); - - const getTransparency = () => { - pendingTransparency(); - asyncStdoutToPython("/get/data/transparency"); - }; - - const setTransparency = (selected_transparency) => { - pendingTransparency(); - asyncStdoutToPython("/set/data/transparency", selected_transparency); - }; - - return { - currentTransparency, - getTransparency, - updateTransparency, - setTransparency, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useUiLanguage.js b/src-ui/logics/configs/appearance/useUiLanguage.js deleted file mode 100644 index 149a8fb3..00000000 --- a/src-ui/logics/configs/appearance/useUiLanguage.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_UiLanguage } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useUiLanguage = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentUiLanguage, updateUiLanguage, pendingUiLanguage } = useStore_UiLanguage(); - - const getUiLanguage = () => { - pendingUiLanguage(); - asyncStdoutToPython("/get/data/ui_language"); - }; - - const setUiLanguage = (selected_ui_language) => { - pendingUiLanguage(); - asyncStdoutToPython("/set/data/ui_language", selected_ui_language); - }; - - return { - currentUiLanguage, - getUiLanguage, - updateUiLanguage, - setUiLanguage, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/appearance/useUiScaling.js b/src-ui/logics/configs/appearance/useUiScaling.js deleted file mode 100644 index 501118f1..00000000 --- a/src-ui/logics/configs/appearance/useUiScaling.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_UiScaling } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useUiScaling = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentUiScaling, updateUiScaling, pendingUiScaling } = useStore_UiScaling(); - - const getUiScaling = () => { - pendingUiScaling(); - asyncStdoutToPython("/get/data/ui_scaling"); - }; - - const setUiScaling = (selected_ui_scaling) => { - pendingUiScaling(); - asyncStdoutToPython("/set/data/ui_scaling", selected_ui_scaling); - }; - - return { - currentUiScaling, - getUiScaling, - updateUiScaling, - setUiScaling, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useDevice.js b/src-ui/logics/configs/device/useDevice.js new file mode 100644 index 00000000..b0919ad1 --- /dev/null +++ b/src-ui/logics/configs/device/useDevice.js @@ -0,0 +1,306 @@ +import { + useStore_EnableAutoMicSelect, + useStore_EnableAutoSpeakerSelect, + + useStore_MicDeviceList, + useStore_MicHostList, + useStore_SpeakerDeviceList, + + useStore_SelectedMicHost, + useStore_SelectedMicDevice, + + useStore_SelectedSpeakerDevice, + + useStore_MicThreshold, + useStore_EnableAutomaticMicThreshold, + useStore_SpeakerThreshold, + useStore_EnableAutomaticSpeakerThreshold, +} from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { arrayToObject } from "@utils"; +import { useNotificationStatus } from "@logics_common"; + +export const useDevice = () => { + const { asyncStdoutToPython } = useStdoutToPython(); + const { showNotification_SaveSuccess } = useNotificationStatus(); + + const { currentEnableAutoMicSelect, updateEnableAutoMicSelect, pendingEnableAutoMicSelect } = useStore_EnableAutoMicSelect(); + const { currentEnableAutoSpeakerSelect, updateEnableAutoSpeakerSelect, pendingEnableAutoSpeakerSelect } = useStore_EnableAutoSpeakerSelect(); + + const { currentMicDeviceList, updateMicDeviceList, pendingMicDeviceList } = useStore_MicDeviceList(); + const { currentMicHostList, updateMicHostList, pendingMicHostList } = useStore_MicHostList(); + const { currentSpeakerDeviceList, updateSpeakerDeviceList, pendingSpeakerDeviceList } = useStore_SpeakerDeviceList(); + + const { currentSelectedMicHost, updateSelectedMicHost, pendingSelectedMicHost } = useStore_SelectedMicHost(); + const { currentSelectedMicDevice, updateSelectedMicDevice, pendingSelectedMicDevice } = useStore_SelectedMicDevice(); + + const { currentSelectedSpeakerDevice, updateSelectedSpeakerDevice, pendingSelectedSpeakerDevice } = useStore_SelectedSpeakerDevice(); + + const { currentMicThreshold, updateMicThreshold } = useStore_MicThreshold(); + const { currentEnableAutomaticMicThreshold, updateEnableAutomaticMicThreshold, pendingEnableAutomaticMicThreshold } = useStore_EnableAutomaticMicThreshold(); + + const { currentSpeakerThreshold, updateSpeakerThreshold } = useStore_SpeakerThreshold(); + const { currentEnableAutomaticSpeakerThreshold, updateEnableAutomaticSpeakerThreshold, pendingEnableAutomaticSpeakerThreshold } = useStore_EnableAutomaticSpeakerThreshold(); + + // Auto Select (Mic) + const getEnableAutoMicSelect = () => { + pendingEnableAutoMicSelect(); + asyncStdoutToPython("/get/data/auto_mic_select"); + }; + + const toggleEnableAutoMicSelect = () => { + pendingEnableAutoMicSelect(); + if (currentEnableAutoMicSelect.data) { + asyncStdoutToPython("/set/disable/auto_mic_select"); + } else { + asyncStdoutToPython("/set/enable/auto_mic_select"); + } + }; + + const setSuccessEnableAutoMicSelect = (enabled) => { + updateEnableAutoMicSelect(enabled); + showNotification_SaveSuccess(); + }; + + // Auto Select (Speaker) + const getEnableAutoSpeakerSelect = () => { + pendingEnableAutoSpeakerSelect(); + asyncStdoutToPython("/get/data/auto_speaker_select"); + }; + + const toggleEnableAutoSpeakerSelect = () => { + pendingEnableAutoSpeakerSelect(); + if (currentEnableAutoSpeakerSelect.data) { + asyncStdoutToPython("/set/disable/auto_speaker_select"); + } else { + asyncStdoutToPython("/set/enable/auto_speaker_select"); + } + }; + + const setSuccessEnableAutoSpeakerSelect = (enabled) => { + updateEnableAutoSpeakerSelect(enabled); + showNotification_SaveSuccess(); + }; + + // List (Mic device) + const getMicDeviceList = () => { + pendingMicDeviceList(); + asyncStdoutToPython("/get/data/mic_device_list"); + }; + + const updateMicDeviceList_FromBackend = (payload) => { + updateMicDeviceList(arrayToObject(payload)); + }; + + // List (Mic host) + const getMicHostList = () => { + pendingMicHostList(); + asyncStdoutToPython("/get/data/mic_host_list"); + }; + + const updateMicHostList_FromBackend = (payload) => { + updateMicHostList(arrayToObject(payload)); + }; + + // List (Speaker device) + const getSpeakerDeviceList = () => { + pendingSpeakerDeviceList(); + asyncStdoutToPython("/get/data/speaker_device_list"); + }; + + const updateSpeakerDeviceList_FromBackend = (payload) => { + updateSpeakerDeviceList(arrayToObject(payload)); + }; + + // Selected (Mic host) + const getSelectedMicHost = () => { + pendingSelectedMicHost(); + asyncStdoutToPython("/get/data/selected_mic_host"); + }; + + const setSelectedMicHost = (selected_mic_host) => { + pendingSelectedMicHost(); + asyncStdoutToPython("/set/data/selected_mic_host", selected_mic_host); + }; + + const setSuccessSelectedMicHost = (payload) => { + updateSelectedMicHostAndDevice(payload); // Receive host and device from backend. + showNotification_SaveSuccess(); + }; + + // Selected (Mic device) + const getSelectedMicDevice = () => { + pendingSelectedMicDevice(); + asyncStdoutToPython("/get/data/selected_mic_device"); + }; + + const setSelectedMicDevice = (selected_mic_device) => { + pendingSelectedMicDevice(); + asyncStdoutToPython("/set/data/selected_mic_device", selected_mic_device); + }; + + const setSuccessSelectedMicDevice = (selected_mic_device) => { + updateSelectedMicDevice(selected_mic_device); + showNotification_SaveSuccess(); + }; + + // Selected (Mic Device and Host) + const updateSelectedMicHostAndDevice = (payload) => { + updateSelectedMicHost(payload.host); + updateSelectedMicDevice(payload.device); + } + + // Selected (Speaker device) + const getSelectedSpeakerDevice = () => { + pendingSelectedSpeakerDevice(); + asyncStdoutToPython("/get/data/selected_speaker_device"); + }; + + const setSelectedSpeakerDevice = (selected_speaker_device) => { + pendingSelectedSpeakerDevice(); + asyncStdoutToPython("/set/data/selected_speaker_device", selected_speaker_device); + }; + + const setSuccessSelectedSpeakerDevice = (selected_speaker_device) => { + updateSelectedSpeakerDevice(selected_speaker_device); + showNotification_SaveSuccess(); + }; + + // Threshold (Mic) + const getMicThreshold = () => { + asyncStdoutToPython("/get/data/mic_threshold"); + }; + + const setMicThreshold = (mic_threshold) => { + asyncStdoutToPython("/set/data/mic_threshold", mic_threshold); + }; + + const setSuccessMicThreshold = (mic_threshold) => { + updateMicThreshold(mic_threshold); + showNotification_SaveSuccess(); + }; + + const getEnableAutomaticMicThreshold = () => { + pendingEnableAutomaticMicThreshold(); + asyncStdoutToPython("/get/data/mic_automatic_threshold"); + }; + + const toggleEnableAutomaticMicThreshold = () => { + pendingEnableAutomaticMicThreshold(); + if (currentEnableAutomaticMicThreshold.data) { + asyncStdoutToPython("/set/disable/mic_automatic_threshold"); + } else { + asyncStdoutToPython("/set/enable/mic_automatic_threshold"); + } + }; + + const setSuccessEnableAutomaticMicThreshold = (enabled) => { + updateEnableAutomaticMicThreshold(enabled); + showNotification_SaveSuccess(); + }; + + // Threshold (Speaker) + const getSpeakerThreshold = () => { + asyncStdoutToPython("/get/data/speaker_threshold"); + }; + + const setSpeakerThreshold = (speaker_threshold) => { + asyncStdoutToPython("/set/data/speaker_threshold", speaker_threshold); + }; + + const setSuccessSpeakerThreshold = (speaker_threshold) => { + updateSpeakerThreshold(speaker_threshold); + showNotification_SaveSuccess(); + }; + + const getEnableAutomaticSpeakerThreshold = () => { + pendingEnableAutomaticSpeakerThreshold(); + asyncStdoutToPython("/get/data/speaker_automatic_threshold"); + }; + + const toggleEnableAutomaticSpeakerThreshold = () => { + pendingEnableAutomaticSpeakerThreshold(); + if (currentEnableAutomaticSpeakerThreshold.data) { + asyncStdoutToPython("/set/disable/speaker_automatic_threshold"); + } else { + asyncStdoutToPython("/set/enable/speaker_automatic_threshold"); + } + }; + + const setSuccessEnableAutomaticSpeakerThreshold = (enabled) => { + updateEnableAutomaticSpeakerThreshold(enabled); + showNotification_SaveSuccess(); + }; + + return { + currentEnableAutoMicSelect, + getEnableAutoMicSelect, + updateEnableAutoMicSelect, + toggleEnableAutoMicSelect, + setSuccessEnableAutoMicSelect, + + currentEnableAutoSpeakerSelect, + getEnableAutoSpeakerSelect, + updateEnableAutoSpeakerSelect, + toggleEnableAutoSpeakerSelect, + setSuccessEnableAutoSpeakerSelect, + + currentMicDeviceList, + getMicDeviceList, + updateMicDeviceList, + updateMicDeviceList_FromBackend, + + currentMicHostList, + getMicHostList, + updateMicHostList, + updateMicHostList_FromBackend, + + currentSpeakerDeviceList, + getSpeakerDeviceList, + updateSpeakerDeviceList, + updateSpeakerDeviceList_FromBackend, + + currentSelectedMicHost, + getSelectedMicHost, + updateSelectedMicHost, + setSelectedMicHost, + setSuccessSelectedMicHost, + + currentSelectedMicDevice, + getSelectedMicDevice, + updateSelectedMicDevice, + setSelectedMicDevice, + setSuccessSelectedMicDevice, + updateSelectedMicHostAndDevice, + + currentSelectedSpeakerDevice, + getSelectedSpeakerDevice, + updateSelectedSpeakerDevice, + setSelectedSpeakerDevice, + setSuccessSelectedSpeakerDevice, + + currentMicThreshold, + getMicThreshold, + setMicThreshold, + updateMicThreshold, + setSuccessMicThreshold, + + currentEnableAutomaticMicThreshold, + getEnableAutomaticMicThreshold, + toggleEnableAutomaticMicThreshold, + updateEnableAutomaticMicThreshold, + setSuccessEnableAutomaticMicThreshold, + + currentSpeakerThreshold, + getSpeakerThreshold, + setSpeakerThreshold, + updateSpeakerThreshold, + setSuccessSpeakerThreshold, + + currentEnableAutomaticSpeakerThreshold, + getEnableAutomaticSpeakerThreshold, + toggleEnableAutomaticSpeakerThreshold, + updateEnableAutomaticSpeakerThreshold, + setSuccessEnableAutomaticSpeakerThreshold, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useEnableAutoMicSelect.js b/src-ui/logics/configs/device/useEnableAutoMicSelect.js deleted file mode 100644 index 1370d055..00000000 --- a/src-ui/logics/configs/device/useEnableAutoMicSelect.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableAutoMicSelect } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableAutoMicSelect = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableAutoMicSelect, updateEnableAutoMicSelect, pendingEnableAutoMicSelect } = useStore_EnableAutoMicSelect(); - - const getEnableAutoMicSelect = () => { - pendingEnableAutoMicSelect(); - asyncStdoutToPython("/get/data/auto_mic_select"); - }; - - const toggleEnableAutoMicSelect = () => { - pendingEnableAutoMicSelect(); - if (currentEnableAutoMicSelect.data) { - asyncStdoutToPython("/set/disable/auto_mic_select"); - } else { - asyncStdoutToPython("/set/enable/auto_mic_select"); - } - }; - - return { - currentEnableAutoMicSelect, - getEnableAutoMicSelect, - updateEnableAutoMicSelect, - toggleEnableAutoMicSelect, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useEnableAutoSpeakerSelect.js b/src-ui/logics/configs/device/useEnableAutoSpeakerSelect.js deleted file mode 100644 index d43184de..00000000 --- a/src-ui/logics/configs/device/useEnableAutoSpeakerSelect.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableAutoSpeakerSelect } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableAutoSpeakerSelect = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableAutoSpeakerSelect, updateEnableAutoSpeakerSelect, pendingEnableAutoSpeakerSelect } = useStore_EnableAutoSpeakerSelect(); - - const getEnableAutoSpeakerSelect = () => { - pendingEnableAutoSpeakerSelect(); - asyncStdoutToPython("/get/data/auto_speaker_select"); - }; - - const toggleEnableAutoSpeakerSelect = () => { - pendingEnableAutoSpeakerSelect(); - if (currentEnableAutoSpeakerSelect.data) { - asyncStdoutToPython("/set/disable/auto_speaker_select"); - } else { - asyncStdoutToPython("/set/enable/auto_speaker_select"); - } - }; - - return { - currentEnableAutoSpeakerSelect, - getEnableAutoSpeakerSelect, - updateEnableAutoSpeakerSelect, - toggleEnableAutoSpeakerSelect, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useMicDeviceList.js b/src-ui/logics/configs/device/useMicDeviceList.js deleted file mode 100644 index 196b32cf..00000000 --- a/src-ui/logics/configs/device/useMicDeviceList.js +++ /dev/null @@ -1,18 +0,0 @@ -import { useStore_MicDeviceList } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMicDeviceList = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentMicDeviceList, updateMicDeviceList, pendingMicDeviceList } = useStore_MicDeviceList(); - - const getMicDeviceList = () => { - pendingMicDeviceList(); - asyncStdoutToPython("/get/data/mic_device_list"); - }; - - return { - currentMicDeviceList, - getMicDeviceList, - updateMicDeviceList, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useMicHostList.js b/src-ui/logics/configs/device/useMicHostList.js deleted file mode 100644 index ed61f80a..00000000 --- a/src-ui/logics/configs/device/useMicHostList.js +++ /dev/null @@ -1,18 +0,0 @@ -import { useStore_MicHostList } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMicHostList = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentMicHostList, updateMicHostList, pendingMicHostList } = useStore_MicHostList(); - - const getMicHostList = () => { - pendingMicHostList(); - asyncStdoutToPython("/get/data/mic_host_list"); - }; - - return { - currentMicHostList, - getMicHostList, - updateMicHostList, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useMicThreshold.js b/src-ui/logics/configs/device/useMicThreshold.js deleted file mode 100644 index ab6bda6c..00000000 --- a/src-ui/logics/configs/device/useMicThreshold.js +++ /dev/null @@ -1,42 +0,0 @@ -import { useStore_MicThreshold, useStore_EnableAutomaticMicThreshold } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMicThreshold = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { updateMicThreshold, currentMicThreshold } = useStore_MicThreshold(); - const { updateEnableAutomaticMicThreshold, currentEnableAutomaticMicThreshold, pendingEnableAutomaticMicThreshold } = useStore_EnableAutomaticMicThreshold(); - - const getMicThreshold = () => { - asyncStdoutToPython("/get/data/mic_threshold"); - }; - - const setMicThreshold = (mic_threshold) => { - asyncStdoutToPython("/set/data/mic_threshold", mic_threshold); - }; - - const getEnableAutomaticMicThreshold = () => { - pendingEnableAutomaticMicThreshold(); - asyncStdoutToPython("/get/data/mic_automatic_threshold"); - }; - - const toggleEnableAutomaticMicThreshold = () => { - pendingEnableAutomaticMicThreshold(); - if (currentEnableAutomaticMicThreshold.data) { - asyncStdoutToPython("/set/disable/mic_automatic_threshold"); - } else { - asyncStdoutToPython("/set/enable/mic_automatic_threshold"); - } - }; - - return { - currentMicThreshold, - getMicThreshold, - setMicThreshold, - updateMicThreshold, - - currentEnableAutomaticMicThreshold, - getEnableAutomaticMicThreshold, - toggleEnableAutomaticMicThreshold, - updateEnableAutomaticMicThreshold, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSelectedMicDevice.js b/src-ui/logics/configs/device/useSelectedMicDevice.js deleted file mode 100644 index 798eae5a..00000000 --- a/src-ui/logics/configs/device/useSelectedMicDevice.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedMicDevice } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedMicDevice = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedMicDevice, updateSelectedMicDevice, pendingSelectedMicDevice } = useStore_SelectedMicDevice(); - - const getSelectedMicDevice = () => { - pendingSelectedMicDevice(); - asyncStdoutToPython("/get/data/selected_mic_device"); - }; - - const setSelectedMicDevice = (selected_mic_device) => { - pendingSelectedMicDevice(); - asyncStdoutToPython("/set/data/selected_mic_device", selected_mic_device); - }; - - return { - currentSelectedMicDevice, - getSelectedMicDevice, - updateSelectedMicDevice, - setSelectedMicDevice, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSelectedMicHost.js b/src-ui/logics/configs/device/useSelectedMicHost.js deleted file mode 100644 index 0ef9c882..00000000 --- a/src-ui/logics/configs/device/useSelectedMicHost.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedMicHost } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedMicHost = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedMicHost, updateSelectedMicHost, pendingSelectedMicHost } = useStore_SelectedMicHost(); - - const getSelectedMicHost = () => { - pendingSelectedMicHost(); - asyncStdoutToPython("/get/data/selected_mic_host"); - }; - - const setSelectedMicHost = (selected_mic_host) => { - pendingSelectedMicHost(); - asyncStdoutToPython("/set/data/selected_mic_host", selected_mic_host); - }; - - return { - currentSelectedMicHost, - getSelectedMicHost, - updateSelectedMicHost, - setSelectedMicHost, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSelectedSpeakerDevice.js b/src-ui/logics/configs/device/useSelectedSpeakerDevice.js deleted file mode 100644 index b8d85693..00000000 --- a/src-ui/logics/configs/device/useSelectedSpeakerDevice.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedSpeakerDevice } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedSpeakerDevice = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedSpeakerDevice, updateSelectedSpeakerDevice, pendingSelectedSpeakerDevice } = useStore_SelectedSpeakerDevice(); - - const getSelectedSpeakerDevice = () => { - pendingSelectedSpeakerDevice(); - asyncStdoutToPython("/get/data/selected_speaker_device"); - }; - - const setSelectedSpeakerDevice = (selected_speaker_device) => { - pendingSelectedSpeakerDevice(); - asyncStdoutToPython("/set/data/selected_speaker_device", selected_speaker_device); - }; - - return { - currentSelectedSpeakerDevice, - getSelectedSpeakerDevice, - updateSelectedSpeakerDevice, - setSelectedSpeakerDevice, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSpeakerDeviceList.js b/src-ui/logics/configs/device/useSpeakerDeviceList.js deleted file mode 100644 index 2848111c..00000000 --- a/src-ui/logics/configs/device/useSpeakerDeviceList.js +++ /dev/null @@ -1,18 +0,0 @@ -import { useStore_SpeakerDeviceList } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSpeakerDeviceList = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSpeakerDeviceList, updateSpeakerDeviceList, pendingSpeakerDeviceList } = useStore_SpeakerDeviceList(); - - const getSpeakerDeviceList = () => { - pendingSpeakerDeviceList(); - asyncStdoutToPython("/get/data/speaker_device_list"); - }; - - return { - currentSpeakerDeviceList, - getSpeakerDeviceList, - updateSpeakerDeviceList, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/device/useSpeakerThreshold.js b/src-ui/logics/configs/device/useSpeakerThreshold.js deleted file mode 100644 index 29824b01..00000000 --- a/src-ui/logics/configs/device/useSpeakerThreshold.js +++ /dev/null @@ -1,42 +0,0 @@ -import { useStore_SpeakerThreshold, useStore_EnableAutomaticSpeakerThreshold } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSpeakerThreshold = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { updateSpeakerThreshold, currentSpeakerThreshold } = useStore_SpeakerThreshold(); - const { updateEnableAutomaticSpeakerThreshold, currentEnableAutomaticSpeakerThreshold, pendingEnableAutomaticSpeakerThreshold } = useStore_EnableAutomaticSpeakerThreshold(); - - const getSpeakerThreshold = () => { - asyncStdoutToPython("/get/data/speaker_threshold"); - }; - - const setSpeakerThreshold = (speaker_threshold) => { - asyncStdoutToPython("/set/data/speaker_threshold", speaker_threshold); - }; - - const getEnableAutomaticSpeakerThreshold = () => { - pendingEnableAutomaticSpeakerThreshold(); - asyncStdoutToPython("/get/data/speaker_automatic_threshold"); - }; - - const toggleEnableAutomaticSpeakerThreshold = () => { - pendingEnableAutomaticSpeakerThreshold(); - if (currentEnableAutomaticSpeakerThreshold.data) { - asyncStdoutToPython("/set/disable/speaker_automatic_threshold"); - } else { - asyncStdoutToPython("/set/enable/speaker_automatic_threshold"); - } - }; - - return { - currentSpeakerThreshold, - getSpeakerThreshold, - setSpeakerThreshold, - updateSpeakerThreshold, - - currentEnableAutomaticSpeakerThreshold, - getEnableAutomaticSpeakerThreshold, - toggleEnableAutomaticSpeakerThreshold, - updateEnableAutomaticSpeakerThreshold, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/hotkeys/useHotkeys.js b/src-ui/logics/configs/hotkeys/useHotkeys.js index a2bbe35d..df7db416 100644 --- a/src-ui/logics/configs/hotkeys/useHotkeys.js +++ b/src-ui/logics/configs/hotkeys/useHotkeys.js @@ -1,5 +1,5 @@ import { store, useStore_Hotkeys } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; import { useNotificationStatus } from "@logics_common"; import { useMainFunction } from "@logics_main"; import { register, unregisterAll, isRegistered } from "@tauri-apps/plugin-global-shortcut"; @@ -20,7 +20,7 @@ export const useHotkeys = () => { pendingHotkeys(); asyncStdoutToPython("/get/data/hotkeys"); }; - const { showNotification_Success, showNotification_Error, closeNotification } = useNotificationStatus(); + const { showNotification_SaveSuccess, showNotification_Error, closeNotification } = useNotificationStatus(); const setHotkeys = (hotkeys) => { pendingHotkeys(); @@ -106,11 +106,17 @@ export const useHotkeys = () => { } }; + const setSuccessHotkeys = (hotkeys) => { + updateHotkeys(hotkeys); + showNotification_SaveSuccess(); + }; + return { currentHotkeys, getHotkeys, updateHotkeys, setHotkeys, + setSuccessHotkeys, registerShortcuts, unregisterAll, }; diff --git a/src-ui/logics/configs/index.js b/src-ui/logics/configs/index.js index 03214771..54e7d133 100644 --- a/src-ui/logics/configs/index.js +++ b/src-ui/logics/configs/index.js @@ -1,66 +1,12 @@ -export { useEnableAutoMicSelect } from "./device/useEnableAutoMicSelect"; -export { useEnableAutoSpeakerSelect } from "./device/useEnableAutoSpeakerSelect"; -export { useMicDeviceList } from "./device/useMicDeviceList"; -export { useMicHostList } from "./device/useMicHostList"; -export { useMicThreshold } from "./device/useMicThreshold"; -export { useSelectedMicDevice } from "./device/useSelectedMicDevice"; -export { useSelectedMicHost } from "./device/useSelectedMicHost"; -export { useSelectedSpeakerDevice } from "./device/useSelectedSpeakerDevice"; -export { useSpeakerDeviceList } from "./device/useSpeakerDeviceList"; -export { useSpeakerThreshold } from "./device/useSpeakerThreshold"; - -export { useMessageLogUiScaling } from "./appearance/useMessageLogUiScaling"; -export { useSelectedFontFamily } from "./appearance/useSelectedFontFamily"; -export { useTransparency } from "./appearance/useTransparency"; -export { useSendMessageButtonType } from "./others/useSendMessageButtonType"; -export { useUiLanguage } from "./appearance/useUiLanguage"; -export { useUiScaling } from "./appearance/useUiScaling"; - -export { useEnableAutoClearMessageInputBox } from "./others/useEnableAutoClearMessageInputBox"; -export { useEnableAutoExportMessageLogs } from "./others/useEnableAutoExportMessageLogs"; -export { useEnableSendMessageToVrc } from "./others/useEnableSendMessageToVrc"; -export { useEnableSendReceivedMessageToVrc } from "./others/useEnableSendReceivedMessageToVrc"; -export { useEnableSendOnlyTranslatedMessages } from "./others/useEnableSendOnlyTranslatedMessages"; -export { useEnableVrcMicMuteSync } from "./others/useEnableVrcMicMuteSync"; -export { useEnableNotificationVrcSfx } from "./others/useEnableNotificationVrcSfx"; - -export { useMicRecordTimeout } from "./transcription/useMicRecordTimeout"; -export { useMicPhraseTimeout } from "./transcription/useMicPhraseTimeout"; -export { useMicMaxWords } from "./transcription/useMicMaxWords"; -export { useMicWordFilterList } from "./transcription/useMicWordFilterList"; - -export { useSpeakerRecordTimeout } from "./transcription/useSpeakerRecordTimeout"; -export { useSpeakerPhraseTimeout } from "./transcription/useSpeakerPhraseTimeout"; -export { useSpeakerMaxWords } from "./transcription/useSpeakerMaxWords"; - -export { useSelectedTranscriptionEngine } from "./transcription/useSelectedTranscriptionEngine"; -export { useWhisperWeightTypeStatus } from "./transcription/useWhisperWeightTypeStatus"; -export { useSelectedWhisperWeightType } from "./transcription/useSelectedWhisperWeightType"; -export { useSelectableWhisperComputeDeviceList } from "./transcription/useSelectableWhisperComputeDeviceList"; -export { useSelectedWhisperComputeDevice } from "./transcription/useSelectedWhisperComputeDevice"; - -export { useDeepLAuthKey } from "./translation/useDeepLAuthKey"; -export { useCTranslate2WeightTypeStatus } from "./translation/useCTranslate2WeightTypeStatus"; -export { useSelectedCTranslate2WeightType } from "./translation/useSelectedCTranslate2WeightType"; -export { useSelectableCTranslate2ComputeDeviceList } from "./translation/useSelectableCTranslate2ComputeDeviceList"; -export { useSelectedCTranslate2ComputeDevice } from "./translation/useSelectedCTranslate2ComputeDevice"; - -export { useIsEnabledOverlaySmallLog } from "./vr/useIsEnabledOverlaySmallLog"; -export { useOverlaySmallLogSettings } from "./vr/useOverlaySmallLogSettings"; -export { useIsEnabledOverlayLargeLog } from "./vr/useIsEnabledOverlayLargeLog"; -export { useOverlayShowOnlyTranslatedMessages } from "./vr/useOverlayShowOnlyTranslatedMessages"; -export { useOverlayLargeLogSettings } from "./vr/useOverlayLargeLogSettings"; -export { useSendTextToOverlay } from "./vr/useSendTextToOverlay"; - +export { useDevice } from "./device/useDevice"; +export { useAppearance } from "./appearance/useAppearance"; +export { useOthers } from "./others/useOthers"; +export { useTranscription } from "./transcription/useTranscription"; +export { useTranslation } from "./translation/useTranslation"; +export { useVr } from "./vr/useVr"; export { useHotkeys } from "./hotkeys/useHotkeys"; - -export { useOscIpAddress } from "./advanced_settings/useOscIpAddress"; -export { useOscPort } from "./advanced_settings/useOscPort"; -export { useWebsocket } from "./advanced_settings/useWebsocket"; - - +export { useAdvancedSettings } from "./advanced_settings/useAdvancedSettings"; export { useSupporters } from "./supporters/useSupporters"; - export { usePlugins } from "./plugins/usePlugins"; export { useSettingBoxScrollPosition } from "./useSettingBoxScrollPosition"; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useEnableAutoClearMessageInputBox.js b/src-ui/logics/configs/others/useEnableAutoClearMessageInputBox.js deleted file mode 100644 index d04c6094..00000000 --- a/src-ui/logics/configs/others/useEnableAutoClearMessageInputBox.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableAutoClearMessageInputBox } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableAutoClearMessageInputBox = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableAutoClearMessageInputBox, updateEnableAutoClearMessageInputBox, pendingEnableAutoClearMessageInputBox } = useStore_EnableAutoClearMessageInputBox(); - - const getEnableAutoClearMessageInputBox = () => { - pendingEnableAutoClearMessageInputBox(); - asyncStdoutToPython("/get/data/auto_clear_message_box"); - }; - - const toggleEnableAutoClearMessageInputBox = () => { - pendingEnableAutoClearMessageInputBox(); - if (currentEnableAutoClearMessageInputBox.data) { - asyncStdoutToPython("/set/disable/auto_clear_message_box"); - } else { - asyncStdoutToPython("/set/enable/auto_clear_message_box"); - } - }; - - return { - currentEnableAutoClearMessageInputBox, - getEnableAutoClearMessageInputBox, - toggleEnableAutoClearMessageInputBox, - updateEnableAutoClearMessageInputBox, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useEnableAutoExportMessageLogs.js b/src-ui/logics/configs/others/useEnableAutoExportMessageLogs.js deleted file mode 100644 index 8249a83a..00000000 --- a/src-ui/logics/configs/others/useEnableAutoExportMessageLogs.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableAutoExportMessageLogs } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableAutoExportMessageLogs = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableAutoExportMessageLogs, updateEnableAutoExportMessageLogs, pendingEnableAutoExportMessageLogs } = useStore_EnableAutoExportMessageLogs(); - - const getEnableAutoExportMessageLogs = () => { - pendingEnableAutoExportMessageLogs(); - asyncStdoutToPython("/get/data/logger_feature"); - }; - - const toggleEnableAutoExportMessageLogs = () => { - pendingEnableAutoExportMessageLogs(); - if (currentEnableAutoExportMessageLogs.data) { - asyncStdoutToPython("/set/disable/logger_feature"); - } else { - asyncStdoutToPython("/set/enable/logger_feature"); - } - }; - - return { - currentEnableAutoExportMessageLogs, - getEnableAutoExportMessageLogs, - toggleEnableAutoExportMessageLogs, - updateEnableAutoExportMessageLogs, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useEnableNotificationVrcSfx.js b/src-ui/logics/configs/others/useEnableNotificationVrcSfx.js deleted file mode 100644 index 24e1096a..00000000 --- a/src-ui/logics/configs/others/useEnableNotificationVrcSfx.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableNotificationVrcSfx } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableNotificationVrcSfx = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableNotificationVrcSfx, updateEnableNotificationVrcSfx, pendingEnableNotificationVrcSfx } = useStore_EnableNotificationVrcSfx(); - - const getEnableNotificationVrcSfx = () => { - pendingEnableNotificationVrcSfx(); - asyncStdoutToPython("/get/data/notification_vrc_sfx"); - }; - - const toggleEnableNotificationVrcSfx = () => { - pendingEnableNotificationVrcSfx(); - if (currentEnableNotificationVrcSfx.data) { - asyncStdoutToPython("/set/disable/notification_vrc_sfx"); - } else { - asyncStdoutToPython("/set/enable/notification_vrc_sfx"); - } - }; - - return { - currentEnableNotificationVrcSfx, - getEnableNotificationVrcSfx, - toggleEnableNotificationVrcSfx, - updateEnableNotificationVrcSfx, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useEnableSendMessageToVrc.js b/src-ui/logics/configs/others/useEnableSendMessageToVrc.js deleted file mode 100644 index 10ef4b0c..00000000 --- a/src-ui/logics/configs/others/useEnableSendMessageToVrc.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableSendMessageToVrc } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableSendMessageToVrc = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableSendMessageToVrc, updateEnableSendMessageToVrc, pendingEnableSendMessageToVrc } = useStore_EnableSendMessageToVrc(); - - const getEnableSendMessageToVrc = () => { - pendingEnableSendMessageToVrc(); - asyncStdoutToPython("/get/data/send_message_to_vrc"); - }; - - const toggleEnableSendMessageToVrc = () => { - pendingEnableSendMessageToVrc(); - if (currentEnableSendMessageToVrc.data) { - asyncStdoutToPython("/set/disable/send_message_to_vrc"); - } else { - asyncStdoutToPython("/set/enable/send_message_to_vrc"); - } - }; - - return { - currentEnableSendMessageToVrc, - getEnableSendMessageToVrc, - toggleEnableSendMessageToVrc, - updateEnableSendMessageToVrc, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useEnableSendOnlyTranslatedMessages.js b/src-ui/logics/configs/others/useEnableSendOnlyTranslatedMessages.js deleted file mode 100644 index 7e9abefb..00000000 --- a/src-ui/logics/configs/others/useEnableSendOnlyTranslatedMessages.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableSendOnlyTranslatedMessages } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableSendOnlyTranslatedMessages = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableSendOnlyTranslatedMessages, updateEnableSendOnlyTranslatedMessages, pendingEnableSendOnlyTranslatedMessages } = useStore_EnableSendOnlyTranslatedMessages(); - - const getEnableSendOnlyTranslatedMessages = () => { - pendingEnableSendOnlyTranslatedMessages(); - asyncStdoutToPython("/get/data/send_only_translated_messages"); - }; - - const toggleEnableSendOnlyTranslatedMessages = () => { - pendingEnableSendOnlyTranslatedMessages(); - if (currentEnableSendOnlyTranslatedMessages.data) { - asyncStdoutToPython("/set/disable/send_only_translated_messages"); - } else { - asyncStdoutToPython("/set/enable/send_only_translated_messages"); - } - }; - - return { - currentEnableSendOnlyTranslatedMessages, - getEnableSendOnlyTranslatedMessages, - toggleEnableSendOnlyTranslatedMessages, - updateEnableSendOnlyTranslatedMessages, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useEnableSendReceivedMessageToVrc.js b/src-ui/logics/configs/others/useEnableSendReceivedMessageToVrc.js deleted file mode 100644 index 5eeeb102..00000000 --- a/src-ui/logics/configs/others/useEnableSendReceivedMessageToVrc.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableSendReceivedMessageToVrc } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableSendReceivedMessageToVrc = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableSendReceivedMessageToVrc, updateEnableSendReceivedMessageToVrc, pendingEnableSendReceivedMessageToVrc } = useStore_EnableSendReceivedMessageToVrc(); - - const getEnableSendReceivedMessageToVrc = () => { - pendingEnableSendReceivedMessageToVrc(); - asyncStdoutToPython("/get/data/send_received_message_to_vrc"); - }; - - const toggleEnableSendReceivedMessageToVrc = () => { - pendingEnableSendReceivedMessageToVrc(); - if (currentEnableSendReceivedMessageToVrc.data) { - asyncStdoutToPython("/set/disable/send_received_message_to_vrc"); - } else { - asyncStdoutToPython("/set/enable/send_received_message_to_vrc"); - } - }; - - return { - currentEnableSendReceivedMessageToVrc, - getEnableSendReceivedMessageToVrc, - toggleEnableSendReceivedMessageToVrc, - updateEnableSendReceivedMessageToVrc, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useEnableVrcMicMuteSync.js b/src-ui/logics/configs/others/useEnableVrcMicMuteSync.js deleted file mode 100644 index 6515ffc2..00000000 --- a/src-ui/logics/configs/others/useEnableVrcMicMuteSync.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_EnableVrcMicMuteSync } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useEnableVrcMicMuteSync = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentEnableVrcMicMuteSync, updateEnableVrcMicMuteSync, pendingEnableVrcMicMuteSync } = useStore_EnableVrcMicMuteSync(); - - const getEnableVrcMicMuteSync = () => { - pendingEnableVrcMicMuteSync(); - asyncStdoutToPython("/get/data/vrc_mic_mute_sync"); - }; - - const toggleEnableVrcMicMuteSync = () => { - pendingEnableVrcMicMuteSync(); - if (currentEnableVrcMicMuteSync.data.is_enabled) { - asyncStdoutToPython("/set/disable/vrc_mic_mute_sync"); - } else { - asyncStdoutToPython("/set/enable/vrc_mic_mute_sync"); - } - }; - - return { - currentEnableVrcMicMuteSync, - getEnableVrcMicMuteSync, - toggleEnableVrcMicMuteSync, - updateEnableVrcMicMuteSync, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useOthers.js b/src-ui/logics/configs/others/useOthers.js new file mode 100644 index 00000000..62a14364 --- /dev/null +++ b/src-ui/logics/configs/others/useOthers.js @@ -0,0 +1,229 @@ +import { + useStore_EnableAutoClearMessageInputBox, + useStore_EnableSendOnlyTranslatedMessages, + useStore_EnableAutoExportMessageLogs, + useStore_EnableVrcMicMuteSync, + useStore_EnableSendMessageToVrc, + useStore_EnableNotificationVrcSfx, + useStore_EnableSendReceivedMessageToVrc, +} from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { useNotificationStatus } from "@logics_common"; + +export const useOthers = () => { + const { asyncStdoutToPython } = useStdoutToPython(); + + // Auto Clear Message Input Box + const { currentEnableAutoClearMessageInputBox, updateEnableAutoClearMessageInputBox, pendingEnableAutoClearMessageInputBox } = useStore_EnableAutoClearMessageInputBox(); + // Send Only Translated Messages + const { currentEnableSendOnlyTranslatedMessages, updateEnableSendOnlyTranslatedMessages, pendingEnableSendOnlyTranslatedMessages } = useStore_EnableSendOnlyTranslatedMessages(); + // Auto Export Message Logs + const { currentEnableAutoExportMessageLogs, updateEnableAutoExportMessageLogs, pendingEnableAutoExportMessageLogs } = useStore_EnableAutoExportMessageLogs(); + // VRC Mic Mute Sync + const { currentEnableVrcMicMuteSync, updateEnableVrcMicMuteSync, pendingEnableVrcMicMuteSync } = useStore_EnableVrcMicMuteSync(); + // Send Message To VRCT + const { currentEnableSendMessageToVrc, updateEnableSendMessageToVrc, pendingEnableSendMessageToVrc } = useStore_EnableSendMessageToVrc(); + // Sounds + // Notification VRC SFX + const { currentEnableNotificationVrcSfx, updateEnableNotificationVrcSfx, pendingEnableNotificationVrcSfx } = useStore_EnableNotificationVrcSfx(); + // Speaker2Chatbox + // Send Received Message To VRC + const { currentEnableSendReceivedMessageToVrc, updateEnableSendReceivedMessageToVrc, pendingEnableSendReceivedMessageToVrc } = useStore_EnableSendReceivedMessageToVrc(); + + const { showNotification_SaveSuccess } = useNotificationStatus(); + + // Auto Clear Message Input Box + const getEnableAutoClearMessageInputBox = () => { + pendingEnableAutoClearMessageInputBox(); + asyncStdoutToPython("/get/data/auto_clear_message_box"); + }; + + const toggleEnableAutoClearMessageInputBox = () => { + pendingEnableAutoClearMessageInputBox(); + if (currentEnableAutoClearMessageInputBox.data) { + asyncStdoutToPython("/set/disable/auto_clear_message_box"); + } else { + asyncStdoutToPython("/set/enable/auto_clear_message_box"); + } + }; + + const setSuccessEnableAutoClearMessageInputBox = (enabled) => { + updateEnableAutoClearMessageInputBox(enabled); + showNotification_SaveSuccess(); + }; + + // Send Only Translated Messages + const getEnableSendOnlyTranslatedMessages = () => { + pendingEnableSendOnlyTranslatedMessages(); + asyncStdoutToPython("/get/data/send_only_translated_messages"); + }; + + const toggleEnableSendOnlyTranslatedMessages = () => { + pendingEnableSendOnlyTranslatedMessages(); + if (currentEnableSendOnlyTranslatedMessages.data) { + asyncStdoutToPython("/set/disable/send_only_translated_messages"); + } else { + asyncStdoutToPython("/set/enable/send_only_translated_messages"); + } + }; + + const setSuccessEnableSendOnlyTranslatedMessages = (enabled) => { + updateEnableSendOnlyTranslatedMessages(enabled); + showNotification_SaveSuccess(); + }; + + // Auto Export Message Logs + const getEnableAutoExportMessageLogs = () => { + pendingEnableAutoExportMessageLogs(); + asyncStdoutToPython("/get/data/logger_feature"); + }; + + const toggleEnableAutoExportMessageLogs = () => { + pendingEnableAutoExportMessageLogs(); + if (currentEnableAutoExportMessageLogs.data) { + asyncStdoutToPython("/set/disable/logger_feature"); + } else { + asyncStdoutToPython("/set/enable/logger_feature"); + } + }; + + const setSuccessEnableAutoExportMessageLogs = (enabled) => { + updateEnableAutoExportMessageLogs(enabled); + showNotification_SaveSuccess(); + }; + + // VRC Mic Mute Sync + const getEnableVrcMicMuteSync = () => { + pendingEnableVrcMicMuteSync(); + asyncStdoutToPython("/get/data/vrc_mic_mute_sync"); + }; + + const toggleEnableVrcMicMuteSync = () => { + pendingEnableVrcMicMuteSync(); + if (currentEnableVrcMicMuteSync.data.is_enabled) { + asyncStdoutToPython("/set/disable/vrc_mic_mute_sync"); + } else { + asyncStdoutToPython("/set/enable/vrc_mic_mute_sync"); + } + }; + + const setSuccessEnableVrcMicMuteSync = (is_enabled) => { + updateEnableVrcMicMuteSync(old => ({ ...old.data, is_enabled: is_enabled })); + showNotification_SaveSuccess(); + }; + + // Send Message To VRCT + const getEnableSendMessageToVrc = () => { + pendingEnableSendMessageToVrc(); + asyncStdoutToPython("/get/data/send_message_to_vrc"); + }; + + const toggleEnableSendMessageToVrc = () => { + pendingEnableSendMessageToVrc(); + if (currentEnableSendMessageToVrc.data) { + asyncStdoutToPython("/set/disable/send_message_to_vrc"); + } else { + asyncStdoutToPython("/set/enable/send_message_to_vrc"); + } + }; + + const setSuccessEnableSendMessageToVrc = (enabled) => { + updateEnableSendMessageToVrc(enabled); + showNotification_SaveSuccess(); + }; + + // Sounds + // Notification VRC SFX + const getEnableNotificationVrcSfx = () => { + pendingEnableNotificationVrcSfx(); + asyncStdoutToPython("/get/data/notification_vrc_sfx"); + }; + + const toggleEnableNotificationVrcSfx = () => { + pendingEnableNotificationVrcSfx(); + if (currentEnableNotificationVrcSfx.data) { + asyncStdoutToPython("/set/disable/notification_vrc_sfx"); + } else { + asyncStdoutToPython("/set/enable/notification_vrc_sfx"); + } + }; + + const setSuccessEnableNotificationVrcSfx = (enabled) => { + updateEnableNotificationVrcSfx(enabled); + showNotification_SaveSuccess(); + }; + + // Speaker2Chatbox + // Send Received Message To VRC + const getEnableSendReceivedMessageToVrc = () => { + pendingEnableSendReceivedMessageToVrc(); + asyncStdoutToPython("/get/data/send_received_message_to_vrc"); + }; + + const toggleEnableSendReceivedMessageToVrc = () => { + pendingEnableSendReceivedMessageToVrc(); + if (currentEnableSendReceivedMessageToVrc.data) { + asyncStdoutToPython("/set/disable/send_received_message_to_vrc"); + } else { + asyncStdoutToPython("/set/enable/send_received_message_to_vrc"); + } + }; + + const setSuccessEnableSendReceivedMessageToVrc = (enabled) => { + updateEnableSendReceivedMessageToVrc(enabled); + showNotification_SaveSuccess(); + }; + + return { + // Auto Clear Message Input Box + currentEnableAutoClearMessageInputBox, + getEnableAutoClearMessageInputBox, + toggleEnableAutoClearMessageInputBox, + updateEnableAutoClearMessageInputBox, + setSuccessEnableAutoClearMessageInputBox, + + // Send Only Translated Messages + currentEnableSendOnlyTranslatedMessages, + getEnableSendOnlyTranslatedMessages, + toggleEnableSendOnlyTranslatedMessages, + updateEnableSendOnlyTranslatedMessages, + setSuccessEnableSendOnlyTranslatedMessages, + + // Auto Export Message Logs + currentEnableAutoExportMessageLogs, + getEnableAutoExportMessageLogs, + toggleEnableAutoExportMessageLogs, + updateEnableAutoExportMessageLogs, + setSuccessEnableAutoExportMessageLogs, + + // VRC Mic Mute Sync + currentEnableVrcMicMuteSync, + getEnableVrcMicMuteSync, + toggleEnableVrcMicMuteSync, + updateEnableVrcMicMuteSync, + setSuccessEnableVrcMicMuteSync, + + // Send Message To VRCT + currentEnableSendMessageToVrc, + getEnableSendMessageToVrc, + toggleEnableSendMessageToVrc, + updateEnableSendMessageToVrc, + setSuccessEnableSendMessageToVrc, + + // Sounds + // Notification VRC SFX + currentEnableNotificationVrcSfx, + getEnableNotificationVrcSfx, + toggleEnableNotificationVrcSfx, + updateEnableNotificationVrcSfx, + setSuccessEnableNotificationVrcSfx, + + // Speaker2Chatbox + // Send Received Message To VRC + currentEnableSendReceivedMessageToVrc, + getEnableSendReceivedMessageToVrc, + toggleEnableSendReceivedMessageToVrc, + updateEnableSendReceivedMessageToVrc, + setSuccessEnableSendReceivedMessageToVrc, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/configs/others/useSendMessageButtonType.js b/src-ui/logics/configs/others/useSendMessageButtonType.js deleted file mode 100644 index a6a22add..00000000 --- a/src-ui/logics/configs/others/useSendMessageButtonType.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SendMessageButtonType } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSendMessageButtonType = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSendMessageButtonType, updateSendMessageButtonType, pendingSendMessageButtonType } = useStore_SendMessageButtonType(); - - const getSendMessageButtonType = () => { - pendingSendMessageButtonType(); - asyncStdoutToPython("/get/data/send_message_button_type"); - }; - - const setSendMessageButtonType = (send_message_button_type) => { - pendingSendMessageButtonType(); - asyncStdoutToPython("/set/data/send_message_button_type", send_message_button_type); - }; - - return { - currentSendMessageButtonType, - getSendMessageButtonType, - setSendMessageButtonType, - updateSendMessageButtonType, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/plugins/usePlugins.js b/src-ui/logics/configs/plugins/usePlugins.js index d4d398fa..bec290ba 100644 --- a/src-ui/logics/configs/plugins/usePlugins.js +++ b/src-ui/logics/configs/plugins/usePlugins.js @@ -1,5 +1,5 @@ import { invoke } from "@tauri-apps/api/core"; -import { useTranslation } from "react-i18next"; +import { useI18n } from "@useI18n"; import { IS_PLUGIN_PATH_DEV_MODE, getPluginsList } from "@ui_configs"; import { store, @@ -11,7 +11,7 @@ import { useStore_FetchedPluginsInfo, useStore_LoadedPlugins, } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; import { transform } from "@babel/standalone"; import { writeFile, mkdir, exists, remove, readDir, BaseDirectory, readTextFile } from "@tauri-apps/plugin-fs"; @@ -36,8 +36,8 @@ import * as logics_common from "@logics_common"; const PLUGIN_LIST_URL = getPluginsList(); export const usePlugins = () => { - const { t } = useTranslation(); - const { showNotification_Success, showNotification_Error } = useNotificationStatus(); + const { t, i18n } = useI18n(); + const { showNotification_SaveSuccess, showNotification_Success, showNotification_Error } = useNotificationStatus(); const { asyncStdoutToPython } = useStdoutToPython(); const { currentFetchedPluginsInfo, updateFetchedPluginsInfo, pendingFetchedPluginsInfo, errorFetchedPluginsInfo } = useStore_FetchedPluginsInfo(); @@ -50,8 +50,6 @@ export const usePlugins = () => { const { asyncTauriFetchGithub } = useFetch(); - const { i18n } = useTranslation(); - const generatePluginContext = (downloaded_plugin_info) => { const plugin_context = { registerComponent: (component) => { @@ -284,40 +282,57 @@ export const usePlugins = () => { }); }; - const toggleSavedPluginsStatus = (target_plugin_id) => { - const is_exists = currentSavedPluginsStatus.data.some( + const setSavedPluginEnabled = (target_plugin_id, is_enabled) => { + const notify = () => { + const msg_key = is_enabled + ? "plugin_notifications.is_enabled" + : "plugin_notifications.is_disabled"; + showNotification_Success(t(msg_key), { + hide_duration: 1000, + category_id: "switch_enable_plugin", + }); + } + + const exists = currentSavedPluginsStatus.data.some( (d) => d.plugin_id === target_plugin_id ); + let new_value = []; - if (is_exists) { + + if (exists) { new_value = currentSavedPluginsStatus.data.map((d) => { if (d.plugin_id === target_plugin_id) { - d.is_enabled = !d.is_enabled; - (d.is_enabled) - ? showNotification_Success(t("plugin_notifications.is_enabled")) - : showNotification_Success(t("plugin_notifications.is_disabled")); + d.is_enabled = is_enabled; + notify(); } return d; }); } else { - new_value.push(...currentSavedPluginsStatus.data); - new_value.push({ - plugin_id: target_plugin_id, - is_enabled: true, - }); - showNotification_Success(t("plugin_notifications.is_enabled")) + // 存在しない場合は追加 + new_value = [ + ...currentSavedPluginsStatus.data, + { plugin_id: target_plugin_id, is_enabled: is_enabled } + ]; + notify(); } - // 「currentPluginsData.data」でis_downloadedがtrueのものだけ残す + // ダウンロード済みプラグインのみ残す new_value = new_value.filter((item) => currentPluginsData.data.some( - (plugin) => plugin.plugin_id === item.plugin_id && plugin.is_downloaded + (p) => p.plugin_id === item.plugin_id && p.is_downloaded ) ); setSavedPluginsStatus(new_value); }; + const toggleSavedPluginsStatus = (plugin_id) => { + // 現在の状態を探す(未登録なら false とみなす) + const current = currentSavedPluginsStatus.data.find( + (d) => d.plugin_id === plugin_id + )?.is_enabled ?? false; + setSavedPluginEnabled(plugin_id, !current); + }; // Init時の処理 非対応のものを無効化する際に、savedDPluginsStatusから不要なものを削除する処理が邪魔になるので該当コードを削除したバージョン。Init以外で使用する時にはリファクタが必要になる。 const setTargetSavedPluginsStatus_Init = (target_plugin_id, is_enabled) => { @@ -373,6 +388,19 @@ export const usePlugins = () => { }); } + const setSuccessSavedPluginsStatus = (plugins_status) => { + updateSavedPluginsStatus(plugins_status); + showNotification_SaveSuccess(); + }; + + const setErrorPlugin = (plugin_id, error_message_type) => { + const error_message = t("plugin_notifications.disabled_due_to_an_error"); + + setSavedPluginEnabled(plugin_id, false); + updateTargetPluginData(plugin_id, "is_error", true); + updateTargetPluginData(plugin_id, "error_message_type", error_message_type); + showNotification_Error(error_message); + }; return { @@ -387,6 +415,7 @@ export const usePlugins = () => { currentSavedPluginsStatus, updateSavedPluginsStatus, + setSuccessSavedPluginsStatus, currentPluginsData, updatePluginsData, @@ -399,11 +428,15 @@ export const usePlugins = () => { currentLoadedPlugins, updateLoadedPlugins, + setSavedPluginEnabled, toggleSavedPluginsStatus, setTargetSavedPluginsStatus_Init, setSavedPluginsStatus, + handlePendingPlugin, + + setErrorPlugin, }; }; diff --git a/src-ui/logics/configs/supporters/useSupporters.jsx b/src-ui/logics/configs/supporters/useSupporters.js similarity index 100% rename from src-ui/logics/configs/supporters/useSupporters.jsx rename to src-ui/logics/configs/supporters/useSupporters.js diff --git a/src-ui/logics/configs/transcription/useMicMaxWords.js b/src-ui/logics/configs/transcription/useMicMaxWords.js deleted file mode 100644 index 7415d655..00000000 --- a/src-ui/logics/configs/transcription/useMicMaxWords.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_MicMaxWords } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMicMaxWords = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentMicMaxWords, updateMicMaxWords, pendingMicMaxWords } = useStore_MicMaxWords(); - - const getMicMaxWords = () => { - pendingMicMaxWords(); - asyncStdoutToPython("/get/data/mic_max_phrases"); - }; - - const setMicMaxWords = (selected_mic_max_phrases) => { - pendingMicMaxWords(); - asyncStdoutToPython("/set/data/mic_max_phrases", selected_mic_max_phrases); - }; - - return { - currentMicMaxWords, - getMicMaxWords, - updateMicMaxWords, - setMicMaxWords, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useMicPhraseTimeout.js b/src-ui/logics/configs/transcription/useMicPhraseTimeout.js deleted file mode 100644 index 02601b0c..00000000 --- a/src-ui/logics/configs/transcription/useMicPhraseTimeout.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_MicPhraseTimeout } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMicPhraseTimeout = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentMicPhraseTimeout, updateMicPhraseTimeout, pendingMicPhraseTimeout } = useStore_MicPhraseTimeout(); - - const getMicPhraseTimeout = () => { - pendingMicPhraseTimeout(); - asyncStdoutToPython("/get/data/mic_phrase_timeout"); - }; - - const setMicPhraseTimeout = (selected_mic_phrase_timeout) => { - pendingMicPhraseTimeout(); - asyncStdoutToPython("/set/data/mic_phrase_timeout", selected_mic_phrase_timeout); - }; - - return { - currentMicPhraseTimeout, - getMicPhraseTimeout, - updateMicPhraseTimeout, - setMicPhraseTimeout, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useMicRecordTimeout.js b/src-ui/logics/configs/transcription/useMicRecordTimeout.js deleted file mode 100644 index 27798804..00000000 --- a/src-ui/logics/configs/transcription/useMicRecordTimeout.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_MicRecordTimeout } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMicRecordTimeout = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentMicRecordTimeout, updateMicRecordTimeout, pendingMicRecordTimeout } = useStore_MicRecordTimeout(); - - const getMicRecordTimeout = () => { - pendingMicRecordTimeout(); - asyncStdoutToPython("/get/data/mic_record_timeout"); - }; - - const setMicRecordTimeout = (selected_mic_record_timeout) => { - pendingMicRecordTimeout(); - asyncStdoutToPython("/set/data/mic_record_timeout", selected_mic_record_timeout); - }; - - return { - currentMicRecordTimeout, - getMicRecordTimeout, - updateMicRecordTimeout, - setMicRecordTimeout, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useMicWordFilterList.js b/src-ui/logics/configs/transcription/useMicWordFilterList.js deleted file mode 100644 index cca40b0a..00000000 --- a/src-ui/logics/configs/transcription/useMicWordFilterList.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_MicWordFilterList } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useMicWordFilterList = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentMicWordFilterList, updateMicWordFilterList, pendingMicWordFilterList } = useStore_MicWordFilterList(); - - const getMicWordFilterList = () => { - pendingMicWordFilterList(); - asyncStdoutToPython("/get/data/mic_word_filter"); - }; - - const setMicWordFilterList = (selected_mic_word_filter) => { - pendingMicWordFilterList(); - asyncStdoutToPython("/set/data/mic_word_filter", selected_mic_word_filter); - }; - - return { - currentMicWordFilterList, - getMicWordFilterList, - updateMicWordFilterList, - setMicWordFilterList, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useSelectableWhisperComputeDeviceList.js b/src-ui/logics/configs/transcription/useSelectableWhisperComputeDeviceList.js deleted file mode 100644 index 94ae24f6..00000000 --- a/src-ui/logics/configs/transcription/useSelectableWhisperComputeDeviceList.js +++ /dev/null @@ -1,18 +0,0 @@ -import { useStore_SelectableWhisperComputeDeviceList } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectableWhisperComputeDeviceList = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectableWhisperComputeDeviceList, updateSelectableWhisperComputeDeviceList, pendingSelectableWhisperComputeDeviceList } = useStore_SelectableWhisperComputeDeviceList(); - - const getSelectableWhisperComputeDeviceList = () => { - pendingSelectableWhisperComputeDeviceList(); - asyncStdoutToPython("/get/data/transcription_compute_device_list"); - }; - - return { - currentSelectableWhisperComputeDeviceList, - getSelectableWhisperComputeDeviceList, - updateSelectableWhisperComputeDeviceList, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useSelectedTranscriptionEngine.js b/src-ui/logics/configs/transcription/useSelectedTranscriptionEngine.js deleted file mode 100644 index 43f0b6ab..00000000 --- a/src-ui/logics/configs/transcription/useSelectedTranscriptionEngine.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedTranscriptionEngine } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedTranscriptionEngine = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedTranscriptionEngine, updateSelectedTranscriptionEngine, pendingSelectedTranscriptionEngine } = useStore_SelectedTranscriptionEngine(); - - const getSelectedTranscriptionEngine = () => { - pendingSelectedTranscriptionEngine(); - asyncStdoutToPython("/get/data/selected_transcription_engine"); - }; - - const setSelectedTranscriptionEngine = (selected_transcription_engine) => { - pendingSelectedTranscriptionEngine(); - asyncStdoutToPython("/set/data/selected_transcription_engine", selected_transcription_engine); - }; - - return { - currentSelectedTranscriptionEngine, - getSelectedTranscriptionEngine, - updateSelectedTranscriptionEngine, - setSelectedTranscriptionEngine, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useSelectedWhisperComputeDevice.js b/src-ui/logics/configs/transcription/useSelectedWhisperComputeDevice.js deleted file mode 100644 index f2d34af1..00000000 --- a/src-ui/logics/configs/transcription/useSelectedWhisperComputeDevice.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedWhisperComputeDevice } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedWhisperComputeDevice = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedWhisperComputeDevice, updateSelectedWhisperComputeDevice, pendingSelectedWhisperComputeDevice } = useStore_SelectedWhisperComputeDevice(); - - const getSelectedWhisperComputeDevice = () => { - pendingSelectedWhisperComputeDevice(); - asyncStdoutToPython("/get/data/selected_transcription_compute_device"); - }; - - const setSelectedWhisperComputeDevice = (selected_transcription_compute_device) => { - pendingSelectedWhisperComputeDevice(); - asyncStdoutToPython("/set/data/selected_transcription_compute_device", selected_transcription_compute_device); - }; - - return { - currentSelectedWhisperComputeDevice, - getSelectedWhisperComputeDevice, - updateSelectedWhisperComputeDevice, - setSelectedWhisperComputeDevice, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useSelectedWhisperWeightType.js b/src-ui/logics/configs/transcription/useSelectedWhisperWeightType.js deleted file mode 100644 index 02993646..00000000 --- a/src-ui/logics/configs/transcription/useSelectedWhisperWeightType.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedWhisperWeightType } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedWhisperWeightType = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedWhisperWeightType, updateSelectedWhisperWeightType, pendingSelectedWhisperWeightType } = useStore_SelectedWhisperWeightType(); - - const getSelectedWhisperWeightType = () => { - pendingSelectedWhisperWeightType(); - asyncStdoutToPython("/get/data/whisper_weight_type"); - }; - - const setSelectedWhisperWeightType = (selected_whisper_weight_type) => { - pendingSelectedWhisperWeightType(); - asyncStdoutToPython("/set/data/whisper_weight_type", selected_whisper_weight_type); - }; - - return { - currentSelectedWhisperWeightType, - getSelectedWhisperWeightType, - updateSelectedWhisperWeightType, - setSelectedWhisperWeightType, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useSpeakerMaxWords.js b/src-ui/logics/configs/transcription/useSpeakerMaxWords.js deleted file mode 100644 index 8678ceb2..00000000 --- a/src-ui/logics/configs/transcription/useSpeakerMaxWords.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SpeakerMaxWords } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSpeakerMaxWords = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSpeakerMaxWords, updateSpeakerMaxWords, pendingSpeakerMaxWords } = useStore_SpeakerMaxWords(); - - const getSpeakerMaxWords = () => { - pendingSpeakerMaxWords(); - asyncStdoutToPython("/get/data/speaker_max_phrases"); - }; - - const setSpeakerMaxWords = (selected_speaker_max_phrases) => { - pendingSpeakerMaxWords(); - asyncStdoutToPython("/set/data/speaker_max_phrases", selected_speaker_max_phrases); - }; - - return { - currentSpeakerMaxWords, - getSpeakerMaxWords, - updateSpeakerMaxWords, - setSpeakerMaxWords, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useSpeakerPhraseTimeout.js b/src-ui/logics/configs/transcription/useSpeakerPhraseTimeout.js deleted file mode 100644 index af9e8fba..00000000 --- a/src-ui/logics/configs/transcription/useSpeakerPhraseTimeout.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SpeakerPhraseTimeout } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSpeakerPhraseTimeout = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSpeakerPhraseTimeout, updateSpeakerPhraseTimeout, pendingSpeakerPhraseTimeout } = useStore_SpeakerPhraseTimeout(); - - const getSpeakerPhraseTimeout = () => { - pendingSpeakerPhraseTimeout(); - asyncStdoutToPython("/get/data/speaker_phrase_timeout"); - }; - - const setSpeakerPhraseTimeout = (selected_speaker_phrase_timeout) => { - pendingSpeakerPhraseTimeout(); - asyncStdoutToPython("/set/data/speaker_phrase_timeout", selected_speaker_phrase_timeout); - }; - - return { - currentSpeakerPhraseTimeout, - getSpeakerPhraseTimeout, - updateSpeakerPhraseTimeout, - setSpeakerPhraseTimeout, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useSpeakerRecordTimeout.js b/src-ui/logics/configs/transcription/useSpeakerRecordTimeout.js deleted file mode 100644 index 5d17754c..00000000 --- a/src-ui/logics/configs/transcription/useSpeakerRecordTimeout.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SpeakerRecordTimeout } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSpeakerRecordTimeout = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSpeakerRecordTimeout, updateSpeakerRecordTimeout, pendingSpeakerRecordTimeout } = useStore_SpeakerRecordTimeout(); - - const getSpeakerRecordTimeout = () => { - pendingSpeakerRecordTimeout(); - asyncStdoutToPython("/get/data/speaker_record_timeout"); - }; - - const setSpeakerRecordTimeout = (selected_speaker_record_timeout) => { - pendingSpeakerRecordTimeout(); - asyncStdoutToPython("/set/data/speaker_record_timeout", selected_speaker_record_timeout); - }; - - return { - currentSpeakerRecordTimeout, - getSpeakerRecordTimeout, - updateSpeakerRecordTimeout, - setSpeakerRecordTimeout, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useTranscription.js b/src-ui/logics/configs/transcription/useTranscription.js new file mode 100644 index 00000000..0c4b8b2b --- /dev/null +++ b/src-ui/logics/configs/transcription/useTranscription.js @@ -0,0 +1,341 @@ +import { + useStore_MicRecordTimeout, + useStore_MicPhraseTimeout, + useStore_MicMaxWords, + useStore_MicWordFilterList, + + useStore_SpeakerMaxWords, + useStore_SpeakerPhraseTimeout, + useStore_SpeakerRecordTimeout, + + useStore_SelectableWhisperComputeDeviceList, + useStore_SelectedTranscriptionEngine, + useStore_SelectedWhisperComputeDevice, + useStore_SelectedWhisperWeightType, + + useStore_WhisperWeightTypeStatus, +} from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { transformToIndexedArray } from "@utils"; +import { useNotificationStatus } from "@logics_common"; + +export const useTranscription = () => { + const { asyncStdoutToPython } = useStdoutToPython(); + const { showNotification_SaveSuccess } = useNotificationStatus(); + + // Mic + const { currentMicRecordTimeout, updateMicRecordTimeout, pendingMicRecordTimeout } = useStore_MicRecordTimeout(); + const { currentMicPhraseTimeout, updateMicPhraseTimeout, pendingMicPhraseTimeout } = useStore_MicPhraseTimeout(); + const { currentMicMaxWords, updateMicMaxWords, pendingMicMaxWords } = useStore_MicMaxWords(); + const { currentMicWordFilterList, updateMicWordFilterList, pendingMicWordFilterList } = useStore_MicWordFilterList(); + + // Speaker + const { currentSpeakerRecordTimeout, updateSpeakerRecordTimeout, pendingSpeakerRecordTimeout } = useStore_SpeakerRecordTimeout(); + const { currentSpeakerPhraseTimeout, updateSpeakerPhraseTimeout, pendingSpeakerPhraseTimeout } = useStore_SpeakerPhraseTimeout(); + const { currentSpeakerMaxWords, updateSpeakerMaxWords, pendingSpeakerMaxWords } = useStore_SpeakerMaxWords(); + + // Transcription Engines + const { currentSelectedTranscriptionEngine, updateSelectedTranscriptionEngine, pendingSelectedTranscriptionEngine } = useStore_SelectedTranscriptionEngine(); + const { currentWhisperWeightTypeStatus, updateWhisperWeightTypeStatus, pendingWhisperWeightTypeStatus } = useStore_WhisperWeightTypeStatus(); + const { currentSelectedWhisperWeightType, updateSelectedWhisperWeightType, pendingSelectedWhisperWeightType } = useStore_SelectedWhisperWeightType(); + const { currentSelectableWhisperComputeDeviceList, updateSelectableWhisperComputeDeviceList, pendingSelectableWhisperComputeDeviceList } = useStore_SelectableWhisperComputeDeviceList(); + const { currentSelectedWhisperComputeDevice, updateSelectedWhisperComputeDevice, pendingSelectedWhisperComputeDevice } = useStore_SelectedWhisperComputeDevice(); + + // Mic + const getMicRecordTimeout = () => { + pendingMicRecordTimeout(); + asyncStdoutToPython("/get/data/mic_record_timeout"); + }; + + const setMicRecordTimeout = (selected_mic_record_timeout) => { + pendingMicRecordTimeout(); + asyncStdoutToPython("/set/data/mic_record_timeout", selected_mic_record_timeout); + }; + + const setSuccessMicRecordTimeout = (value) => { + updateMicRecordTimeout(value); + showNotification_SaveSuccess(); + }; + + const getMicPhraseTimeout = () => { + pendingMicPhraseTimeout(); + asyncStdoutToPython("/get/data/mic_phrase_timeout"); + }; + + const setMicPhraseTimeout = (selected_mic_phrase_timeout) => { + pendingMicPhraseTimeout(); + asyncStdoutToPython("/set/data/mic_phrase_timeout", selected_mic_phrase_timeout); + }; + + const setSuccessMicPhraseTimeout = (value) => { + updateMicPhraseTimeout(value); + showNotification_SaveSuccess(); + }; + + const getMicMaxWords = () => { + pendingMicMaxWords(); + asyncStdoutToPython("/get/data/mic_max_phrases"); + }; + + const setMicMaxWords = (selected_mic_max_phrases) => { + pendingMicMaxWords(); + asyncStdoutToPython("/set/data/mic_max_phrases", selected_mic_max_phrases); + }; + + const setSuccessMicMaxWords = (value) => { + updateMicMaxWords(value); + showNotification_SaveSuccess(); + }; + + const getMicWordFilterList = () => { + pendingMicWordFilterList(); + asyncStdoutToPython("/get/data/mic_word_filter"); + }; + + const setMicWordFilterList = (selected_mic_word_filter) => { + pendingMicWordFilterList(); + asyncStdoutToPython("/set/data/mic_word_filter", selected_mic_word_filter); + }; + + const setSuccessMicWordFilterList = (payload) => { + updateMicWordFilterList((prev_list) => { + const updated_list = [...prev_list.data]; + for (const value of payload) { + const existing_item = updated_list.find(item => item.value === value); + if (existing_item) { + existing_item.is_redoable = false; + } else { + updated_list.push({ value, is_redoable: false }); + } + } + return updated_list; + }); + showNotification_SaveSuccess(); + }; + + // Speaker + const getSpeakerRecordTimeout = () => { + pendingSpeakerRecordTimeout(); + asyncStdoutToPython("/get/data/speaker_record_timeout"); + }; + + const setSpeakerRecordTimeout = (selected_speaker_record_timeout) => { + pendingSpeakerRecordTimeout(); + asyncStdoutToPython("/set/data/speaker_record_timeout", selected_speaker_record_timeout); + }; + + const setSuccessSpeakerRecordTimeout = (value) => { + updateSpeakerRecordTimeout(value); + showNotification_SaveSuccess(); + }; + + const getSpeakerPhraseTimeout = () => { + pendingSpeakerPhraseTimeout(); + asyncStdoutToPython("/get/data/speaker_phrase_timeout"); + }; + + const setSpeakerPhraseTimeout = (selected_speaker_phrase_timeout) => { + pendingSpeakerPhraseTimeout(); + asyncStdoutToPython("/set/data/speaker_phrase_timeout", selected_speaker_phrase_timeout); + }; + + const setSuccessSpeakerPhraseTimeout = (value) => { + updateSpeakerPhraseTimeout(value); + showNotification_SaveSuccess(); + }; + + const getSpeakerMaxWords = () => { + pendingSpeakerMaxWords(); + asyncStdoutToPython("/get/data/speaker_max_phrases"); + }; + + const setSpeakerMaxWords = (selected_speaker_max_phrases) => { + pendingSpeakerMaxWords(); + asyncStdoutToPython("/set/data/speaker_max_phrases", selected_speaker_max_phrases); + }; + + const setSuccessSpeakerMaxWords = (value) => { + updateSpeakerMaxWords(value); + showNotification_SaveSuccess(); + }; + + // Transcription Engines + // Transcription Engines (Google / Whisper) + const getSelectedTranscriptionEngine = () => { + pendingSelectedTranscriptionEngine(); + asyncStdoutToPython("/get/data/selected_transcription_engine"); + }; + + const setSelectedTranscriptionEngine = (selected_transcription_engine) => { + pendingSelectedTranscriptionEngine(); + asyncStdoutToPython("/set/data/selected_transcription_engine", selected_transcription_engine); + }; + + const setSuccessSelectedTranscriptionEngine = (engine) => { + updateSelectedTranscriptionEngine(engine); + showNotification_SaveSuccess(); + }; + + // Transcription Engines (Weight Type List) + const updateDownloadedWhisperWeightTypeStatus = (downloaded_weight_type_status) => { + updateWhisperWeightTypeStatus((old_status) => + old_status.data.map((item) => ({ + ...item, + is_downloaded: downloaded_weight_type_status[item.id] ?? item.is_downloaded, + })) + ); + }; + const updateDownloadProgressWhisperWeightTypeStatus = (payload) => { + if (payload === true) return console.error("fix me."); + + updateWhisperWeightTypeStatus((old_status) => + old_status.data.map((item) => + payload.weight_type === item.id + ? { ...item, progress: payload.progress * 100 } + : item + ) + ); + }; + const pendingWhisperWeightType = (id) => { + updateWhisperWeightTypeStatus((old_status) => + old_status.data.map((item) => + id === item.id + ? { ...item, is_pending: true } + : item + ) + ); + }; + const downloadedWhisperWeightType = (id) => { + updateWhisperWeightTypeStatus((old_status) => + old_status.data.map((item) => + id === item.id + ? { ...item, is_downloaded: true, is_pending: false, progress: null } + : item + ) + ); + }; + + const downloadWhisperWeight = (weight_type) => { + asyncStdoutToPython("/run/download_whisper_weight", weight_type); + }; + + // Transcription Engines (Selected Weight Type) + const getSelectedWhisperWeightType = () => { + pendingSelectedWhisperWeightType(); + asyncStdoutToPython("/get/data/whisper_weight_type"); + }; + + const setSelectedWhisperWeightType = (selected_whisper_weight_type) => { + pendingSelectedWhisperWeightType(); + asyncStdoutToPython("/set/data/whisper_weight_type", selected_whisper_weight_type); + }; + + const setSuccessSelectedWhisperWeightType = (wt) => { + updateSelectedWhisperWeightType(wt); + showNotification_SaveSuccess(); + }; + + // Transcription Engines (Compute Device List) + const getSelectableWhisperComputeDeviceList = () => { + pendingSelectableWhisperComputeDeviceList(); + asyncStdoutToPython("/get/data/transcription_compute_device_list"); + }; + + const updateSelectableWhisperComputeDeviceList_FromBackend = (payload) => { + updateSelectableWhisperComputeDeviceList(transformToIndexedArray(payload)); + }; + + // Transcription Engines (Selected Compute Device) + const getSelectedWhisperComputeDevice = () => { + pendingSelectedWhisperComputeDevice(); + asyncStdoutToPython("/get/data/selected_transcription_compute_device"); + }; + + const setSelectedWhisperComputeDevice = (selected_transcription_compute_device) => { + pendingSelectedWhisperComputeDevice(); + asyncStdoutToPython("/set/data/selected_transcription_compute_device", selected_transcription_compute_device); + }; + + const setSuccessSelectedWhisperComputeDevice = (dev) => { + updateSelectedWhisperComputeDevice(dev); + showNotification_SaveSuccess(); + }; + + return { + // Mic + currentMicRecordTimeout, + getMicRecordTimeout, + updateMicRecordTimeout, + setMicRecordTimeout, + setSuccessMicRecordTimeout, + + currentMicPhraseTimeout, + getMicPhraseTimeout, + updateMicPhraseTimeout, + setMicPhraseTimeout, + setSuccessMicPhraseTimeout, + + currentMicMaxWords, + getMicMaxWords, + updateMicMaxWords, + setMicMaxWords, + setSuccessMicMaxWords, + + currentMicWordFilterList, + getMicWordFilterList, + updateMicWordFilterList, + setMicWordFilterList, + setSuccessMicWordFilterList, + + // Speaker + currentSpeakerRecordTimeout, + getSpeakerRecordTimeout, + updateSpeakerRecordTimeout, + setSpeakerRecordTimeout, + setSuccessSpeakerRecordTimeout, + + currentSpeakerPhraseTimeout, + getSpeakerPhraseTimeout, + updateSpeakerPhraseTimeout, + setSpeakerPhraseTimeout, + setSuccessSpeakerPhraseTimeout, + + currentSpeakerMaxWords, + getSpeakerMaxWords, + updateSpeakerMaxWords, + setSpeakerMaxWords, + setSuccessSpeakerMaxWords, + + // Transcription Engines + currentSelectedTranscriptionEngine, + getSelectedTranscriptionEngine, + updateSelectedTranscriptionEngine, + setSelectedTranscriptionEngine, + setSuccessSelectedTranscriptionEngine, + + currentWhisperWeightTypeStatus, + updateWhisperWeightTypeStatus, + updateDownloadedWhisperWeightTypeStatus, + updateDownloadProgressWhisperWeightTypeStatus, + pendingWhisperWeightType, + downloadedWhisperWeightType, + downloadWhisperWeight, + + currentSelectedWhisperWeightType, + getSelectedWhisperWeightType, + updateSelectedWhisperWeightType, + setSelectedWhisperWeightType, + setSuccessSelectedWhisperWeightType, + + currentSelectableWhisperComputeDeviceList, + getSelectableWhisperComputeDeviceList, + updateSelectableWhisperComputeDeviceList, + updateSelectableWhisperComputeDeviceList_FromBackend, + + currentSelectedWhisperComputeDevice, + getSelectedWhisperComputeDevice, + updateSelectedWhisperComputeDevice, + setSelectedWhisperComputeDevice, + setSuccessSelectedWhisperComputeDevice, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/configs/transcription/useWhisperWeightTypeStatus.js b/src-ui/logics/configs/transcription/useWhisperWeightTypeStatus.js deleted file mode 100644 index 482273d2..00000000 --- a/src-ui/logics/configs/transcription/useWhisperWeightTypeStatus.js +++ /dev/null @@ -1,60 +0,0 @@ -import { useStore_WhisperWeightTypeStatus } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useWhisperWeightTypeStatus = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentWhisperWeightTypeStatus, updateWhisperWeightTypeStatus, pendingWhisperWeightTypeStatus } = useStore_WhisperWeightTypeStatus(); - - const updateDownloadedWhisperWeightTypeStatus = (downloaded_weight_type_status) => { - updateWhisperWeightTypeStatus((old_status) => - old_status.data.map((item) => ({ - ...item, - is_downloaded: downloaded_weight_type_status[item.id] ?? item.is_downloaded, - })) - ); - }; - const updateDownloadProgressWhisperWeightTypeStatus = (payload) => { - if (payload === true) return console.error("fix me."); - - updateWhisperWeightTypeStatus((old_status) => - old_status.data.map((item) => - payload.weight_type === item.id - ? { ...item, progress: payload.progress * 100 } - : item - ) - ); - }; - const pendingWhisperWeightType = (id) => { - updateWhisperWeightTypeStatus((old_status) => - old_status.data.map((item) => - id === item.id - ? { ...item, is_pending: true } - : item - ) - ); - }; - const downloadedWhisperWeightType = (id) => { - updateWhisperWeightTypeStatus((old_status) => - old_status.data.map((item) => - id === item.id - ? { ...item, is_downloaded: true, is_pending: false, progress: null } - : item - ) - ); - }; - - const downloadWhisperWeight = (weight_type) => { - asyncStdoutToPython("/run/download_whisper_weight", weight_type); - }; - - return { - currentWhisperWeightTypeStatus, - updateWhisperWeightTypeStatus, - - updateDownloadedWhisperWeightTypeStatus, - updateDownloadProgressWhisperWeightTypeStatus, - pendingWhisperWeightType, - downloadedWhisperWeightType, - downloadWhisperWeight, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/translation/useCTranslate2WeightTypeStatus.js b/src-ui/logics/configs/translation/useCTranslate2WeightTypeStatus.js deleted file mode 100644 index 4f840765..00000000 --- a/src-ui/logics/configs/translation/useCTranslate2WeightTypeStatus.js +++ /dev/null @@ -1,60 +0,0 @@ -import { useStore_CTranslate2WeightTypeStatus } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useCTranslate2WeightTypeStatus = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentCTranslate2WeightTypeStatus, updateCTranslate2WeightTypeStatus, pendingCTranslate2WeightTypeStatus } = useStore_CTranslate2WeightTypeStatus(); - - const updateDownloadedCTranslate2WeightTypeStatus = (downloaded_weight_type_status) => { - updateCTranslate2WeightTypeStatus((old_status) => - old_status.data.map((item) => ({ - ...item, - is_downloaded: downloaded_weight_type_status[item.id] ?? item.is_downloaded, - })) - ); - }; - const updateDownloadProgressCTranslate2WeightTypeStatus = (payload) => { - if (payload === true) return console.error("fix me."); - - updateCTranslate2WeightTypeStatus((old_status) => - old_status.data.map((item) => - payload.weight_type === item.id - ? { ...item, progress: payload.progress * 100 } - : item - ) - ); - }; - const pendingCTranslate2WeightType = (id) => { - updateCTranslate2WeightTypeStatus((old_status) => - old_status.data.map((item) => - id === item.id - ? { ...item, is_pending: true } - : item - ) - ); - }; - const downloadedCTranslate2WeightType = (id) => { - updateCTranslate2WeightTypeStatus((old_status) => - old_status.data.map((item) => - id === item.id - ? { ...item, is_downloaded: true, is_pending: false, progress: null } - : item - ) - ); - }; - - const downloadCTranslate2Weight = (weight_type) => { - asyncStdoutToPython("/run/download_ctranslate2_weight", weight_type); - }; - - return { - currentCTranslate2WeightTypeStatus, - updateCTranslate2WeightTypeStatus, - - updateDownloadedCTranslate2WeightTypeStatus, - updateDownloadProgressCTranslate2WeightTypeStatus, - pendingCTranslate2WeightType, - downloadedCTranslate2WeightType, - downloadCTranslate2Weight, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/translation/useDeepLAuthKey.js b/src-ui/logics/configs/translation/useDeepLAuthKey.js deleted file mode 100644 index a568dfe9..00000000 --- a/src-ui/logics/configs/translation/useDeepLAuthKey.js +++ /dev/null @@ -1,41 +0,0 @@ -import { useStore_DeepLAuthKey } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; -import { useTranslation } from "react-i18next"; -import { useNotificationStatus } from "@logics_common"; - -export const useDeepLAuthKey = () => { - const { t } = useTranslation(); - const { showNotification_Success, showNotification_Error } = useNotificationStatus(); - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentDeepLAuthKey, updateDeepLAuthKey, pendingDeepLAuthKey } = useStore_DeepLAuthKey(); - - const getDeepLAuthKey = () => { - pendingDeepLAuthKey(); - asyncStdoutToPython("/get/data/deepl_auth_key"); - }; - - const setDeepLAuthKey = (selected_deepl_auth_key) => { - pendingDeepLAuthKey(); - asyncStdoutToPython("/set/data/deepl_auth_key", selected_deepl_auth_key); - }; - - const deleteDeepLAuthKey = () => { - pendingDeepLAuthKey(); - asyncStdoutToPython("/delete/data/deepl_auth_key"); - }; - - const savedDeepLAuthKey = (data) => { - updateDeepLAuthKey(data); - showNotification_Success(t("config_page.translation.deepl_auth_key.auth_key_success")); - }; - - return { - currentDeepLAuthKey, - getDeepLAuthKey, - updateDeepLAuthKey, - setDeepLAuthKey, - deleteDeepLAuthKey, - - savedDeepLAuthKey, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/translation/useSelectableCTranslate2ComputeDeviceList.js b/src-ui/logics/configs/translation/useSelectableCTranslate2ComputeDeviceList.js deleted file mode 100644 index e2ca89ca..00000000 --- a/src-ui/logics/configs/translation/useSelectableCTranslate2ComputeDeviceList.js +++ /dev/null @@ -1,18 +0,0 @@ -import { useStore_SelectableCTranslate2ComputeDeviceList } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectableCTranslate2ComputeDeviceList = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectableCTranslate2ComputeDeviceList, updateSelectableCTranslate2ComputeDeviceList, pendingSelectableCTranslate2ComputeDeviceList } = useStore_SelectableCTranslate2ComputeDeviceList(); - - const getSelectableCTranslate2ComputeDeviceList = () => { - pendingSelectableCTranslate2ComputeDeviceList(); - asyncStdoutToPython("/get/data/translation_compute_device_list"); - }; - - return { - currentSelectableCTranslate2ComputeDeviceList, - getSelectableCTranslate2ComputeDeviceList, - updateSelectableCTranslate2ComputeDeviceList, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/translation/useSelectedCTranslate2ComputeDevice.js b/src-ui/logics/configs/translation/useSelectedCTranslate2ComputeDevice.js deleted file mode 100644 index 37f6623d..00000000 --- a/src-ui/logics/configs/translation/useSelectedCTranslate2ComputeDevice.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedCTranslate2ComputeDevice } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedCTranslate2ComputeDevice = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedCTranslate2ComputeDevice, updateSelectedCTranslate2ComputeDevice, pendingSelectedCTranslate2ComputeDevice } = useStore_SelectedCTranslate2ComputeDevice(); - - const getSelectedCTranslate2ComputeDevice = () => { - pendingSelectedCTranslate2ComputeDevice(); - asyncStdoutToPython("/get/data/selected_translation_compute_device"); - }; - - const setSelectedCTranslate2ComputeDevice = (selected_translation_compute_device) => { - pendingSelectedCTranslate2ComputeDevice(); - asyncStdoutToPython("/set/data/selected_translation_compute_device", selected_translation_compute_device); - }; - - return { - currentSelectedCTranslate2ComputeDevice, - getSelectedCTranslate2ComputeDevice, - updateSelectedCTranslate2ComputeDevice, - setSelectedCTranslate2ComputeDevice, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/translation/useSelectedCTranslate2WeightType.js b/src-ui/logics/configs/translation/useSelectedCTranslate2WeightType.js deleted file mode 100644 index 8641a2ac..00000000 --- a/src-ui/logics/configs/translation/useSelectedCTranslate2WeightType.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_SelectedCTranslate2WeightType } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectedCTranslate2WeightType = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectedCTranslate2WeightType, updateSelectedCTranslate2WeightType, pendingSelectedCTranslate2WeightType } = useStore_SelectedCTranslate2WeightType(); - - const getSelectedCTranslate2WeightType = () => { - pendingSelectedCTranslate2WeightType(); - asyncStdoutToPython("/get/data/ctranslate2_weight_type"); - }; - - const setSelectedCTranslate2WeightType = (selected_ctranslate2_weight_type) => { - pendingSelectedCTranslate2WeightType(); - asyncStdoutToPython("/set/data/ctranslate2_weight_type", selected_ctranslate2_weight_type); - }; - - return { - currentSelectedCTranslate2WeightType, - getSelectedCTranslate2WeightType, - updateSelectedCTranslate2WeightType, - setSelectedCTranslate2WeightType, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/translation/useTranslation.js b/src-ui/logics/configs/translation/useTranslation.js new file mode 100644 index 00000000..b282bf90 --- /dev/null +++ b/src-ui/logics/configs/translation/useTranslation.js @@ -0,0 +1,168 @@ +import { + useStore_CTranslate2WeightTypeStatus, + useStore_SelectedCTranslate2WeightType, + useStore_SelectableCTranslate2ComputeDeviceList, + useStore_SelectedCTranslate2ComputeDevice, + useStore_DeepLAuthKey, +} from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { useI18n } from "@useI18n"; +import { transformToIndexedArray } from "@utils"; +import { useNotificationStatus } from "@logics_common"; + +export const useTranslation = () => { + const { t } = useI18n(); + const { asyncStdoutToPython } = useStdoutToPython(); + const { showNotification_SaveSuccess } = useNotificationStatus(); + + const { currentCTranslate2WeightTypeStatus, updateCTranslate2WeightTypeStatus, pendingCTranslate2WeightTypeStatus } = useStore_CTranslate2WeightTypeStatus(); + const { currentSelectedCTranslate2WeightType, updateSelectedCTranslate2WeightType, pendingSelectedCTranslate2WeightType } = useStore_SelectedCTranslate2WeightType(); + const { currentSelectableCTranslate2ComputeDeviceList, updateSelectableCTranslate2ComputeDeviceList, pendingSelectableCTranslate2ComputeDeviceList } = useStore_SelectableCTranslate2ComputeDeviceList(); + const { currentSelectedCTranslate2ComputeDevice, updateSelectedCTranslate2ComputeDevice, pendingSelectedCTranslate2ComputeDevice } = useStore_SelectedCTranslate2ComputeDevice(); + const { currentDeepLAuthKey, updateDeepLAuthKey, pendingDeepLAuthKey } = useStore_DeepLAuthKey(); + + + const updateDownloadedCTranslate2WeightTypeStatus = (downloaded_weight_type_status) => { + updateCTranslate2WeightTypeStatus((old_status) => + old_status.data.map((item) => ({ + ...item, + is_downloaded: downloaded_weight_type_status[item.id] ?? item.is_downloaded, + })) + ); + }; + const updateDownloadProgressCTranslate2WeightTypeStatus = (payload) => { + if (payload === true) return console.error("fix me."); + + updateCTranslate2WeightTypeStatus((old_status) => + old_status.data.map((item) => + payload.weight_type === item.id + ? { ...item, progress: payload.progress * 100 } + : item + ) + ); + }; + const pendingCTranslate2WeightType = (id) => { + updateCTranslate2WeightTypeStatus((old_status) => + old_status.data.map((item) => + id === item.id + ? { ...item, is_pending: true } + : item + ) + ); + }; + const downloadedCTranslate2WeightType = (id) => { + updateCTranslate2WeightTypeStatus((old_status) => + old_status.data.map((item) => + id === item.id + ? { ...item, is_downloaded: true, is_pending: false, progress: null } + : item + ) + ); + }; + const downloadCTranslate2Weight = (weight_type) => { + asyncStdoutToPython("/run/download_ctranslate2_weight", weight_type); + }; + + + const getSelectedCTranslate2WeightType = () => { + pendingSelectedCTranslate2WeightType(); + asyncStdoutToPython("/get/data/ctranslate2_weight_type"); + }; + + const setSelectedCTranslate2WeightType = (selected_ctranslate2_weight_type) => { + pendingSelectedCTranslate2WeightType(); + asyncStdoutToPython("/set/data/ctranslate2_weight_type", selected_ctranslate2_weight_type); + }; + + const setSuccessSelectedCTranslate2WeightType = (selected_ctranslate2_weight_type) => { + updateSelectedCTranslate2WeightType(selected_ctranslate2_weight_type); + showNotification_SaveSuccess(); + }; + + + const getSelectableCTranslate2ComputeDeviceList = () => { + pendingSelectableCTranslate2ComputeDeviceList(); + asyncStdoutToPython("/get/data/translation_compute_device_list"); + }; + + const updateSelectableCTranslate2ComputeDeviceList_FromBackend = (payload) => { + updateSelectableCTranslate2ComputeDeviceList(transformToIndexedArray(payload)); + }; + + + const getSelectedCTranslate2ComputeDevice = () => { + pendingSelectedCTranslate2ComputeDevice(); + asyncStdoutToPython("/get/data/selected_translation_compute_device"); + }; + + const setSelectedCTranslate2ComputeDevice = (selected_translation_compute_device) => { + pendingSelectedCTranslate2ComputeDevice(); + asyncStdoutToPython("/set/data/selected_translation_compute_device", selected_translation_compute_device); + }; + + const setSuccessSelectedCTranslate2ComputeDevice = (selected_translation_compute_device) => { + updateSelectedCTranslate2ComputeDevice(selected_translation_compute_device); + showNotification_SaveSuccess(); + }; + + + const getDeepLAuthKey = () => { + pendingDeepLAuthKey(); + asyncStdoutToPython("/get/data/deepl_auth_key"); + }; + + const setDeepLAuthKey = (selected_deepl_auth_key) => { + pendingDeepLAuthKey(); + asyncStdoutToPython("/set/data/deepl_auth_key", selected_deepl_auth_key); + }; + + const setSuccessDeepLAuthKey = (data) => { + updateDeepLAuthKey(data); + showNotification_SaveSuccess(t("config_page.translation.deepl_auth_key.auth_key_success"), { category_id: "deepl_auth_key" }); + }; + + const deleteDeepLAuthKey = () => { + pendingDeepLAuthKey(); + asyncStdoutToPython("/delete/data/deepl_auth_key"); + }; + + const deleteSuccessDeepLAuthKey = () => { + updateDeepLAuthKey(""); + }; + + + return { + currentCTranslate2WeightTypeStatus, + updateCTranslate2WeightTypeStatus, + updateDownloadedCTranslate2WeightTypeStatus, + updateDownloadProgressCTranslate2WeightTypeStatus, + pendingCTranslate2WeightType, + downloadedCTranslate2WeightType, + downloadCTranslate2Weight, + + currentSelectedCTranslate2WeightType, + getSelectedCTranslate2WeightType, + updateSelectedCTranslate2WeightType, + setSelectedCTranslate2WeightType, + setSuccessSelectedCTranslate2WeightType, + + currentSelectableCTranslate2ComputeDeviceList, + getSelectableCTranslate2ComputeDeviceList, + updateSelectableCTranslate2ComputeDeviceList, + updateSelectableCTranslate2ComputeDeviceList_FromBackend, + + currentSelectedCTranslate2ComputeDevice, + getSelectedCTranslate2ComputeDevice, + updateSelectedCTranslate2ComputeDevice, + setSelectedCTranslate2ComputeDevice, + setSuccessSelectedCTranslate2ComputeDevice, + + currentDeepLAuthKey, + getDeepLAuthKey, + updateDeepLAuthKey, + setDeepLAuthKey, + deleteDeepLAuthKey, + deleteSuccessDeepLAuthKey, + setSuccessDeepLAuthKey, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/configs/vr/useIsEnabledOverlayLargeLog.js b/src-ui/logics/configs/vr/useIsEnabledOverlayLargeLog.js deleted file mode 100644 index 0e1f8881..00000000 --- a/src-ui/logics/configs/vr/useIsEnabledOverlayLargeLog.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_IsEnabledOverlayLargeLog } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useIsEnabledOverlayLargeLog = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentIsEnabledOverlayLargeLog, updateIsEnabledOverlayLargeLog, pendingIsEnabledOverlayLargeLog } = useStore_IsEnabledOverlayLargeLog(); - - const getIsEnabledOverlayLargeLog = () => { - pendingIsEnabledOverlayLargeLog(); - asyncStdoutToPython("/get/data/overlay_large_log"); - }; - - const toggleIsEnabledOverlayLargeLog = () => { - pendingIsEnabledOverlayLargeLog(); - if (currentIsEnabledOverlayLargeLog.data) { - asyncStdoutToPython("/set/disable/overlay_large_log"); - } else { - asyncStdoutToPython("/set/enable/overlay_large_log"); - } - }; - - return { - currentIsEnabledOverlayLargeLog, - getIsEnabledOverlayLargeLog, - updateIsEnabledOverlayLargeLog, - toggleIsEnabledOverlayLargeLog, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/vr/useIsEnabledOverlaySmallLog.js b/src-ui/logics/configs/vr/useIsEnabledOverlaySmallLog.js deleted file mode 100644 index e51a34c3..00000000 --- a/src-ui/logics/configs/vr/useIsEnabledOverlaySmallLog.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_IsEnabledOverlaySmallLog } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useIsEnabledOverlaySmallLog = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentIsEnabledOverlaySmallLog, updateIsEnabledOverlaySmallLog, pendingIsEnabledOverlaySmallLog } = useStore_IsEnabledOverlaySmallLog(); - - const getIsEnabledOverlaySmallLog = () => { - pendingIsEnabledOverlaySmallLog(); - asyncStdoutToPython("/get/data/overlay_small_log"); - }; - - const toggleIsEnabledOverlaySmallLog = () => { - pendingIsEnabledOverlaySmallLog(); - if (currentIsEnabledOverlaySmallLog.data) { - asyncStdoutToPython("/set/disable/overlay_small_log"); - } else { - asyncStdoutToPython("/set/enable/overlay_small_log"); - } - }; - - return { - currentIsEnabledOverlaySmallLog, - getIsEnabledOverlaySmallLog, - updateIsEnabledOverlaySmallLog, - toggleIsEnabledOverlaySmallLog, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/vr/useOverlayLargeLogSettings.js b/src-ui/logics/configs/vr/useOverlayLargeLogSettings.js deleted file mode 100644 index 548189e3..00000000 --- a/src-ui/logics/configs/vr/useOverlayLargeLogSettings.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_OverlayLargeLogSettings } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useOverlayLargeLogSettings = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentOverlayLargeLogSettings, updateOverlayLargeLogSettings, pendingOverlayLargeLogSettings } = useStore_OverlayLargeLogSettings(); - - const getOverlayLargeLogSettings = () => { - // pendingOverlayLargeLogSettings(); - asyncStdoutToPython("/get/data/overlay_large_log_settings"); - }; - - const setOverlayLargeLogSettings = (overlay_large_log_settings) => { - // pendingOverlayLargeLogSettings(); - asyncStdoutToPython("/set/data/overlay_large_log_settings", overlay_large_log_settings); - }; - - return { - currentOverlayLargeLogSettings, - getOverlayLargeLogSettings, - updateOverlayLargeLogSettings, - setOverlayLargeLogSettings, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/vr/useOverlayShowOnlyTranslatedMessages.js b/src-ui/logics/configs/vr/useOverlayShowOnlyTranslatedMessages.js deleted file mode 100644 index 895581ae..00000000 --- a/src-ui/logics/configs/vr/useOverlayShowOnlyTranslatedMessages.js +++ /dev/null @@ -1,28 +0,0 @@ -import { useStore_OverlayShowOnlyTranslatedMessages } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useOverlayShowOnlyTranslatedMessages = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentOverlayShowOnlyTranslatedMessages, updateOverlayShowOnlyTranslatedMessages, pendingOverlayShowOnlyTranslatedMessages } = useStore_OverlayShowOnlyTranslatedMessages(); - - const getOverlayShowOnlyTranslatedMessages = () => { - pendingOverlayShowOnlyTranslatedMessages(); - asyncStdoutToPython("/get/data/overlay_show_only_translated_messages"); - }; - - const toggleOverlayShowOnlyTranslatedMessages = () => { - pendingOverlayShowOnlyTranslatedMessages(); - if (currentOverlayShowOnlyTranslatedMessages.data) { - asyncStdoutToPython("/set/disable/overlay_show_only_translated_messages"); - } else { - asyncStdoutToPython("/set/enable/overlay_show_only_translated_messages"); - } - }; - - return { - currentOverlayShowOnlyTranslatedMessages, - getOverlayShowOnlyTranslatedMessages, - updateOverlayShowOnlyTranslatedMessages, - toggleOverlayShowOnlyTranslatedMessages, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/vr/useOverlaySmallLogSettings.js b/src-ui/logics/configs/vr/useOverlaySmallLogSettings.js deleted file mode 100644 index 03b61393..00000000 --- a/src-ui/logics/configs/vr/useOverlaySmallLogSettings.js +++ /dev/null @@ -1,24 +0,0 @@ -import { useStore_OverlaySmallLogSettings } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useOverlaySmallLogSettings = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentOverlaySmallLogSettings, updateOverlaySmallLogSettings, pendingOverlaySmallLogSettings } = useStore_OverlaySmallLogSettings(); - - const getOverlaySmallLogSettings = () => { - // pendingOverlaySmallLogSettings(); - asyncStdoutToPython("/get/data/overlay_small_log_settings"); - }; - - const setOverlaySmallLogSettings = (overlay_small_log_settings) => { - // pendingOverlaySmallLogSettings(); - asyncStdoutToPython("/set/data/overlay_small_log_settings", overlay_small_log_settings); - }; - - return { - currentOverlaySmallLogSettings, - getOverlaySmallLogSettings, - updateOverlaySmallLogSettings, - setOverlaySmallLogSettings, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/vr/useSendTextToOverlay.js b/src-ui/logics/configs/vr/useSendTextToOverlay.js deleted file mode 100644 index 268881ec..00000000 --- a/src-ui/logics/configs/vr/useSendTextToOverlay.js +++ /dev/null @@ -1,13 +0,0 @@ -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSendTextToOverlay = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - - const sendTextToOverlay = (text) => { - asyncStdoutToPython("/run/send_text_overlay", text); - }; - - return { - sendTextToOverlay, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/configs/vr/useVr.js b/src-ui/logics/configs/vr/useVr.js new file mode 100644 index 00000000..ee65c538 --- /dev/null +++ b/src-ui/logics/configs/vr/useVr.js @@ -0,0 +1,145 @@ +import { + useStore_IsEnabledOverlaySmallLog, + useStore_IsEnabledOverlayLargeLog, + useStore_OverlaySmallLogSettings, + useStore_OverlayLargeLogSettings, + useStore_OverlayShowOnlyTranslatedMessages, +} from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { useNotificationStatus } from "@logics_common"; + +export const useVr = () => { + const { asyncStdoutToPython } = useStdoutToPython(); + const { showNotification_SaveSuccess } = useNotificationStatus(); + + const { currentIsEnabledOverlaySmallLog, updateIsEnabledOverlaySmallLog, pendingIsEnabledOverlaySmallLog } = useStore_IsEnabledOverlaySmallLog(); + const { currentIsEnabledOverlayLargeLog, updateIsEnabledOverlayLargeLog, pendingIsEnabledOverlayLargeLog } = useStore_IsEnabledOverlayLargeLog(); + const { currentOverlaySmallLogSettings, updateOverlaySmallLogSettings, pendingOverlaySmallLogSettings } = useStore_OverlaySmallLogSettings(); + const { currentOverlayLargeLogSettings, updateOverlayLargeLogSettings, pendingOverlayLargeLogSettings } = useStore_OverlayLargeLogSettings(); + const { currentOverlayShowOnlyTranslatedMessages, updateOverlayShowOnlyTranslatedMessages, pendingOverlayShowOnlyTranslatedMessages } = useStore_OverlayShowOnlyTranslatedMessages(); + + const getIsEnabledOverlaySmallLog = () => { + pendingIsEnabledOverlaySmallLog(); + asyncStdoutToPython("/get/data/overlay_small_log"); + }; + + const toggleIsEnabledOverlaySmallLog = () => { + pendingIsEnabledOverlaySmallLog(); + if (currentIsEnabledOverlaySmallLog.data) { + asyncStdoutToPython("/set/disable/overlay_small_log"); + } else { + asyncStdoutToPython("/set/enable/overlay_small_log"); + } + }; + + const setSuccessIsEnabledOverlaySmallLog = (enabled) => { + updateIsEnabledOverlaySmallLog(enabled); + showNotification_SaveSuccess(); + }; + + const getIsEnabledOverlayLargeLog = () => { + pendingIsEnabledOverlayLargeLog(); + asyncStdoutToPython("/get/data/overlay_large_log"); + }; + + const toggleIsEnabledOverlayLargeLog = () => { + pendingIsEnabledOverlayLargeLog(); + if (currentIsEnabledOverlayLargeLog.data) { + asyncStdoutToPython("/set/disable/overlay_large_log"); + } else { + asyncStdoutToPython("/set/enable/overlay_large_log"); + } + }; + + const setSuccessIsEnabledOverlayLargeLog = (enabled) => { + updateIsEnabledOverlayLargeLog(enabled); + showNotification_SaveSuccess(); + }; + + const getOverlaySmallLogSettings = () => { + // pendingOverlaySmallLogSettings(); + asyncStdoutToPython("/get/data/overlay_small_log_settings"); + }; + + const setOverlaySmallLogSettings = (overlay_small_log_settings) => { + // pendingOverlaySmallLogSettings(); + asyncStdoutToPython("/set/data/overlay_small_log_settings", overlay_small_log_settings); + }; + + const setSuccessOverlaySmallLogSettings = (settings) => { + updateOverlaySmallLogSettings(settings); + showNotification_SaveSuccess(); + }; + + const getOverlayLargeLogSettings = () => { + // pendingOverlayLargeLogSettings(); + asyncStdoutToPython("/get/data/overlay_large_log_settings"); + }; + + const setOverlayLargeLogSettings = (overlay_large_log_settings) => { + // pendingOverlayLargeLogSettings(); + asyncStdoutToPython("/set/data/overlay_large_log_settings", overlay_large_log_settings); + }; + + const setSuccessOverlayLargeLogSettings = (settings) => { + updateOverlayLargeLogSettings(settings); + showNotification_SaveSuccess(); + }; + + const getOverlayShowOnlyTranslatedMessages = () => { + pendingOverlayShowOnlyTranslatedMessages(); + asyncStdoutToPython("/get/data/overlay_show_only_translated_messages"); + }; + + const toggleOverlayShowOnlyTranslatedMessages = () => { + pendingOverlayShowOnlyTranslatedMessages(); + if (currentOverlayShowOnlyTranslatedMessages.data) { + asyncStdoutToPython("/set/disable/overlay_show_only_translated_messages"); + } else { + asyncStdoutToPython("/set/enable/overlay_show_only_translated_messages"); + } + }; + + const setSuccessOverlayShowOnlyTranslatedMessages = (enabled) => { + updateOverlayShowOnlyTranslatedMessages(enabled); + showNotification_SaveSuccess(); + }; + + const sendTextToOverlay = (text) => { + asyncStdoutToPython("/run/send_text_overlay", text); + }; + + return { + currentIsEnabledOverlaySmallLog, + getIsEnabledOverlaySmallLog, + toggleIsEnabledOverlaySmallLog, + updateIsEnabledOverlaySmallLog, + setSuccessIsEnabledOverlaySmallLog, + + currentIsEnabledOverlayLargeLog, + getIsEnabledOverlayLargeLog, + toggleIsEnabledOverlayLargeLog, + updateIsEnabledOverlayLargeLog, + setSuccessIsEnabledOverlayLargeLog, + + currentOverlaySmallLogSettings, + getOverlaySmallLogSettings, + updateOverlaySmallLogSettings, + setOverlaySmallLogSettings, + setSuccessOverlaySmallLogSettings, + + currentOverlayLargeLogSettings, + getOverlayLargeLogSettings, + updateOverlayLargeLogSettings, + setOverlayLargeLogSettings, + setSuccessOverlayLargeLogSettings, + + currentOverlayShowOnlyTranslatedMessages, + getOverlayShowOnlyTranslatedMessages, + toggleOverlayShowOnlyTranslatedMessages, + updateOverlayShowOnlyTranslatedMessages, + setSuccessOverlayShowOnlyTranslatedMessages, + + sendTextToOverlay, + }; +}; \ No newline at end of file diff --git a/src-ui/logics/main/index.js b/src-ui/logics/main/index.js index 7cd492d6..827e8cef 100644 --- a/src-ui/logics/main/index.js +++ b/src-ui/logics/main/index.js @@ -1,7 +1,5 @@ -export { useIsVisibleResendButton } from "./useIsVisibleResendButton"; export { useIsMainPageCompactMode } from "./useIsMainPageCompactMode"; export { useLanguageSettings } from "./useLanguageSettings"; export { useMainFunction } from "./useMainFunction"; export { useMessageLogScroll } from "./useMessageLogScroll"; -export { useMessageInputBoxRatio } from "./useMessageInputBoxRatio"; -export { useSelectableLanguageList } from "./useSelectableLanguageList"; \ No newline at end of file +export { useMessageInputBoxRatio } from "./useMessageInputBoxRatio"; \ No newline at end of file diff --git a/src-ui/logics/main/useIsMainPageCompactMode.js b/src-ui/logics/main/useIsMainPageCompactMode.js index 9a883c51..a1c7110f 100644 --- a/src-ui/logics/main/useIsMainPageCompactMode.js +++ b/src-ui/logics/main/useIsMainPageCompactMode.js @@ -1,5 +1,5 @@ import { useStore_IsMainPageCompactMode } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; export const useIsMainPageCompactMode = () => { const { asyncStdoutToPython } = useStdoutToPython(); diff --git a/src-ui/logics/main/useIsVisibleResendButton.js b/src-ui/logics/main/useIsVisibleResendButton.js deleted file mode 100644 index c479af0b..00000000 --- a/src-ui/logics/main/useIsVisibleResendButton.js +++ /dev/null @@ -1,15 +0,0 @@ -import { useStore_IsVisibleResendButton } from "@store"; - -export const useIsVisibleResendButton = () => { - const { currentIsVisibleResendButton, updateIsVisibleResendButton } = useStore_IsVisibleResendButton(); - - const toggleIsVisibleResendButton = () => { - updateIsVisibleResendButton(!currentIsVisibleResendButton.data); - }; - - return { - currentIsVisibleResendButton, - toggleIsVisibleResendButton, - updateIsVisibleResendButton, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/main/useLanguageSettings.js b/src-ui/logics/main/useLanguageSettings.js index 163f9f37..aad7ae15 100644 --- a/src-ui/logics/main/useLanguageSettings.js +++ b/src-ui/logics/main/useLanguageSettings.js @@ -1,13 +1,10 @@ -import { useStore_SelectedPresetTabNumber, useStore_EnableMultiTranslation, useStore_SelectedYourLanguages, useStore_SelectedTargetLanguages, useStore_TranslationEngines, useStore_SelectedTranslationEngines } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStore_SelectedPresetTabNumber, useStore_SelectedYourLanguages, useStore_SelectedTargetLanguages, useStore_TranslationEngines, useStore_SelectedTranslationEngines, useStore_SelectableLanguageList } from "@store"; +import { useStdoutToPython } from "@useStdoutToPython"; +import { translator_status } from "@ui_configs"; export const useLanguageSettings = () => { const { asyncStdoutToPython } = useStdoutToPython(); - const { - currentEnableMultiTranslation, - updateEnableMultiTranslation, - pendingEnableMultiTranslation, - } = useStore_EnableMultiTranslation(); + const { currentSelectedYourLanguages, updateSelectedYourLanguages, @@ -34,10 +31,11 @@ export const useLanguageSettings = () => { pendingSelectedTranslationEngines, } = useStore_SelectedTranslationEngines(); - const getEnableMultiTranslation = () => { - pendingEnableMultiTranslation(); - asyncStdoutToPython("/get/data/multi_language_translation"); - }; + const { + currentSelectableLanguageList, + updateSelectableLanguageList, + } = useStore_SelectableLanguageList(); + const getSelectedPresetTabNumber = () => { pendingSelectedPresetTabNumber(); @@ -112,6 +110,16 @@ export const useLanguageSettings = () => { asyncStdoutToPython("/get/data/translation_engines"); }; + const updateTranslatorAvailability = (payload) => { + const keys = payload; + const updated_list = translator_status.map(translator => ({ + ...translator, + is_available: keys.includes(translator.id), + })); + updateTranslationEngines(updated_list); + }; + + const getSelectedTranslationEngines = () => { pendingSelectedTranslationEngines(); asyncStdoutToPython("/get/data/selected_translation_engines"); @@ -124,12 +132,22 @@ export const useLanguageSettings = () => { asyncStdoutToPython("/set/data/selected_translation_engines", send_obj); }; - const runLanguageSwap = () => { + const swapSelectedLanguages = () => { pendingSelectedYourLanguages(); pendingSelectedTargetLanguages(); asyncStdoutToPython("/run/swap_your_language_and_target_language"); }; + const updateBothSelectedLanguages = (payload) => { + updateSelectedYourLanguages(payload.your); + updateSelectedTargetLanguages(payload.target); + }; + + + const getSelectableLanguageList = () => { + asyncStdoutToPython("/get/data/selectable_language_list"); + }; + return { currentSelectedPresetTabNumber, @@ -137,11 +155,6 @@ export const useLanguageSettings = () => { updateSelectedPresetTabNumber, setSelectedPresetTabNumber, - currentEnableMultiTranslation, - getEnableMultiTranslation, - updateEnableMultiTranslation, - // setEnableMultiTranslation, - currentSelectedYourLanguages, getSelectedYourLanguages, updateSelectedYourLanguages, @@ -158,12 +171,18 @@ export const useLanguageSettings = () => { currentTranslationEngines, getTranslationEngines, updateTranslationEngines, + updateTranslatorAvailability, currentSelectedTranslationEngines, getSelectedTranslationEngines, updateSelectedTranslationEngines, setSelectedTranslationEngines, - runLanguageSwap, + swapSelectedLanguages, + updateBothSelectedLanguages, + + currentSelectableLanguageList, + getSelectableLanguageList, + updateSelectableLanguageList, }; }; \ No newline at end of file diff --git a/src-ui/logics/main/useMainFunction.js b/src-ui/logics/main/useMainFunction.js index 05be0662..334ef643 100644 --- a/src-ui/logics/main/useMainFunction.js +++ b/src-ui/logics/main/useMainFunction.js @@ -6,7 +6,7 @@ import { useStore_TranscriptionReceiveStatus, useStore_ForegroundStatus, } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; export const useMainFunction = () => { const appWindow = store.appWindow; diff --git a/src-ui/logics/main/useMessageInputBoxRatio.js b/src-ui/logics/main/useMessageInputBoxRatio.js index b8f8430c..173219d6 100644 --- a/src-ui/logics/main/useMessageInputBoxRatio.js +++ b/src-ui/logics/main/useMessageInputBoxRatio.js @@ -1,6 +1,6 @@ import { store } from "@store"; import { useStore_MessageInputBoxRatio } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; +import { useStdoutToPython } from "@useStdoutToPython"; import { clampMinMax } from "@utils"; export const useMessageInputBoxRatio = () => { const appWindow = store.appWindow; diff --git a/src-ui/logics/main/useSelectableLanguageList.js b/src-ui/logics/main/useSelectableLanguageList.js deleted file mode 100644 index ef771d7f..00000000 --- a/src-ui/logics/main/useSelectableLanguageList.js +++ /dev/null @@ -1,17 +0,0 @@ -import { useStore_SelectableLanguageList } from "@store"; -import { useStdoutToPython } from "@logics/useStdoutToPython"; - -export const useSelectableLanguageList = () => { - const { asyncStdoutToPython } = useStdoutToPython(); - const { currentSelectableLanguageList, updateSelectableLanguageList } = useStore_SelectableLanguageList(); - - const getSelectableLanguageList = () => { - asyncStdoutToPython("/get/data/selectable_language_list"); - }; - - return { - currentSelectableLanguageList, - getSelectableLanguageList, - updateSelectableLanguageList, - }; -}; \ No newline at end of file diff --git a/src-ui/logics/useReceiveRoutes.js b/src-ui/logics/useReceiveRoutes.js index b1d3421b..d83054d3 100644 --- a/src-ui/logics/useReceiveRoutes.js +++ b/src-ui/logics/useReceiveRoutes.js @@ -1,572 +1,364 @@ -import { translator_status } from "@ui_configs"; -import { arrayToObject } from "@utils"; - +import * as common from "@logics_common"; +import * as main from "@logics_main"; +import * as configs from "@logics_configs"; import { _useBackendErrorHandling } from "./_useBackendErrorHandling"; -import { - useIsVrctAvailable, - useNotificationStatus, - useHandleNetworkConnection, - useHandleOscQuery, +export const ROUTE_META_LIST = [ + // Common + { endpoint: "/run/feed_watchdog", ns: null, hook_name: null, method_name: null }, + { endpoint: "/run/initialization_progress", ns: common, hook_name: "useInitProgress", method_name: "updateInitProgress" }, + { endpoint: "/run/enable_ai_models", ns: common, hook_name: "useIsVrctAvailable", method_name: "handleAiModelsAvailability" }, + { endpoint: "/get/data/compute_mode", ns: common, hook_name: "useComputeMode", method_name: "updateComputeMode" }, - useSoftwareVersion, - useComputeMode, - useInitProgress, - useIsBackendReady, - useWindow, - useMessage, - useVolume, -} from "@logics_common"; + { endpoint: "/run/update_software", ns: null, hook_name: null, method_name: null }, + { endpoint: "/run/update_cuda_software", ns: null, hook_name: null, method_name: null }, -import { - useMainFunction, - useSelectableLanguageList, - useLanguageSettings, - useIsMainPageCompactMode, - useMessageInputBoxRatio, -} from "@logics_main"; + { endpoint: "/get/data/main_window_geometry", ns: common, hook_name: "useWindow", method_name: "restoreWindowGeometry" }, + { endpoint: "/set/data/main_window_geometry", ns: null, hook_name: null, method_name: null }, -import { - useEnableAutoMicSelect, - useEnableAutoSpeakerSelect, - useMicHostList, - useSelectedMicHost, - useMicDeviceList, - useSelectedMicDevice, - useSpeakerDeviceList, - useSelectedSpeakerDevice, - useMicThreshold, - useSpeakerThreshold, - useEnableAutoClearMessageInputBox, - useEnableSendOnlyTranslatedMessages, - useEnableAutoExportMessageLogs, - useEnableVrcMicMuteSync, - useEnableSendMessageToVrc, - useEnableSendReceivedMessageToVrc, - useSelectedFontFamily, - useUiLanguage, - useUiScaling, - useMessageLogUiScaling, - useSendMessageButtonType, - useTransparency, - useMicRecordTimeout, - useMicPhraseTimeout, - useMicMaxWords, - useMicWordFilterList, - useSpeakerRecordTimeout, - useSpeakerPhraseTimeout, - useSpeakerMaxWords, - useDeepLAuthKey, - useCTranslate2WeightTypeStatus, - useSelectableCTranslate2ComputeDeviceList, - useSelectedCTranslate2ComputeDevice, - useSelectableWhisperComputeDeviceList, - useSelectedWhisperComputeDevice, - useSelectedCTranslate2WeightType, - useSelectedTranscriptionEngine, - useSelectedWhisperWeightType, - useWhisperWeightTypeStatus, - useIsEnabledOverlaySmallLog, - useOverlaySmallLogSettings, - useIsEnabledOverlayLargeLog, - useOverlayLargeLogSettings, - useOverlayShowOnlyTranslatedMessages, - useEnableNotificationVrcSfx, - useHotkeys, - usePlugins, - useOscIpAddress, - useOscPort, - useWebsocket, -} from "@logics_configs"; + { endpoint: "/run/open_filepath_logs", ns: common, hook_name: "useOpenFolder", method_name: "openedFolder_MessageLogs" }, + { endpoint: "/run/open_filepath_config_file", ns: common, hook_name: "useOpenFolder", method_name: "openedFolder_ConfigFile" }, + + // Software Version + { endpoint: "/get/data/version", ns: common, hook_name: "useSoftwareVersion", method_name: "updateSoftwareVersion" }, + // Latest Software Version Info + { endpoint: "/run/software_update_info", ns: common, hook_name: "useSoftwareVersion", method_name: "updateSoftwareVersionInfo" }, + + { endpoint: "/run/connected_network", ns: common, hook_name: "useHandleNetworkConnection", method_name: "handleNetworkConnection" }, + { endpoint: "/run/enable_osc_query", ns: common, hook_name: "useHandleOscQuery", method_name: "handleOscQuery" }, + + // Message (By typing) + { endpoint: "/run/send_message_box", ns: common, hook_name: "useMessage", method_name: "updateSentMessageLogById" }, + { endpoint: "/run/typing_message_box", ns: null, hook_name: null, method_name: null }, + { endpoint: "/run/stop_typing_message_box", ns: null, hook_name: null, method_name: null }, + // Message Transcription + { endpoint: "/run/transcription_send_mic_message", ns: common, hook_name: "useMessage", method_name: "addSentMessageLog" }, + { endpoint: "/run/transcription_receive_speaker_message", ns: common, hook_name: "useMessage", method_name: "addReceivedMessageLog" }, + + // System Messages + { endpoint: "/run/word_filter", ns: common, hook_name: "useMessage", method_name: "addSystemMessageLog_FromBackend" }, + + + // Volume + { endpoint: "/run/check_mic_volume", ns: common, hook_name: "useVolume", method_name: "updateVolumeVariable_Mic" }, + { endpoint: "/run/check_speaker_volume", ns: common, hook_name: "useVolume", method_name: "updateVolumeVariable_Speaker" }, + { endpoint: "/set/enable/check_mic_threshold", ns: common, hook_name: "useVolume", method_name: "updateMicThresholdCheckStatus" }, + { endpoint: "/set/disable/check_mic_threshold", ns: common, hook_name: "useVolume", method_name: "updateMicThresholdCheckStatus" }, + { endpoint: "/set/enable/check_speaker_threshold", ns: common, hook_name: "useVolume", method_name: "updateSpeakerThresholdCheckStatus" }, + { endpoint: "/set/disable/check_speaker_threshold", ns: common, hook_name: "useVolume", method_name: "updateSpeakerThresholdCheckStatus" }, + + + + + // Main Page + // Page Controls + { endpoint: "/get/data/main_window_sidebar_compact_mode", ns: main, hook_name: "useIsMainPageCompactMode", method_name: "updateIsMainPageCompactMode" }, + { endpoint: "/set/enable/main_window_sidebar_compact_mode", ns: main, hook_name: "useIsMainPageCompactMode", method_name: "updateIsMainPageCompactMode" }, + { endpoint: "/set/disable/main_window_sidebar_compact_mode", ns: main, hook_name: "useIsMainPageCompactMode", method_name: "updateIsMainPageCompactMode" }, + + // Main Functions + { endpoint: "/set/enable/translation", ns: main, hook_name: "useMainFunction", method_name: "updateTranslationStatus" }, + { endpoint: "/set/disable/translation", ns: main, hook_name: "useMainFunction", method_name: "updateTranslationStatus" }, + { endpoint: "/set/enable/transcription_send", ns: main, hook_name: "useMainFunction", method_name: "updateTranscriptionSendStatus" }, + { endpoint: "/set/disable/transcription_send", ns: main, hook_name: "useMainFunction", method_name: "updateTranscriptionSendStatus" }, + { endpoint: "/set/enable/transcription_receive", ns: main, hook_name: "useMainFunction", method_name: "updateTranscriptionReceiveStatus" }, + { endpoint: "/set/disable/transcription_receive", ns: main, hook_name: "useMainFunction", method_name: "updateTranscriptionReceiveStatus" }, + + // Language Settings + { endpoint: "/get/data/selected_tab_no", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedPresetTabNumber" }, + { endpoint: "/set/data/selected_tab_no", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedPresetTabNumber" }, + + { endpoint: "/get/data/selected_your_languages", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedYourLanguages" }, + { endpoint: "/set/data/selected_your_languages", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedYourLanguages" }, + { endpoint: "/get/data/selected_target_languages", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedTargetLanguages" }, + { endpoint: "/set/data/selected_target_languages", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedTargetLanguages" }, + + { endpoint: "/get/data/translation_engines", ns: main, hook_name: "useLanguageSettings", method_name: "updateTranslatorAvailability" }, + { endpoint: "/run/translation_engines", ns: main, hook_name: "useLanguageSettings", method_name: "updateTranslatorAvailability" }, + + { endpoint: "/get/data/selected_translation_engines", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedTranslationEngines" }, + { endpoint: "/set/data/selected_translation_engines", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedTranslationEngines" }, + { endpoint: "/run/selected_translation_engines", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectedTranslationEngines" }, + + { endpoint: "/run/swap_your_language_and_target_language", ns: main, hook_name: "useLanguageSettings", method_name: "updateBothSelectedLanguages" }, + + // Language Selector + { endpoint: "/get/data/selectable_language_list", ns: main, hook_name: "useLanguageSettings", method_name: "updateSelectableLanguageList" }, + + + // Message Input Box + { endpoint: "/get/data/message_box_ratio", ns: main, hook_name: "useMessageInputBoxRatio", method_name: "updateMessageInputBoxRatio" }, + { endpoint: "/set/data/message_box_ratio", ns: main, hook_name: "useMessageInputBoxRatio", method_name: "updateMessageInputBoxRatio" }, + + + + // Config Page + // Device + { endpoint: "/get/data/auto_mic_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoMicSelect" }, + { endpoint: "/set/enable/auto_mic_select", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutoMicSelect" }, + { endpoint: "/set/disable/auto_mic_select", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutoMicSelect" }, + { endpoint: "/get/data/auto_speaker_select", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutoSpeakerSelect" }, + { endpoint: "/set/enable/auto_speaker_select", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutoSpeakerSelect" }, + { endpoint: "/set/disable/auto_speaker_select", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutoSpeakerSelect" }, + + // Device (Mic) + { endpoint: "/get/data/mic_host_list", ns: configs, hook_name: "useDevice", method_name: "updateMicHostList_FromBackend" }, + { endpoint: "/run/mic_host_list", ns: configs, hook_name: "useDevice", method_name: "updateMicHostList_FromBackend" }, + + { endpoint: "/get/data/selected_mic_host", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicHost" }, + { endpoint: "/set/data/selected_mic_host", ns: configs, hook_name: "useDevice", method_name: "setSuccessSelectedMicHost" }, + + + { endpoint: "/get/data/mic_device_list", ns: configs, hook_name: "useDevice", method_name: "updateMicDeviceList_FromBackend" }, + { endpoint: "/run/mic_device_list", ns: configs, hook_name: "useDevice", method_name: "updateMicDeviceList_FromBackend" }, + + { endpoint: "/get/data/selected_mic_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicDevice" }, + { endpoint: "/set/data/selected_mic_device", ns: configs, hook_name: "useDevice", method_name: "setSuccessSelectedMicDevice" }, + + { endpoint: "/run/selected_mic_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedMicHostAndDevice" }, + + // Device (Speaker) + { endpoint: "/get/data/speaker_device_list", ns: configs, hook_name: "useDevice", method_name: "updateSpeakerDeviceList_FromBackend" }, + { endpoint: "/run/speaker_device_list", ns: configs, hook_name: "useDevice", method_name: "updateSpeakerDeviceList_FromBackend" }, + + { endpoint: "/get/data/selected_speaker_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedSpeakerDevice" }, + { endpoint: "/set/data/selected_speaker_device", ns: configs, hook_name: "useDevice", method_name: "setSuccessSelectedSpeakerDevice" }, + { endpoint: "/run/selected_speaker_device", ns: configs, hook_name: "useDevice", method_name: "updateSelectedSpeakerDevice" }, + + // Device (Threshold) + { endpoint: "/get/data/mic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateMicThreshold" }, + { endpoint: "/set/data/mic_threshold", ns: configs, hook_name: "useDevice", method_name: "setSuccessMicThreshold" }, + { endpoint: "/get/data/speaker_threshold", ns: configs, hook_name: "useDevice", method_name: "updateSpeakerThreshold" }, + { endpoint: "/set/data/speaker_threshold", ns: configs, hook_name: "useDevice", method_name: "setSuccessSpeakerThreshold" }, + + { endpoint: "/get/data/mic_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticMicThreshold" }, + { endpoint: "/set/enable/mic_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutomaticMicThreshold" }, + { endpoint: "/set/disable/mic_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutomaticMicThreshold" }, + { endpoint: "/get/data/speaker_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "updateEnableAutomaticSpeakerThreshold" }, + { endpoint: "/set/enable/speaker_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutomaticSpeakerThreshold" }, + { endpoint: "/set/disable/speaker_automatic_threshold", ns: configs, hook_name: "useDevice", method_name: "setSuccessEnableAutomaticSpeakerThreshold" }, + + + // Appearance + { endpoint: "/get/data/ui_language", ns: configs, hook_name: "useAppearance", method_name: "updateUiLanguage" }, + { endpoint: "/set/data/ui_language", ns: configs, hook_name: "useAppearance", method_name: "setSuccessUiLanguage" }, + + { endpoint: "/get/data/ui_scaling", ns: configs, hook_name: "useAppearance", method_name: "updateUiScaling" }, + { endpoint: "/set/data/ui_scaling", ns: configs, hook_name: "useAppearance", method_name: "setSuccessUiScaling" }, + + { endpoint: "/get/data/textbox_ui_scaling", ns: configs, hook_name: "useAppearance", method_name: "updateMessageLogUiScaling" }, + { endpoint: "/set/data/textbox_ui_scaling", ns: configs, hook_name: "useAppearance", method_name: "setSuccessMessageLogUiScaling" }, + + { endpoint: "/get/data/send_message_button_type", ns: configs, hook_name: "useAppearance", method_name: "updateSendMessageButtonType" }, + { endpoint: "/set/data/send_message_button_type", ns: configs, hook_name: "useAppearance", method_name: "setSuccessSendMessageButtonType" }, + + { endpoint: "/get/data/show_resend_button", ns: configs, hook_name: "useAppearance", method_name: "updateShowResendButton" }, + { endpoint: "/set/enable/show_resend_button", ns: configs, hook_name: "useAppearance", method_name: "setSuccessShowResendButton" }, + { endpoint: "/set/disable/show_resend_button", ns: configs, hook_name: "useAppearance", method_name: "setSuccessShowResendButton" }, + + { endpoint: "/get/data/font_family", ns: configs, hook_name: "useAppearance", method_name: "updateSelectedFontFamily" }, + { endpoint: "/set/data/font_family", ns: configs, hook_name: "useAppearance", method_name: "setSuccessSelectedFontFamily" }, + + { endpoint: "/get/data/transparency", ns: configs, hook_name: "useAppearance", method_name: "updateTransparency" }, + { endpoint: "/set/data/transparency", ns: configs, hook_name: "useAppearance", method_name: "setSuccessTransparency" }, + + // Translation + { endpoint: "/get/data/deepl_auth_key", ns: configs, hook_name: "useTranslation", method_name: "updateDeepLAuthKey" }, + { endpoint: "/set/data/deepl_auth_key", ns: configs, hook_name: "useTranslation", method_name: "setSuccessDeepLAuthKey" }, + { endpoint: "/delete/data/deepl_auth_key", ns: configs, hook_name: "useTranslation", method_name: "deleteSuccessDeepLAuthKey" }, + + // Translation (AI Models) + { endpoint: "/get/data/ctranslate2_weight_type", ns: configs, hook_name: "useTranslation", method_name: "updateSelectedCTranslate2WeightType" }, + { endpoint: "/set/data/ctranslate2_weight_type", ns: configs, hook_name: "useTranslation", method_name: "setSuccessSelectedCTranslate2WeightType" }, + + { endpoint: "/get/data/selectable_ctranslate2_weight_type_dict", ns: configs, hook_name: "useTranslation", method_name: "updateDownloadedCTranslate2WeightTypeStatus" }, + + { endpoint: "/run/downloaded_ctranslate2_weight", ns: configs, hook_name: "useTranslation", method_name: "downloadedCTranslate2WeightType" }, + { endpoint: "/run/download_ctranslate2_weight", ns: null, hook_name: null, method_name: null }, + { endpoint: "/run/download_progress_ctranslate2_weight", ns: configs, hook_name: "useTranslation", method_name: "updateDownloadProgressCTranslate2WeightTypeStatus" }, + + { endpoint: "/get/data/translation_compute_device_list", ns: configs, hook_name: "useTranslation", method_name: "updateSelectableCTranslate2ComputeDeviceList_FromBackend" }, + + { endpoint: "/get/data/selected_translation_compute_device", ns: configs, hook_name: "useTranslation", method_name: "updateSelectedCTranslate2ComputeDevice" }, + { endpoint: "/set/data/selected_translation_compute_device", ns: configs, hook_name: "useTranslation", method_name: "setSuccessSelectedCTranslate2ComputeDevice" }, + + + // Transcription + // Transcription (Mic) + { endpoint: "/get/data/mic_record_timeout", ns: configs, hook_name: "useTranscription", method_name: "updateMicRecordTimeout" }, + { endpoint: "/set/data/mic_record_timeout", ns: configs, hook_name: "useTranscription", method_name: "setSuccessMicRecordTimeout" }, + + { endpoint: "/get/data/mic_phrase_timeout", ns: configs, hook_name: "useTranscription", method_name: "updateMicPhraseTimeout" }, + { endpoint: "/set/data/mic_phrase_timeout", ns: configs, hook_name: "useTranscription", method_name: "setSuccessMicPhraseTimeout" }, + + { endpoint: "/get/data/mic_max_phrases", ns: configs, hook_name: "useTranscription", method_name: "updateMicMaxWords" }, + { endpoint: "/set/data/mic_max_phrases", ns: configs, hook_name: "useTranscription", method_name: "setSuccessMicMaxWords" }, + + { endpoint: "/get/data/mic_word_filter", ns: configs, hook_name: "useTranscription", method_name: "updateMicWordFilterList" }, + { endpoint: "/set/data/mic_word_filter", ns: configs, hook_name: "useTranscription", method_name: "setSuccessMicWordFilterList" }, + + // Transcription (Speaker) + { endpoint: "/get/data/speaker_record_timeout", ns: configs, hook_name: "useTranscription", method_name: "updateSpeakerRecordTimeout" }, + { endpoint: "/set/data/speaker_record_timeout", ns: configs, hook_name: "useTranscription", method_name: "setSuccessSpeakerRecordTimeout" }, + + { endpoint: "/get/data/speaker_phrase_timeout", ns: configs, hook_name: "useTranscription", method_name: "updateSpeakerPhraseTimeout" }, + { endpoint: "/set/data/speaker_phrase_timeout", ns: configs, hook_name: "useTranscription", method_name: "setSuccessSpeakerPhraseTimeout" }, + + { endpoint: "/get/data/speaker_max_phrases", ns: configs, hook_name: "useTranscription", method_name: "updateSpeakerMaxWords" }, + { endpoint: "/set/data/speaker_max_phrases", ns: configs, hook_name: "useTranscription", method_name: "setSuccessSpeakerMaxWords" }, + + // Transcription (AI Models) + { endpoint: "/get/data/selected_transcription_engine", ns: configs, hook_name: "useTranscription", method_name: "updateSelectedTranscriptionEngine" }, + { endpoint: "/set/data/selected_transcription_engine", ns: configs, hook_name: "useTranscription", method_name: "setSuccessSelectedTranscriptionEngine" }, + + { endpoint: "/get/data/whisper_weight_type", ns: configs, hook_name: "useTranscription", method_name: "updateSelectedWhisperWeightType" }, + { endpoint: "/set/data/whisper_weight_type", ns: configs, hook_name: "useTranscription", method_name: "setSuccessSelectedWhisperWeightType" }, + + { endpoint: "/get/data/selectable_whisper_weight_type_dict", ns: configs, hook_name: "useTranscription", method_name: "updateDownloadedWhisperWeightTypeStatus" }, + + { endpoint: "/run/downloaded_whisper_weight", ns: configs, hook_name: "useTranscription", method_name: "downloadedWhisperWeightType" }, + { endpoint: "/run/download_whisper_weight", ns: null, hook_name: null, method_name: null }, + { endpoint: "/run/download_progress_whisper_weight", ns: configs, hook_name: "useTranscription", method_name: "updateDownloadProgressWhisperWeightTypeStatus" }, + + { endpoint: "/get/data/transcription_compute_device_list", ns: configs, hook_name: "useTranscription", method_name: "updateSelectableWhisperComputeDeviceList_FromBackend" }, + { endpoint: "/get/data/selected_transcription_compute_device", ns: configs, hook_name: "useTranscription", method_name: "updateSelectedWhisperComputeDevice" }, + { endpoint: "/set/data/selected_transcription_compute_device", ns: configs, hook_name: "useTranscription", method_name: "setSuccessSelectedWhisperComputeDevice" }, + + // VR + { endpoint: "/get/data/overlay_small_log", ns: configs, hook_name: "useVr", method_name: "updateIsEnabledOverlaySmallLog" }, + { endpoint: "/set/enable/overlay_small_log", ns: configs, hook_name: "useVr", method_name: "setSuccessIsEnabledOverlaySmallLog" }, + { endpoint: "/set/disable/overlay_small_log", ns: configs, hook_name: "useVr", method_name: "setSuccessIsEnabledOverlaySmallLog" }, + + { endpoint: "/get/data/overlay_small_log_settings", ns: configs, hook_name: "useVr", method_name: "updateOverlaySmallLogSettings" }, + { endpoint: "/set/data/overlay_small_log_settings", ns: configs, hook_name: "useVr", method_name: "setSuccessOverlaySmallLogSettings" }, + + { endpoint: "/get/data/overlay_large_log", ns: configs, hook_name: "useVr", method_name: "updateIsEnabledOverlayLargeLog" }, + { endpoint: "/set/enable/overlay_large_log", ns: configs, hook_name: "useVr", method_name: "setSuccessIsEnabledOverlayLargeLog" }, + { endpoint: "/set/disable/overlay_large_log", ns: configs, hook_name: "useVr", method_name: "setSuccessIsEnabledOverlayLargeLog" }, + + { endpoint: "/get/data/overlay_large_log_settings", ns: configs, hook_name: "useVr", method_name: "updateOverlayLargeLogSettings" }, + { endpoint: "/set/data/overlay_large_log_settings", ns: configs, hook_name: "useVr", method_name: "setSuccessOverlayLargeLogSettings" }, + + { endpoint: "/get/data/overlay_show_only_translated_messages", ns: configs, hook_name: "useVr", method_name: "updateOverlayShowOnlyTranslatedMessages" }, + { endpoint: "/set/enable/overlay_show_only_translated_messages", ns: configs, hook_name: "useVr", method_name: "setSuccessOverlayShowOnlyTranslatedMessages" }, + { endpoint: "/set/disable/overlay_show_only_translated_messages", ns: configs, hook_name: "useVr", method_name: "setSuccessOverlayShowOnlyTranslatedMessages" }, + + { endpoint: "/run/send_text_overlay", ns: null, hook_name: null, method_name: null }, + + + // Others + { endpoint: "/get/data/auto_clear_message_box", ns: configs, hook_name: "useOthers", method_name: "updateEnableAutoClearMessageInputBox" }, + { endpoint: "/set/enable/auto_clear_message_box", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableAutoClearMessageInputBox" }, + { endpoint: "/set/disable/auto_clear_message_box", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableAutoClearMessageInputBox" }, + + { endpoint: "/get/data/send_only_translated_messages", ns: configs, hook_name: "useOthers", method_name: "updateEnableSendOnlyTranslatedMessages" }, + { endpoint: "/set/enable/send_only_translated_messages", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableSendOnlyTranslatedMessages" }, + { endpoint: "/set/disable/send_only_translated_messages", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableSendOnlyTranslatedMessages" }, + + { endpoint: "/get/data/logger_feature", ns: configs, hook_name: "useOthers", method_name: "updateEnableAutoExportMessageLogs" }, + { endpoint: "/set/enable/logger_feature", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableAutoExportMessageLogs" }, + { endpoint: "/set/disable/logger_feature", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableAutoExportMessageLogs" }, + + { endpoint: "/get/data/vrc_mic_mute_sync", ns: configs, hook_name: "useOthers", method_name: "updateEnableVrcMicMuteSync_FromBackend" }, + { endpoint: "/set/enable/vrc_mic_mute_sync", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableVrcMicMuteSync" }, + { endpoint: "/set/disable/vrc_mic_mute_sync", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableVrcMicMuteSync" }, + + + { endpoint: "/get/data/send_message_to_vrc", ns: configs, hook_name: "useOthers", method_name: "updateEnableSendMessageToVrc" }, + { endpoint: "/set/enable/send_message_to_vrc", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableSendMessageToVrc" }, + { endpoint: "/set/disable/send_message_to_vrc", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableSendMessageToVrc" }, + + { endpoint: "/get/data/send_received_message_to_vrc", ns: configs, hook_name: "useOthers", method_name: "updateEnableSendReceivedMessageToVrc" }, + { endpoint: "/set/enable/send_received_message_to_vrc", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableSendReceivedMessageToVrc" }, + { endpoint: "/set/disable/send_received_message_to_vrc", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableSendReceivedMessageToVrc" }, + + { endpoint: "/get/data/notification_vrc_sfx", ns: configs, hook_name: "useOthers", method_name: "updateEnableNotificationVrcSfx" }, + { endpoint: "/set/enable/notification_vrc_sfx", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableNotificationVrcSfx" }, + { endpoint: "/set/disable/notification_vrc_sfx", ns: configs, hook_name: "useOthers", method_name: "setSuccessEnableNotificationVrcSfx" }, + + // Hotkeys + { endpoint: "/get/data/hotkeys", ns: configs, hook_name: "useHotkeys", method_name: "updateHotkeys" }, + { endpoint: "/set/data/hotkeys", ns: configs, hook_name: "useHotkeys", method_name: "setSuccessHotkeys" }, + + // Plugins + { endpoint: "/get/data/plugins_status", ns: configs, hook_name: "usePlugins", method_name: "updateSavedPluginsStatus" }, + { endpoint: "/set/data/plugins_status", ns: configs, hook_name: "usePlugins", method_name: "setSuccessSavedPluginsStatus" }, + + // Advanced Settings + { endpoint: "/get/data/osc_ip_address", ns: configs, hook_name: "useAdvancedSettings", method_name: "updateOscIpAddress" }, + { endpoint: "/set/data/osc_ip_address", ns: configs, hook_name: "useAdvancedSettings", method_name: "setSuccessOscIpAddress" }, + + { endpoint: "/get/data/osc_port", ns: configs, hook_name: "useAdvancedSettings", method_name: "updateOscPort" }, + { endpoint: "/set/data/osc_port", ns: configs, hook_name: "useAdvancedSettings", method_name: "setSuccessOscPort" }, + + { endpoint: "/get/data/websocket_server", ns: configs, hook_name: "useAdvancedSettings", method_name: "updateEnableWebsocket" }, + { endpoint: "/set/enable/websocket_server", ns: configs, hook_name: "useAdvancedSettings", method_name: "setSuccessEnableWebsocket" }, + { endpoint: "/set/disable/websocket_server", ns: configs, hook_name: "useAdvancedSettings", method_name: "setSuccessEnableWebsocket" }, + + { endpoint: "/get/data/websocket_host", ns: configs, hook_name: "useAdvancedSettings", method_name: "updateWebsocketHost" }, + { endpoint: "/set/data/websocket_host", ns: configs, hook_name: "useAdvancedSettings", method_name: "setSuccessWebsocketHost" }, + + { endpoint: "/get/data/websocket_port", ns: configs, hook_name: "useAdvancedSettings", method_name: "updateWebsocketPort" }, + { endpoint: "/set/data/websocket_port", ns: configs, hook_name: "useAdvancedSettings", method_name: "setSuccessWebsocketPort" }, + + + // Not Implemented Yet... + { endpoint: "/get/data/mic_avg_logprob", ns: null, hook_name: null, method_name: null }, // Not implemented on UI yet + { endpoint: "/get/data/mic_no_speech_prob", ns: null, hook_name: null, method_name: null }, // Not implemented on UI yet + { endpoint: "/get/data/speaker_avg_logprob", ns: null, hook_name: null, method_name: null }, // Not implemented on UI yet + { endpoint: "/get/data/speaker_no_speech_prob", ns: null, hook_name: null, method_name: null }, // Not implemented on UI yet + { endpoint: "/get/data/convert_message_to_romaji", ns: null, hook_name: null, method_name: null }, // Not implemented on UI yet + { endpoint: "/get/data/convert_message_to_hiragana", ns: null, hook_name: null, method_name: null }, // Not implemented on UI yet + { endpoint: "/get/data/transcription_engines", ns: null, hook_name: null, method_name: null }, // 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"]) +]; export const useReceiveRoutes = () => { - const { updateIsVrctAvailable } = useIsVrctAvailable(); - const { updateComputeMode } = useComputeMode(); - const { updateInitProgress } = useInitProgress(); - const { updateIsBackendReady } = useIsBackendReady(); - const { handleOscQuery } = useHandleOscQuery(); - const { restoreWindowGeometry } = useWindow(); - const { updateIsMainPageCompactMode } = useIsMainPageCompactMode(); - const { - updateTranslationStatus, - updateTranscriptionSendStatus, - updateTranscriptionReceiveStatus, - } = useMainFunction(); - const { - updateSelectedPresetTabNumber, - updateEnableMultiTranslation, - updateSelectedYourLanguages, - updateSelectedTargetLanguages, - updateTranslationEngines, - updateSelectedTranslationEngines, - } = useLanguageSettings(); - const { updateSelectableLanguageList } = useSelectableLanguageList(); - const { - addSystemMessageLog, - updateSentMessageLogById, - addSentMessageLog, - addReceivedMessageLog, - } = useMessage(); - const { updateLatestSoftwareVersionInfo } = useSoftwareVersion(); - const { updateSoftwareVersion } = useSoftwareVersion(); - const { updateEnableAutoMicSelect } = useEnableAutoMicSelect(); - const { updateEnableAutoSpeakerSelect } = useEnableAutoSpeakerSelect(); - const { updateMicHostList } = useMicHostList(); - const { updateSelectedMicHost } = useSelectedMicHost(); - const { updateMicDeviceList } = useMicDeviceList(); - const { updateSelectedMicDevice } = useSelectedMicDevice(); - const { updateSpeakerDeviceList } = useSpeakerDeviceList(); - const { updateSelectedSpeakerDevice } = useSelectedSpeakerDevice(); - const { updateMicThreshold, updateEnableAutomaticMicThreshold } = useMicThreshold(); - const { updateSpeakerThreshold, updateEnableAutomaticSpeakerThreshold } = useSpeakerThreshold(); + const { showNotification_Error } = common.useNotificationStatus(); + const { errorHandling_Backend } = _useBackendErrorHandling(); + const { updateIsBackendReady } = common.useIsBackendReady(); - const { updateEnableAutoClearMessageInputBox } = useEnableAutoClearMessageInputBox(); - const { updateEnableSendOnlyTranslatedMessages } = useEnableSendOnlyTranslatedMessages(); - const { updateEnableAutoExportMessageLogs } = useEnableAutoExportMessageLogs(); - const { updateEnableVrcMicMuteSync } = useEnableVrcMicMuteSync(); - const { updateEnableSendMessageToVrc } = useEnableSendMessageToVrc(); - const { updateEnableSendReceivedMessageToVrc } = useEnableSendReceivedMessageToVrc(); - - const { updateSendMessageButtonType } = useSendMessageButtonType(); - const { updateUiLanguage } = useUiLanguage(); - const { updateUiScaling } = useUiScaling(); - const { updateMessageLogUiScaling } = useMessageLogUiScaling(); - const { - updateVolumeVariable_Mic, - updateVolumeVariable_Speaker, - updateMicThresholdCheckStatus, - updateSpeakerThresholdCheckStatus, - } = useVolume(); - - const { updateMessageInputBoxRatio } = useMessageInputBoxRatio(); - const { updateSelectedFontFamily } = useSelectedFontFamily(); - const { updateTransparency } = useTransparency(); - - const { updateMicRecordTimeout } = useMicRecordTimeout(); - const { updateMicPhraseTimeout } = useMicPhraseTimeout(); - const { updateMicMaxWords } = useMicMaxWords(); - const { updateMicWordFilterList } = useMicWordFilterList(); - - const { updateSpeakerRecordTimeout } = useSpeakerRecordTimeout(); - const { updateSpeakerPhraseTimeout } = useSpeakerPhraseTimeout(); - const { updateSpeakerMaxWords } = useSpeakerMaxWords(); - - const { updateDeepLAuthKey, savedDeepLAuthKey } = useDeepLAuthKey(); - const { updateSelectedCTranslate2WeightType } = useSelectedCTranslate2WeightType(); - const { - updateDownloadedCTranslate2WeightTypeStatus, - updateDownloadProgressCTranslate2WeightTypeStatus, - downloadedCTranslate2WeightType, - } = useCTranslate2WeightTypeStatus(); - const { updateSelectableCTranslate2ComputeDeviceList } = useSelectableCTranslate2ComputeDeviceList(); - const { updateSelectedCTranslate2ComputeDevice } = useSelectedCTranslate2ComputeDevice(); - const { updateSelectableWhisperComputeDeviceList } = useSelectableWhisperComputeDeviceList(); - const { updateSelectedWhisperComputeDevice } = useSelectedWhisperComputeDevice(); - - const { updateSelectedTranscriptionEngine } = useSelectedTranscriptionEngine(); - const { updateSelectedWhisperWeightType } = useSelectedWhisperWeightType(); - const { - updateDownloadedWhisperWeightTypeStatus, - updateDownloadProgressWhisperWeightTypeStatus, - downloadedWhisperWeightType, - } = useWhisperWeightTypeStatus(); - - const { updateOverlaySmallLogSettings } = useOverlaySmallLogSettings(); - const { updateIsEnabledOverlaySmallLog } = useIsEnabledOverlaySmallLog(); - const { updateOverlayLargeLogSettings } = useOverlayLargeLogSettings(); - const { updateIsEnabledOverlayLargeLog } = useIsEnabledOverlayLargeLog(); - const { updateOverlayShowOnlyTranslatedMessages } = useOverlayShowOnlyTranslatedMessages(); - const { updateEnableNotificationVrcSfx } = useEnableNotificationVrcSfx(); - - const { updateHotkeys } = useHotkeys(); - const { updateSavedPluginsStatus } = usePlugins(); - - const { updateOscIpAddress } = useOscIpAddress(); - const { updateOscPort } = useOscPort(); - const { - updateEnableWebsocket, - updateWebsocketHost, - updateWebsocketPort, - } = useWebsocket(); - - - - const { showNotification_Success, showNotification_Error } = useNotificationStatus(); - - const { handleNetworkConnection } = useHandleNetworkConnection(); - - const { - errorHandling_Backend, - } = _useBackendErrorHandling(); - - const routes = { - // 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": () => {}, - "/run/open_filepath_logs": () => console.log("Opened Directory, Message Logs"), - "/run/open_filepath_config_file": () => console.log("Opened Directory, Config File"), - "/run/software_update_info": (payload) => { - updateLatestSoftwareVersionInfo(prev => ({ - is_update_available: payload.is_update_available, - new_version: payload.new_version || prev.data.new_version, - })); - }, - "/run/connected_network": handleNetworkConnection, - "/run/enable_osc_query": ({data, disabled_functions}) => { - handleOscQuery({ - is_osc_query_enabled: data, - disabled_functions: disabled_functions, - }); - }, - - // Main Page - // Page Controls - "/get/data/main_window_sidebar_compact_mode": updateIsMainPageCompactMode, - "/set/enable/main_window_sidebar_compact_mode": updateIsMainPageCompactMode, - "/set/disable/main_window_sidebar_compact_mode": updateIsMainPageCompactMode, - // Main Functions - "/set/enable/translation": updateTranslationStatus, - "/set/disable/translation": updateTranslationStatus, - "/set/enable/transcription_send": updateTranscriptionSendStatus, - "/set/disable/transcription_send": updateTranscriptionSendStatus, - "/set/enable/transcription_receive": updateTranscriptionReceiveStatus, - "/set/disable/transcription_receive": updateTranscriptionReceiveStatus, - - // Language Settings - "/get/data/selected_tab_no": updateSelectedPresetTabNumber, - "/set/data/selected_tab_no": updateSelectedPresetTabNumber, - "/get/data/multi_language_translation": updateEnableMultiTranslation, - "/get/data/selected_your_languages": updateSelectedYourLanguages, - "/set/data/selected_your_languages": updateSelectedYourLanguages, - "/get/data/selected_target_languages": updateSelectedTargetLanguages, - "/set/data/selected_target_languages": updateSelectedTargetLanguages, - - "/get/data/translation_engines": (payload) => { - const updateTranslatorAvailability = (keys) => { - return translator_status.map(translator => ({ - ...translator, - is_available: keys.includes(translator.id), - })); - }; - const updated_list = updateTranslatorAvailability(payload); - updateTranslationEngines(updated_list); - }, - "/run/translation_engines": (payload) => { - const updateTranslatorAvailability = (keys) => { - return translator_status.map(translator => ({ - ...translator, - is_available: keys.includes(translator.id), - })); - }; - const updated_list = updateTranslatorAvailability(payload); - updateTranslationEngines(updated_list); - }, - "/get/data/selected_translation_engines": updateSelectedTranslationEngines, - "/set/data/selected_translation_engines": updateSelectedTranslationEngines, - "/run/selected_translation_engines": updateSelectedTranslationEngines, - - "/run/swap_your_language_and_target_language": (payload) => { - updateSelectedYourLanguages(payload.your); - updateSelectedTargetLanguages(payload.target); - }, - - - // Language Selector - "/get/data/selectable_language_list": updateSelectableLanguageList, - - // Message - "/run/send_message_box": updateSentMessageLogById, - "/run/typing_message_box": ()=>{}, - "/run/stop_typing_message_box": ()=>{}, - "/run/transcription_send_mic_message": addSentMessageLog, - "/run/transcription_receive_speaker_message": addReceivedMessageLog, - - // Message Box - "/get/data/message_box_ratio": updateMessageInputBoxRatio, - "/set/data/message_box_ratio": updateMessageInputBoxRatio, - - - // Config Page - // Common - "/get/data/version": updateSoftwareVersion, - - // Device Tab - "/get/data/auto_mic_select": updateEnableAutoMicSelect, - "/set/enable/auto_mic_select": updateEnableAutoMicSelect, - "/set/disable/auto_mic_select": updateEnableAutoMicSelect, - "/get/data/auto_speaker_select": updateEnableAutoSpeakerSelect, - "/set/enable/auto_speaker_select": updateEnableAutoSpeakerSelect, - "/set/disable/auto_speaker_select": updateEnableAutoSpeakerSelect, - - "/get/data/mic_host_list": (payload) => updateMicHostList(arrayToObject(payload)), - "/run/mic_host_list": (payload) => updateMicHostList(arrayToObject(payload)), - "/get/data/selected_mic_host": updateSelectedMicHost, - "/set/data/selected_mic_host": (payload) => { - updateSelectedMicHost(payload.host); - updateSelectedMicDevice(payload.device); - }, - - "/get/data/mic_device_list": (payload) => updateMicDeviceList(arrayToObject(payload)), - "/run/mic_device_list": (payload) => updateMicDeviceList(arrayToObject(payload)), - "/get/data/selected_mic_device": updateSelectedMicDevice, - "/set/data/selected_mic_device": updateSelectedMicDevice, - - "/run/selected_mic_device": (payload) => { - - updateSelectedMicHost(payload.host); - updateSelectedMicDevice(payload.device); - }, - - "/get/data/speaker_device_list": (payload) => updateSpeakerDeviceList(arrayToObject(payload)), - "/run/speaker_device_list": (payload) => updateSpeakerDeviceList(arrayToObject(payload)), - "/get/data/selected_speaker_device": updateSelectedSpeakerDevice, - "/set/data/selected_speaker_device": updateSelectedSpeakerDevice, - "/run/selected_speaker_device": updateSelectedSpeakerDevice, - - "/run/check_mic_volume": updateVolumeVariable_Mic, - "/run/check_speaker_volume": updateVolumeVariable_Speaker, - "/set/enable/check_mic_threshold": updateMicThresholdCheckStatus, - "/set/disable/check_mic_threshold": updateMicThresholdCheckStatus, - "/set/enable/check_speaker_threshold": updateSpeakerThresholdCheckStatus, - "/set/disable/check_speaker_threshold": updateSpeakerThresholdCheckStatus, - - "/get/data/mic_threshold": updateMicThreshold, - "/set/data/mic_threshold": updateMicThreshold, - "/get/data/speaker_threshold": updateSpeakerThreshold, - "/set/data/speaker_threshold": updateSpeakerThreshold, - - "/get/data/mic_automatic_threshold": updateEnableAutomaticMicThreshold, - "/set/enable/mic_automatic_threshold": updateEnableAutomaticMicThreshold, - "/set/disable/mic_automatic_threshold": updateEnableAutomaticMicThreshold, - "/get/data/speaker_automatic_threshold": updateEnableAutomaticSpeakerThreshold, - "/set/enable/speaker_automatic_threshold": updateEnableAutomaticSpeakerThreshold, - "/set/disable/speaker_automatic_threshold": updateEnableAutomaticSpeakerThreshold, - - // Appearance - "/get/data/ui_language": updateUiLanguage, - "/set/data/ui_language": updateUiLanguage, - - "/get/data/ui_scaling": updateUiScaling, - "/set/data/ui_scaling": updateUiScaling, - - "/get/data/textbox_ui_scaling": updateMessageLogUiScaling, - "/set/data/textbox_ui_scaling": updateMessageLogUiScaling, - - "/get/data/send_message_button_type": updateSendMessageButtonType, - "/set/data/send_message_button_type": updateSendMessageButtonType, - - "/get/data/font_family": updateSelectedFontFamily, - "/set/data/font_family": updateSelectedFontFamily, - - "/get/data/transparency": updateTransparency, - "/set/data/transparency": updateTransparency, - - // Translation - "/get/data/deepl_auth_key": updateDeepLAuthKey, - "/set/data/deepl_auth_key": savedDeepLAuthKey, - "/delete/data/deepl_auth_key": () => updateDeepLAuthKey(""), - - "/get/data/ctranslate2_weight_type": updateSelectedCTranslate2WeightType, - "/set/data/ctranslate2_weight_type": updateSelectedCTranslate2WeightType, - - "/get/data/selectable_ctranslate2_weight_type_dict": updateDownloadedCTranslate2WeightTypeStatus, - - "/get/data/translation_compute_device_list": (payload) => updateSelectableCTranslate2ComputeDeviceList(transformToIndexedArray(payload)), - "/get/data/selected_translation_compute_device": updateSelectedCTranslate2ComputeDevice, - "/set/data/selected_translation_compute_device": updateSelectedCTranslate2ComputeDevice, - - "/run/downloaded_ctranslate2_weight": downloadedCTranslate2WeightType, - "/run/download_ctranslate2_weight": () => {}, - "/run/download_progress_ctranslate2_weight": updateDownloadProgressCTranslate2WeightTypeStatus, - - // Transcription - "/get/data/mic_record_timeout": updateMicRecordTimeout, - "/set/data/mic_record_timeout": updateMicRecordTimeout, - - "/get/data/mic_phrase_timeout": updateMicPhraseTimeout, - "/set/data/mic_phrase_timeout": updateMicPhraseTimeout, - - "/get/data/mic_max_phrases": updateMicMaxWords, - "/set/data/mic_max_phrases": updateMicMaxWords, - - "/get/data/mic_word_filter": (payload) => { - updateMicWordFilterList((prev_list) => { - const updated_list = [...prev_list.data]; - for (const value of payload) { - const existing_item = updated_list.find(item => item.value === value); - if (existing_item) { - existing_item.is_redoable = false; - } else { - updated_list.push({ value, is_redoable: false }); - } - } - return updated_list; - }); - }, - "/set/data/mic_word_filter": (payload) => { - updateMicWordFilterList((prev_list) => { - const updated_list = [...prev_list.data]; - for (const value of payload) { - const existing_item = updated_list.find(item => item.value === value); - if (existing_item) { - existing_item.is_redoable = false; - } else { - updated_list.push({ value, is_redoable: false }); - } - } - return updated_list; - }); - }, - "/run/word_filter": (payload) => addSystemMessageLog(payload.message), - - - "/get/data/speaker_record_timeout": updateSpeakerRecordTimeout, - "/set/data/speaker_record_timeout": updateSpeakerRecordTimeout, - - "/get/data/speaker_phrase_timeout": updateSpeakerPhraseTimeout, - "/set/data/speaker_phrase_timeout": updateSpeakerPhraseTimeout, - - "/get/data/speaker_max_phrases": updateSpeakerMaxWords, - "/set/data/speaker_max_phrases": updateSpeakerMaxWords, - - "/get/data/selected_transcription_engine": updateSelectedTranscriptionEngine, - "/set/data/selected_transcription_engine": updateSelectedTranscriptionEngine, - - "/get/data/whisper_weight_type": updateSelectedWhisperWeightType, - "/set/data/whisper_weight_type": updateSelectedWhisperWeightType, - - "/get/data/selectable_whisper_weight_type_dict": updateDownloadedWhisperWeightTypeStatus, - - "/run/downloaded_whisper_weight": downloadedWhisperWeightType, - "/run/download_whisper_weight": () => {}, - "/run/download_progress_whisper_weight": updateDownloadProgressWhisperWeightTypeStatus, - - "/get/data/transcription_compute_device_list": (payload) => updateSelectableWhisperComputeDeviceList(transformToIndexedArray(payload)), - "/get/data/selected_transcription_compute_device": updateSelectedWhisperComputeDevice, - "/set/data/selected_transcription_compute_device": updateSelectedWhisperComputeDevice, - - // VR - "/get/data/overlay_small_log": updateIsEnabledOverlaySmallLog, - "/set/enable/overlay_small_log": updateIsEnabledOverlaySmallLog, - "/set/disable/overlay_small_log": updateIsEnabledOverlaySmallLog, - - "/get/data/overlay_small_log_settings": updateOverlaySmallLogSettings, - "/set/data/overlay_small_log_settings": updateOverlaySmallLogSettings, - - "/get/data/overlay_large_log": updateIsEnabledOverlayLargeLog, - "/set/enable/overlay_large_log": updateIsEnabledOverlayLargeLog, - "/set/disable/overlay_large_log": updateIsEnabledOverlayLargeLog, - - "/get/data/overlay_large_log_settings": updateOverlayLargeLogSettings, - "/set/data/overlay_large_log_settings": updateOverlayLargeLogSettings, - - "/get/data/overlay_show_only_translated_messages": updateOverlayShowOnlyTranslatedMessages, - "/set/enable/overlay_show_only_translated_messages": updateOverlayShowOnlyTranslatedMessages, - "/set/disable/overlay_show_only_translated_messages": updateOverlayShowOnlyTranslatedMessages, - - "/run/send_text_overlay": () => {}, - - // Others Tab - "/get/data/auto_clear_message_box": updateEnableAutoClearMessageInputBox, - "/set/enable/auto_clear_message_box": updateEnableAutoClearMessageInputBox, - "/set/disable/auto_clear_message_box": updateEnableAutoClearMessageInputBox, - - "/get/data/send_only_translated_messages": updateEnableSendOnlyTranslatedMessages, - "/set/enable/send_only_translated_messages": updateEnableSendOnlyTranslatedMessages, - "/set/disable/send_only_translated_messages": updateEnableSendOnlyTranslatedMessages, - - "/get/data/logger_feature": updateEnableAutoExportMessageLogs, - "/set/enable/logger_feature": updateEnableAutoExportMessageLogs, - "/set/disable/logger_feature": updateEnableAutoExportMessageLogs, - - "/get/data/vrc_mic_mute_sync": (payload) => updateEnableVrcMicMuteSync((old_value) => { - return {...old_value.data, is_enabled: payload}; - }), - "/set/enable/vrc_mic_mute_sync": (payload) => updateEnableVrcMicMuteSync((old_value) => { - return {...old_value.data, is_enabled: payload}; - }), - "/set/disable/vrc_mic_mute_sync": (payload) => updateEnableVrcMicMuteSync((old_value) => { - return {...old_value.data, is_enabled: payload}; - }), - - "/get/data/send_message_to_vrc": updateEnableSendMessageToVrc, - "/set/enable/send_message_to_vrc": updateEnableSendMessageToVrc, - "/set/disable/send_message_to_vrc": updateEnableSendMessageToVrc, - - "/get/data/send_received_message_to_vrc": updateEnableSendReceivedMessageToVrc, - "/set/enable/send_received_message_to_vrc": updateEnableSendReceivedMessageToVrc, - "/set/disable/send_received_message_to_vrc": updateEnableSendReceivedMessageToVrc, - - "/get/data/notification_vrc_sfx": updateEnableNotificationVrcSfx, - "/set/enable/notification_vrc_sfx": updateEnableNotificationVrcSfx, - "/set/disable/notification_vrc_sfx": updateEnableNotificationVrcSfx, - - // Hotkeys - "/get/data/hotkeys": updateHotkeys, - "/set/data/hotkeys": updateHotkeys, - - // Plugins - "/get/data/plugins_status": updateSavedPluginsStatus, - "/set/data/plugins_status": updateSavedPluginsStatus, - - // Advanced Settings - "/get/data/osc_ip_address": updateOscIpAddress, - "/set/data/osc_ip_address": updateOscIpAddress, - - "/get/data/osc_port": updateOscPort, - "/set/data/osc_port": updateOscPort, - - "/get/data/websocket_server": updateEnableWebsocket, - "/set/enable/websocket_server": updateEnableWebsocket, - "/set/disable/websocket_server": updateEnableWebsocket, - - "/get/data/websocket_host": updateWebsocketHost, - "/set/data/websocket_host": updateWebsocketHost, - - "/get/data/websocket_port": updateWebsocketPort, - "/set/data/websocket_port": updateWebsocketPort, - - "/get/data/mic_avg_logprob": ()=>{}, // Not implemented on UI yet - "/get/data/mic_no_speech_prob": ()=>{}, // Not implemented on UI yet - "/get/data/speaker_avg_logprob": ()=>{}, // Not implemented on UI yet - "/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 handleInvalidEndpoint = (parsed_data) => { + console.error(`Invalid endpoint: ${parsed_data.endpoint}\nresult: ${JSON.stringify(parsed_data.result)}`); }; + const hook_results = {}; + ROUTE_META_LIST.forEach(({ ns, hook_name }) => { + if (ns && hook_name && !(hook_name in hook_results)) { + hook_results[hook_name] = ns[hook_name](); + } + }); + + const noop = () => {}; + + const routes = Object.fromEntries( + ROUTE_META_LIST.map(({ endpoint, hook_name, method_name }) => { + const result_obj = hook_results[hook_name] || {}; + const fn = result_obj[method_name]; + return [endpoint, typeof fn === "function" ? fn : noop]; + }) + ); + + 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}\nvalue: ${JSON.stringify(value)}`); - } - }; + const { endpoint, status, result } = parsed_data; - const handleInvalidEndpoint = (parsed_data) => { - console.error(`Invalid endpoint: ${parsed_data.endpoint}\nresult: ${JSON.stringify(parsed_data.result)}`); - }; - - if (parsed_data.endpoint === "/run/initialization_complete") { - initDataSyncProcess(parsed_data.result); + if (endpoint === "/run/initialization_complete") { + Object.entries(result).forEach(([ep, value]) => { + if (ep in routes) { + routes[ep](value); + } else { + handleInvalidEndpoint({ endpoint: ep, result: value }); + } + }); updateIsBackendReady(true); return; - }; + } - switch (parsed_data.status) { + + switch (status) { case 200: - const route = routes[parsed_data.endpoint]; - if (route) { - route(parsed_data.result); + if (endpoint in routes) { + routes[endpoint](result); } else { handleInvalidEndpoint(parsed_data); } @@ -580,31 +372,24 @@ export const useReceiveRoutes = () => { result: parsed_data.result, }); break; - case 500: - showNotification_Error( - `An error occurred. Please restart VRCT or contact the developers. ${JSON.stringify(parsed_data.result)}`, { hide_duration: null }); - break; case 348: // console.log(`from backend: %c ${JSON.stringify(parsed_data)}`, style_348); break; + case 500: + showNotification_Error( + `An error occurred. Please restart VRCT or contact the developers. ${JSON.stringify(parsed_data.result)}`, { hide_duration: null }); + break; + default: console.log("Received data status does not match.", parsed_data); - break; } - }; + return { receiveRoutes }; }; const style_348 = [ "color: gray", -].join(";"); - -const transformToIndexedArray = (devices) => { - return devices.reduce((result, device, index) => { - result[index] = device; - return result; - }, {}); -}; \ No newline at end of file +].join(";"); \ No newline at end of file diff --git a/src-ui/logics/useStartPython.js b/src-ui/logics/useStartPython.js deleted file mode 100644 index c8aaf2f5..00000000 --- a/src-ui/logics/useStartPython.js +++ /dev/null @@ -1,34 +0,0 @@ -import { Command } from "@tauri-apps/plugin-shell"; -import { store } from "@store"; -import { useReceiveRoutes } from "./useReceiveRoutes"; -import { - useNotificationStatus, -} from "@logics_common"; - -export const useStartPython = () => { - const { receiveRoutes } = useReceiveRoutes(); - const { showNotification_Success, showNotification_Error } = useNotificationStatus(); - - const asyncStartPython = async () => { - const command = Command.sidecar("bin/VRCT-sidecar"); - command.on("error", error => console.error(`error: "${error}"`)); - command.stdout.on("data", (line) => { - let parsed_data = ""; - try { - parsed_data = JSON.parse(line); - receiveRoutes(parsed_data); - } catch (error) { - console.log(error, line); - } - }); - command.stderr.on("data", line => { - showNotification_Error( - `An error occurred. Please restart VRCT or contact the developers. The last line:${JSON.stringify(line)}`, { hide_duration: null }); - console.error("stderr", line) - }); - const backend_subprocess = await command.spawn(); - store.backend_subprocess = backend_subprocess; - }; - - return { asyncStartPython }; -}; \ No newline at end of file diff --git a/src-ui/store.js b/src-ui/store.js index 06fc859a..7d2fac28 100644 --- a/src-ui/store.js +++ b/src-ui/store.js @@ -5,8 +5,9 @@ import { } from "jotai"; import { - generateTestData, -} from "@test_data"; + generateTestConversationData, +} from "./_test_data.js" + import { translator_status, ctranslate2_weight_type_status, @@ -15,12 +16,9 @@ import { export const store = { backend_subprocess: null, - config_page: null, setting_box_scroll_container: null, log_box_ref: null, text_area_ref: null, - is_register_window_geometry_controller: false, - is_applied_init_message_box_height: false, is_initialized_load_plugin: false, is_fetched_plugins_info_already: false, is_initialized_fetched_plugin_info: false, @@ -31,10 +29,7 @@ const generatePropertyNames = (base_name) => ({ pending: `pending${base_name}`, current: `current${base_name}`, update: `update${base_name}`, - updatePart: `updatePart${base_name}`, - async_update: `asyncUpdate${base_name}`, add: `add${base_name}`, - async_add: `asyncAdd${base_name}`, }); @@ -152,7 +147,6 @@ export const { atomInstance: Atom_TranscriptionReceiveStatus, useHook: useStore_ export const { atomInstance: Atom_ForegroundStatus, useHook: useStore_ForegroundStatus } = createAtomWithHook(false, "ForegroundStatus", {is_state_ok: true}); export const { atomInstance: Atom_SelectedPresetTabNumber, useHook: useStore_SelectedPresetTabNumber } = createAtomWithHook("1", "SelectedPresetTabNumber"); -export const { atomInstance: Atom_EnableMultiTranslation, useHook: useStore_EnableMultiTranslation } = createAtomWithHook(false, "EnableMultiTranslation"); export const { atomInstance: Atom_SelectedYourLanguages, useHook: useStore_SelectedYourLanguages } = createAtomWithHook({}, "SelectedYourLanguages"); export const { atomInstance: Atom_SelectedTargetLanguages, useHook: useStore_SelectedTargetLanguages } = createAtomWithHook({}, "SelectedTargetLanguages"); @@ -169,10 +163,9 @@ export const { atomInstance: Atom_SelectableLanguageList, useHook: useStore_Sele // Message Container export const { atomInstance: Atom_MessageLogs, useHook: useStore_MessageLogs } = createAtomWithHook([], "MessageLogs"); -// export const { atomInstance: Atom_MessageLogs, useHook: useStore_MessageLogs } = createAtomWithHook(generateTestData(20), "MessageLogs"); // For testing +// export const { atomInstance: Atom_MessageLogs, useHook: useStore_MessageLogs } = createAtomWithHook(generateTestConversationData(20), "MessageLogs"); // For testing export const { atomInstance: Atom_MessageInputBoxRatio, useHook: useStore_MessageInputBoxRatio } = createAtomWithHook(20, "MessageInputBoxRatio"); export const { atomInstance: Atom_MessageInputValue, useHook: useStore_MessageInputValue } = createAtomWithHook("", "MessageInputValue"); -export const { atomInstance: Atom_IsVisibleResendButton, useHook: useStore_IsVisibleResendButton } = createAtomWithHook(false, "IsVisibleResendButton", {is_state_ok: true}); @@ -213,6 +206,7 @@ export const { atomInstance: Atom_UiLanguage, useHook: useStore_UiLanguage } = c export const { atomInstance: Atom_UiScaling, useHook: useStore_UiScaling } = createAtomWithHook(100, "UiScaling"); export const { atomInstance: Atom_MessageLogUiScaling, useHook: useStore_MessageLogUiScaling } = createAtomWithHook(100, "MessageLogUiScaling"); export const { atomInstance: Atom_SendMessageButtonType, useHook: useStore_SendMessageButtonType } = createAtomWithHook("show", "SendMessageButtonType"); +export const { atomInstance: Atom_ShowResendButton, useHook: useStore_ShowResendButton } = createAtomWithHook(false, "ShowResendButton"); export const { atomInstance: Atom_SelectedFontFamily, useHook: useStore_SelectedFontFamily } = createAtomWithHook("Yu Gothic UI", "SelectedFontFamily"); export const { atomInstance: Atom_SelectableFontFamilyList, useHook: useStore_SelectableFontFamilyList } = createAtomWithHook({}, "SelectableFontFamilyList"); export const { atomInstance: Atom_Transparency, useHook: useStore_Transparency } = createAtomWithHook(100, "Transparency"); diff --git a/src-ui/utils.js b/src-ui/utils.js index 96a87c75..2f5f8bdc 100644 --- a/src-ui/utils.js +++ b/src-ui/utils.js @@ -57,4 +57,12 @@ export const genNumArray = (count, start_from = 0) => { export const genNumObjArray = (count, start_from = 0) => { return arrayToObject(genNumArray(count, start_from)); +}; + +// This is using for only AI models compute device list, currently. (CTranslate2, Whisper) +export const transformToIndexedArray = (devices) => { + return devices.reduce((result, device, index) => { + result[index] = device; + return result; + }, {}); }; \ No newline at end of file diff --git a/vite.config.js b/vite.config.js index 092db909..b678f171 100644 --- a/vite.config.js +++ b/vite.config.js @@ -56,7 +56,11 @@ export default defineConfig(async () => { resolve: { alias: { "@root": path.resolve(__dirname), - "@test_data": path.resolve(__dirname, "./test_data.js"), + + "@useI18n": path.resolve(__dirname, "locales/useI18n.js"), + + "@useReceiveRoutes": path.resolve(__dirname, "src-ui/logics/useReceiveRoutes.js"), + "@useStdoutToPython": path.resolve(__dirname, "src-ui/logics/useStdoutToPython.js"), "@ui_configs": path.resolve(__dirname, "src-ui/ui_configs.js"), "@scss_mixins": path.resolve(__dirname, "src-ui/common_css/mixins.scss"),