Skip to content

Fix PC-to-Android file transfer progress display using ConPTY#46

Open
yubingjiaocn wants to merge 1 commit into
T0biasCZe:masterfrom
yubingjiaocn:fix-progress-display-conpty
Open

Fix PC-to-Android file transfer progress display using ConPTY#46
yubingjiaocn wants to merge 1 commit into
T0biasCZe:masterfrom
yubingjiaocn:fix-progress-display-conpty

Conversation

@yubingjiaocn

@yubingjiaocn yubingjiaocn commented Jan 13, 2026

Copy link
Copy Markdown
Contributor

Summary

This PR fixes the progress bar not updating during PC-to-Android file transfers, and add x64 support.

This PR will close #44 and #43.

Problem

ADB suppresses progress output when stderr is not a TTY, causing the progress bar to remain at 0% during file transfers. The original DLL injection approach in the codebase was incomplete (HookDll.dll was never implemented).

Solution

Replace DLL injection with Windows ConPTY (Pseudo Console API) to create a virtual terminal that makes ADB output progress information.

Changes

  • Rewrite AdbProgressRunner to use ConPTY for terminal emulation
  • Add fallback to standard Process for systems without ConPTY support
  • Use regex to parse progress directly from output chunks
  • Add process cancellation support with taskkill and ADB server restart
  • Add IsCancelled flag to stop multi-file transfer queues when user closes progress dialog
  • Enable AnyCPU platform target (x64 support) since DLL injection is no longer needed
  • Refresh Android file list after PC-to-Android copy completes

Technical Details

  • ConPTY requires Windows 10 1809 (build 17763) or later
  • Uses P/Invoke for CreatePseudoConsole, CreateProcess with EXTENDED_STARTUPINFO_PRESENT flag
  • Progress regex pattern: [\s*(\d+)%]

Testing

Tested on Windows 11 (x64 build) with Xiaomi 14:

  • Single file transfer: Progress bar updates correctly from 0% to 100%
  • Multi-file transfer: Progress bar shows both total and per-file progress
  • Cancellation: Closing progress dialog stops current transfer and remaining queue
  • Device remains connected after cancellation (ADB server restart handles cleanup)

Generated with Claude Code

Problem:
ADB suppresses progress output when stderr is not a TTY, causing the
progress bar to never update during PC-to-Android file transfers.
The original DLL injection approach was incomplete (HookDll.dll was
never implemented).

Solution:
Replace DLL injection with Windows ConPTY (Pseudo Console API) to
create a virtual terminal that makes ADB output progress information.

Changes:
- Rewrite AdbProgressRunner to use ConPTY for terminal emulation
- Add fallback to standard Process for systems without ConPTY
- Use regex to parse progress directly from output chunks
- Add process cancellation support with taskkill and ADB server restart
- Add IsCancelled flag to stop multi-file transfer queues
- Enable AnyCPU platform target (x64 support) since DLL injection
  is no longer needed
- Refresh Android file list after PC-to-Android copy completes

Technical details:
- ConPTY requires Windows 10 1809 (build 17763) or later
- Uses P/Invoke for CreatePseudoConsole, CreateProcess with
  EXTENDED_STARTUPINFO_PRESENT flag
- Progress regex pattern: [\s*(\d+)%]

Tested on Windows 11 with Xiaomi 14.

Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
@yubingjiaocn
yubingjiaocn force-pushed the fix-progress-display-conpty branch from 134f562 to 9583c5f Compare January 13, 2026 04:20
@T0biasCZe

Copy link
Copy Markdown
Owner

Thank you for the commit, however, I already did the PC -> Android copying rewrite myself

And I thought about the ConPTY method myself back when I was writing the new copying, however as that would break compatibility with older versions of Windows I decided to instead use the dll injection method

@yubingjiaocn

yubingjiaocn commented Jan 14, 2026

Copy link
Copy Markdown
Contributor Author

For ConPTY issue, the code already has fallback logic:

In AdbProgressRunner.cs:

  if (IsConPtySupported()) {
      await RunWithConPtyAsync(adbPath, adbArgsString ?? string.Empty);
  }
  else {
      await RunWithProcessAsync(adbPath, adbArgsString ?? string.Empty);
  }

The IsConPtySupported() method at line 108-112 correctly detects Windows 10 1809+ and falls back to RunWithProcessAsync() on older systems. Unfortunately I can't use real system to test it.

Comparison of the two methods:

Feature RunWithConPtyAsync RunWithProcessAsync
File transfer Works Works
Progress display Real-time updates No progress (stays at 0%)
Requirements Windows 10 1809+ Any Windows

What users on older Windows versions will experience:

  1. File transfers still work correctly
  2. Progress dialog appears but shows 0% throughout the transfer
  3. Progress jumps to 100% when file completes
  4. Multi-file transfers show file count progress (e.g., "2/5 files") but not per-file percentage

This is the same behavior as before the ConPTY fix was implemented - the fallback preserves existing functionality for older systems while enabling real-time progress on Windows 10 1809+.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Progress bar still broken, and UI still freezes

2 participants