fix: keep transcript in application field when target is absent
This commit is contained in:
parent
22da86bbfc
commit
cfddb0210e
|
|
@ -77,6 +77,10 @@ class ClipboardFallback:
|
|||
logger.warning(message)
|
||||
return ClipboardFallbackResult(success=False, error_message=message)
|
||||
|
||||
if target_window is None:
|
||||
logger.info("No target window was captured; clipboard fallback is a no-op for the application field.")
|
||||
return ClipboardFallbackResult(success=True, target_window=None, text_length=len(text), clipboard_restored=True)
|
||||
|
||||
validation = self._target_window_service.validate_target_window(target_window)
|
||||
if not validation.success or validation.target is None:
|
||||
message = validation.error_message or "The target window is not available."
|
||||
|
|
@ -174,6 +178,17 @@ class TextInjector:
|
|||
logger.warning(message)
|
||||
return TextInjectionResult(success=False, mode=normalized_mode, error_message=message)
|
||||
|
||||
if target_window is None:
|
||||
logger.info("No target window was captured; keeping transcript in the application field.")
|
||||
return TextInjectionResult(
|
||||
success=True,
|
||||
mode=normalized_mode,
|
||||
effective_mode="application",
|
||||
used_fallback=False,
|
||||
target_window=None,
|
||||
text_length=len(text),
|
||||
)
|
||||
|
||||
validation = self._target_window_service.validate_target_window(target_window)
|
||||
if not validation.success or validation.target is None:
|
||||
message = validation.error_message or "The target window is not available."
|
||||
|
|
|
|||
|
|
@ -135,3 +135,23 @@ def test_text_injector_reports_invalid_target_window() -> None:
|
|||
assert backend.activate_calls == []
|
||||
assert backend.send_calls == []
|
||||
assert fallback.calls == []
|
||||
|
||||
|
||||
|
||||
def test_text_injector_keeps_transcript_in_application_when_no_target_window_is_available() -> None:
|
||||
target_service = TargetWindowService(backend=FakeTargetBackend(handle=None), clock=lambda: 123.5)
|
||||
backend = FakeDirectTypingBackend()
|
||||
fallback = FakeClipboardFallback()
|
||||
injector = TextInjector(target_window_service=target_service, backend=backend, clipboard_fallback=fallback)
|
||||
|
||||
result = injector.inject_text("Hello world", target_window=None)
|
||||
|
||||
assert result.success
|
||||
assert result.mode == "direct_typing"
|
||||
assert result.effective_mode == "application"
|
||||
assert result.used_fallback is False
|
||||
assert result.target_window is None
|
||||
assert result.text_length == 11
|
||||
assert backend.activate_calls == []
|
||||
assert backend.send_calls == []
|
||||
assert fallback.calls == []
|
||||
|
|
|
|||
Loading…
Reference in New Issue