diff --git a/src-python/controller.py b/src-python/controller.py index 99167a64..327752dd 100644 --- a/src-python/controller.py +++ b/src-python/controller.py @@ -424,8 +424,7 @@ class Controller: if config.ENABLE_CLIPBOARD is True: clipboard_message = self.messageFormatter("SEND", translation, message) - model.setCopyToClipboard(clipboard_message) - model.setPasteFromClipboard() + model.setCopyToClipboardAndPasteFromClipboard(clipboard_message) if model.checkWebSocketServerAlive() is True: model.websocketSendMessage( @@ -779,11 +778,6 @@ class Controller: ) model.updateOverlayLargeLog(overlay_image) - if config.ENABLE_CLIPBOARD is True: - clipboard_message = self.messageFormatter("SEND", translation, message) - model.setCopyToClipboard(clipboard_message) - model.setPasteFromClipboard() - if model.checkWebSocketServerAlive() is True: model.websocketSendMessage( { diff --git a/src-python/model.py b/src-python/model.py index bd989485..0933eb43 100644 --- a/src-python/model.py +++ b/src-python/model.py @@ -1299,11 +1299,11 @@ class Model: errorLogging() return False - def setCopyToClipboard(self, text:str) -> bool: + def setCopyToClipboardAndPasteFromClipboard(self, text:str) -> bool: self.ensure_initialized() try: if isinstance(self.clipboard, Clipboard): - self.clipboard.copy(text) + self.clipboard.copy_and_paste(text) return True else: return False @@ -1311,17 +1311,6 @@ class Model: errorLogging() return False - def setPasteFromClipboard(self) -> bool: - self.ensure_initialized() - try: - if isinstance(self.clipboard, Clipboard): - return self.clipboard.paste() - else: - return False - except Exception: - errorLogging() - return False - def telemetryInit(self, enabled: bool, app_version: str): """Model 内で Telemetry を初期化""" self.telemetry.init(enabled=enabled, app_version=app_version) diff --git a/src-python/models/clipboard/clipboard.py b/src-python/models/clipboard/clipboard.py index a26b536d..0760f2ae 100644 --- a/src-python/models/clipboard/clipboard.py +++ b/src-python/models/clipboard/clipboard.py @@ -139,7 +139,6 @@ def paste_via_pyautogui(countdown: int = 0) -> bool: class Clipboard: def __init__(self): - self.is_enabled = True self._vr_monitor_thread = None self._stop_monitoring = False self.app_name = None @@ -192,47 +191,7 @@ class Clipboard: printLog(f"Clipboard: Error setting up VR app name: {e}") self.app_name = None - def enable(self): - """Enable clipboard functionality. Reinitialize the class.""" - printLog("Clipboard: Enabling clipboard functionality.") - self.is_enabled = True - self._initialize() - - def disable(self): - """Disable clipboard functionality. Stop VR monitoring.""" - printLog("Clipboard: Disabling clipboard functionality.") - self.is_enabled = False - self._stop_monitoring = True - if self._vr_monitor_thread is not None and self._vr_monitor_thread.is_alive(): - self._vr_monitor_thread.join(timeout=1) - self._vr_monitor_thread = None - - def copy(self, message: str) -> bool: - """Copy `message` to clipboard. - - Args: - message: Text to copy. - - Returns: - True if copy succeeded, False otherwise. - """ - if not self.is_enabled: - return False - return copy_to_clipboard(message) - - def paste(self, window_name: str|None = None, countdown: int = 0) -> bool: - """Focus a window identified by `window_name`, then paste via Ctrl+V. - - Args: - window_name: Window title substring or process name to find and focus (Windows only). Required. - countdown: Seconds to wait before sending paste key. - - Returns: - True if paste command was sent, False otherwise. - """ - if not self.is_enabled: - return False - + def copy_and_paste(self, message: str, window_name: str|None = None, countdown: int = 0) -> bool: window_name = window_name if window_name is not None else self.app_name # If window_name is provided, attempt to focus it (Windows only). @@ -265,11 +224,17 @@ class Clipboard: # small delay to allow focus to settle time.sleep(0.2) - # paste - pasted = paste_via_pyautogui(countdown) - return bool(pasted) + # copy + copied = copy_to_clipboard(message) + if not copied: + printLog("copy_and_paste: failed to copy to clipboard") + return False + # paste + pasted = paste_via_pyautogui(countdown) + return bool(pasted) + else: + return False if __name__ == '__main__': clipboard = Clipboard() - clipboard.copy("Sample text to copy to clipboard.") - clipboard.paste(window_name=None, countdown=3) \ No newline at end of file + clipboard.copy_and_paste("Sample text to copy to clipboard.", window_name=None, countdown=3) \ No newline at end of file