From 4e5acd4ac33d585184207e75f787511699e30dfe Mon Sep 17 00:00:00 2001 From: misyaguziya <53165965+misyaguziya@users.noreply.github.com> Date: Tue, 13 Jan 2026 21:12:05 +0900 Subject: [PATCH] =?UTF-8?q?[Update]=20=E3=82=AF=E3=83=AA=E3=83=83=E3=83=97?= =?UTF-8?q?=E3=83=9C=E3=83=BC=E3=83=89=E6=A9=9F=E8=83=BD=E3=82=92=E7=B5=B1?= =?UTF-8?q?=E5=90=88=E3=81=97=E3=80=81=E3=82=B3=E3=83=94=E3=83=BC=E3=81=A8?= =?UTF-8?q?=E3=83=9A=E3=83=BC=E3=82=B9=E3=83=88=E3=82=92=E4=B8=80=E5=BA=A6?= =?UTF-8?q?=E3=81=AE=E5=91=BC=E3=81=B3=E5=87=BA=E3=81=97=E3=81=A7=E5=AE=9F?= =?UTF-8?q?=E8=A1=8C=E3=81=A7=E3=81=8D=E3=82=8B=E3=82=88=E3=81=86=E3=81=AB?= =?UTF-8?q?=E5=A4=89=E6=9B=B4?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src-python/controller.py | 8 +--- src-python/model.py | 15 +----- src-python/models/clipboard/clipboard.py | 59 +++++------------------- 3 files changed, 15 insertions(+), 67 deletions(-) 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