From d3ef567ef295ad937661c2e7684c72f9a4742609 Mon Sep 17 00:00:00 2001 From: Sakamoto Shiina <68018796+ShiinaSakamoto@users.noreply.github.com> Date: Wed, 22 Oct 2025 17:34:57 +0900 Subject: [PATCH] [Refactor/TMP5] Refactor UI components and connect to backend APIs. (VR(Overlay)) --- src-ui/store.js | 50 ++++++++++++++++++------------------- src-ui/ui_config_setter.js | 42 +++++++++++++------------------ src-ui/useSettingsLogics.js | 16 ++++++++++++ 3 files changed, 59 insertions(+), 49 deletions(-) diff --git a/src-ui/store.js b/src-ui/store.js index b5a91406..4eb3f56b 100644 --- a/src-ui/store.js +++ b/src-ui/store.js @@ -298,31 +298,31 @@ export const { atomInstance: Atom_IsOpenedMicWordFilterList, useHook: useStore_I // VR -export const { atomInstance: Atom_OverlaySmallLogSettings, useHook: useStore_OverlaySmallLogSettings } = createAtomWithHook({ - x_pos: 0.0, - y_pos: 0.0, - z_pos: 0.0, - x_rotation: 0.0, - y_rotation: 0.0, - z_rotation: 0.0, - display_duration: 5, - fadeout_duration: 2, - tracker: "HMD", -}, "OverlaySmallLogSettings"); -export const { atomInstance: Atom_IsEnabledOverlaySmallLog, useHook: useStore_IsEnabledOverlaySmallLog } = createAtomWithHook(false, "IsEnabledOverlaySmallLog"); -export const { atomInstance: Atom_OverlayLargeLogSettings, useHook: useStore_OverlayLargeLogSettings } = createAtomWithHook({ - x_pos: 0.0, - y_pos: 0.0, - z_pos: 0.0, - x_rotation: 0.0, - y_rotation: 0.0, - z_rotation: 0.0, - display_duration: 5, - fadeout_duration: 2, - tracker: "HMD", -}, "OverlayLargeLogSettings"); -export const { atomInstance: Atom_IsEnabledOverlayLargeLog, useHook: useStore_IsEnabledOverlayLargeLog } = createAtomWithHook(false, "IsEnabledOverlayLargeLog"); -export const { atomInstance: Atom_OverlayShowOnlyTranslatedMessages, useHook: useStore_OverlayShowOnlyTranslatedMessages } = createAtomWithHook(false, "OverlayShowOnlyTranslatedMessages"); +// export const { atomInstance: Atom_OverlaySmallLogSettings, useHook: useStore_OverlaySmallLogSettings } = createAtomWithHook({ +// x_pos: 0.0, +// y_pos: 0.0, +// z_pos: 0.0, +// x_rotation: 0.0, +// y_rotation: 0.0, +// z_rotation: 0.0, +// display_duration: 5, +// fadeout_duration: 2, +// tracker: "HMD", +// }, "OverlaySmallLogSettings"); +// export const { atomInstance: Atom_IsEnabledOverlaySmallLog, useHook: useStore_IsEnabledOverlaySmallLog } = createAtomWithHook(false, "IsEnabledOverlaySmallLog"); +// export const { atomInstance: Atom_OverlayLargeLogSettings, useHook: useStore_OverlayLargeLogSettings } = createAtomWithHook({ +// x_pos: 0.0, +// y_pos: 0.0, +// z_pos: 0.0, +// x_rotation: 0.0, +// y_rotation: 0.0, +// z_rotation: 0.0, +// display_duration: 5, +// fadeout_duration: 2, +// tracker: "HMD", +// }, "OverlayLargeLogSettings"); +// export const { atomInstance: Atom_IsEnabledOverlayLargeLog, useHook: useStore_IsEnabledOverlayLargeLog } = createAtomWithHook(false, "IsEnabledOverlayLargeLog"); +// export const { atomInstance: Atom_OverlayShowOnlyTranslatedMessages, useHook: useStore_OverlayShowOnlyTranslatedMessages } = createAtomWithHook(false, "OverlayShowOnlyTranslatedMessages"); // Others // export const { atomInstance: Atom_EnableAutoClearMessageInputBox, useHook: useStore_EnableAutoClearMessageInputBox } = createAtomWithHook(true, "EnableAutoClearMessageInputBox"); diff --git a/src-ui/ui_config_setter.js b/src-ui/ui_config_setter.js index aff22a55..889bce48 100644 --- a/src-ui/ui_config_setter.js +++ b/src-ui/ui_config_setter.js @@ -3,9 +3,13 @@ import { createAtomWithHook } from "@store"; import { ctranslate2_weight_type_status, whisper_weight_type_status, + ui_configs, } from "@ui_configs"; -import { useSettingsLogics } from "./useSettingsLogics"; +import { + useSettingsLogics, + useConfigFunctions, +} from "./useSettingsLogics"; export const SETTINGS_ARRAY = [ @@ -378,6 +382,14 @@ export const SETTINGS_ARRAY = [ logics_template_id: "toggle_enable_disable", base_endpoint_name: "overlay_small_log", }, + { + Category: "Vr", + Base_Name: "OverlaySmallLogSettings", + default_value: ui_configs.overlay_small_log_default_settings, + ui_template_id: "object", + logics_template_id: "get_set", + base_endpoint_name: "overlay_small_log_settings", + }, { Category: "Vr", Base_Name: "IsEnabledOverlayLargeLog", @@ -386,18 +398,10 @@ export const SETTINGS_ARRAY = [ logics_template_id: "toggle_enable_disable", base_endpoint_name: "overlay_large_log", }, - { - Category: "Vr", - Base_Name: "OverlaySmallLogSettings", - default_value: {}, - ui_template_id: "object", - logics_template_id: "get_set", - base_endpoint_name: "overlay_small_log_settings", - }, { Category: "Vr", Base_Name: "OverlayLargeLogSettings", - default_value: {}, + default_value: ui_configs.overlay_large_log_default_settings, ui_template_id: "object", logics_template_id: "get_set", base_endpoint_name: "overlay_large_log_settings", @@ -501,16 +505,6 @@ export const SETTINGS_ARRAY = [ base_endpoint_name: "convert_message_to_hiragana", }, - // Hotkeys - // { - // Category: "Hotkeys", - // Base_Name: "SendMessageHotkey", - // default_value: "", - // ui_template_id: "input", - // logics_template_id: "get_set", - // base_endpoint_name: "send_message_hotkey", - // }, - // AdvancedSettings { Category: "AdvancedSettings", @@ -561,7 +555,7 @@ for (const setting_data of SETTINGS_ARRAY) { createAtomWithHook(setting_data.default_value, setting_data.Base_Name); } -const buildCategoryApiFromSettings = (settings, settingsArray, Category) => { +const buildCategoryApiFromSettings = (settings, settingsArray, Category, extraFunctions = {}) => { const api = {}; const filtered = settingsArray.filter((s) => s.Category === Category); @@ -598,14 +592,14 @@ const buildCategoryApiFromSettings = (settings, settingsArray, Category) => { if (typeof settings[updateFromBackendKey] === "function") api[updateFromBackendKey] = settings[updateFromBackendKey]; } } - - return api; + return { ...api, ...extraFunctions }; }; const createCategoryHook = (Category) => { return () => { const { settings } = useSettingsLogics(SETTINGS_ARRAY, Category); - const autoApi = buildCategoryApiFromSettings(settings, SETTINGS_ARRAY, Category); + const extraFunctions = useConfigFunctions(Category); + const autoApi = buildCategoryApiFromSettings(settings, SETTINGS_ARRAY, Category, extraFunctions); return { ...autoApi }; }; }; diff --git a/src-ui/useSettingsLogics.js b/src-ui/useSettingsLogics.js index 1429cd8a..613c17d4 100644 --- a/src-ui/useSettingsLogics.js +++ b/src-ui/useSettingsLogics.js @@ -185,3 +185,19 @@ export const useSettingsLogics = (settingsArray, Category) => { return { settings: result }; }; + + +export const useConfigFunctions = (Category) => { + const { asyncStdoutToPython } = useStdoutToPython(); + + switch (Category) { + case "Vr": + return { + sendTextToOverlay: (text) => { + asyncStdoutToPython("/run/send_text_overlay", text); + }, + }; + default: + return {}; + } +}; \ No newline at end of file