Skip to content

Conversation

@Coldaine
Copy link
Owner

@Coldaine Coldaine commented Oct 8, 2025

Summary

Part 6 of 9 in the domain-based refactor split.

Adds clipboard preservation and Wayland-first injection strategy with fallback chains.

Changes

Text Injection Crate (crates/coldvox-text-injection/**)

  • Clipboard preservation: Save and restore user clipboard after injection
  • Wayland-first strategy: AT-SPI → clipboard paste → ydotool fallback chain
  • Strategy management: Runtime backend selection with success metrics
  • Session tracking: Per-app injection strategy optimization

Backends

  • atspi_injector.rs: AT-SPI direct insertion (when available)
  • clipboard_paste_injector.rs: Clipboard + paste composite strategy
  • clipboard_injector.rs: Internal clipboard operations helper
  • ydotool_injector.rs: Wayland fallback via ydotool
  • kdotool_injector.rs: X11 support
  • enigo_injector.rs: Cross-platform fallback

Management

  • manager.rs: StrategyManager with per-app success tracking
  • session.rs: Injection session handling
  • window_manager.rs: Focus and window tracking
  • focus.rs: AT-SPI focus detection (currently short-circuited due to API regression)

Dependencies

Validation

cargo check --workspace --features text-injection
cargo test -p coldvox-text-injection
cargo run --example inject_demo --features text-injection
# Manual: Test clipboard preservation in real applications

Metrics

  • Files changed: 18
  • LOC: +823 -470 (net +353)
  • Size: ✅ Within target (300-500 LOC target, 1000 LOC max)

Review Notes

  • Clipboard preservation defaults to 500ms restore delay (configurable)
  • AT-SPI focus detection disabled pending upstream API fix
  • Fallback chain ensures injection works across all environments
  • Strategy manager learns best backend per application

Stack position: 6/9
Previous PR: #5 (app-runtime-wav)
Next PR: #7 (testing)

Copilot AI review requested due to automatic review settings October 8, 2025 06:24
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds clipboard preservation and introduces a Wayland-first strategy for text injection by consolidating clipboard and paste operations into a unified approach. The changes replace the separate clipboard and combo injectors with a streamlined ClipboardPasteInjector that saves/restores user clipboard content automatically.

Key changes:

  • Consolidates clipboard operations with automatic preservation and configurable restore delays
  • Implements unified clipboard+paste strategy with AT-SPI first, ydotool fallback approach
  • Simplifies strategy ordering to prioritize environment detection over complex backend detection
  • Removes separate allow_ydotool configuration as ydotool becomes an internal fallback mechanism

Reviewed Changes

Copilot reviewed 18 out of 18 changed files in this pull request and generated 3 comments.

Show a summary per file
File Description
ydotool_injector.rs Removes allow_ydotool configuration checks and simplifies availability detection
window_manager.rs Converts async window detection functions to synchronous operations and adds Sway support
types.rs Updates injection method enum, removes clipboard configuration options, adds fail-fast mode
test_*.rs Updates test files to use new ClipboardPasteFallback method and removes async calls
clipboard_paste_injector.rs New composite injector that combines clipboard setting with paste actions and automatic restoration
clipboard_injector.rs Refactors to internal helper with automatic clipboard preservation
manager.rs Major refactor to environment-first strategy ordering and simplified method registration
lib.rs Updates module exports to reflect new clipboard paste architecture
focus.rs Temporarily disables AT-SPI focus detection due to API changes
Documentation files Updates to reflect new clipboard preservation behavior and unified strategy approach


#[test]
fn test_x11_detection() {
fn test_x1_detection() {
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Corrected spelling of 'test_x1_detection' to 'test_x11_detection'.

Suggested change
fn test_x1_detection() {
fn test_x11_detection() {

Copilot uses AI. Check for mistakes.
let total_methods = method_order.len();

for method in method_order {
for method in method_order.clone() {
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary clone of method_order vector. The loop doesn't modify the vector, so the original can be used directly.

Suggested change
for method in method_order.clone() {
for method in method_order {

Copilot uses AI. Check for mistakes.
Comment on lines +23 to +24
use std::io::Write;
use std::process;
Copy link

Copilot AI Oct 8, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The std::io::Write and std::process imports are only used in the fail-fast error handling path. Consider moving these imports closer to their usage or making them conditional with #[cfg] attributes if they're only used in specific configurations.

Suggested change
use std::io::Write;
use std::process;

Copilot uses AI. Check for mistakes.
Copy link

@chatgpt-codex-connector chatgpt-codex-connector bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

💡 Codex Review

// Create injection configuration
let config = InjectionConfig {
allow_ydotool: true,
allow_kdotool: false,
allow_enigo: false,
restore_clipboard: true,

P1 Badge Update InjectionConfig usages after removing allow_ydotool/restore_clipboard

The commit drops the allow_ydotool and restore_clipboard fields from InjectionConfig, but call sites still initialize them in the demo and tests (InjectionConfig { allow_ydotool: true, … restore_clipboard: true, … }). With those struct members gone the example no longer compiles (struct InjectionConfig has no field named …), so cargo check --workspace will fail. These assignments need to be removed or migrated to whatever replaces those settings.

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting

- Remove unused combo_clip_atspi.rs file (dead code, no references)
- Deduplicate method ordering logic into compute_method_order() helper
- Link TODOs to tracking issues (#38, #40) and add context notes
- All tests pass (50 passed, 0 failed)

🤖 Generated with [Claude Code](https://claude.com/claude-code)

Co-Authored-By: Claude <[email protected]>
ColdVox Dev added 3 commits October 8, 2025 07:43
- Remove allow_ydotool field references (deleted in config refactor)
- Remove restore_clipboard field references (restoration now unconditional)
- Update combo_clip_ydotool.rs to always restore clipboard

Fixes compilation errors in:
- examples/inject_demo.rs
- crates/app/tests/integration/text_injection_integration_test.rs
- crates/app/tests/integration/mock_injection_tests.rs
- crates/coldvox-text-injection/src/combo_clip_ydotool.rs
Base automatically changed from 05-app-runtime-wav to main October 8, 2025 13:33
@Coldaine Coldaine merged commit 3a33c53 into main Oct 8, 2025
0 of 6 checks passed
@Coldaine Coldaine deleted the 06-text-injection branch October 8, 2025 13:35
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants