Skip to content

Conversation

@mdmohsin7
Copy link
Member

Summary

  • WiFi transfer cancel is now immediate: cancelSync() actively disconnects the TCP transport and completes the transfer completer instead of just setting a flag. UI state resets immediately; BLE reconnection happens in the background.
  • Replace hard 5-min timeout with 2-min inactivity timer: The old timeout would silently end after 5 minutes regardless of data flow. Now the timer resets on each data event, so slow transfers aren't killed prematurely, while stalled transfers are detected within 2 minutes.
  • Protect SD card data on partial transfers: Only clear SD card storage when the full file has been transferred (offset >= storageTotalBytes). Previously, partial transfers could mark as complete and wipe the SD card.
  • Wait for internet after WiFi transfer before cloud upload: After WiFi transfer via the device's AP, the phone has no internet. Added a connectivity wait loop before attempting cloud uploads, preventing immediate upload failures.

Test plan

  • Start WiFi transfer, tap cancel → transfer stops immediately, device reconnects via BLE
  • Start WiFi transfer, let it complete partially (e.g., disconnect device) → SD card data preserved, partial data saved locally
  • Start WiFi transfer with "Sync All", let it complete → cloud upload waits for internet before starting
  • Start WiFi transfer, minimize app briefly, return → transfer continues (inactivity timer resets on data)

🤖 Generated with Claude Code

mdmohsin7 and others added 2 commits February 9, 2026 17:48
- Cancel now actively disconnects TCP transport and completes the
  transfer completer for immediate teardown instead of just setting
  a flag
- Replace hard 5-minute timeout with 2-minute inactivity timer that
  resets on each data event, preventing premature timeout on slow
  transfers
- Only clear SD card when transfer is fully complete (offset >=
  totalBytes), preventing data loss on partial transfers
- Move UI state reset before BLE reconnection on cancel path for
  faster user feedback
- Add background BLE reconnect helper for cancel path

Co-Authored-By: Claude Opus 4.6 <[email protected]>
After WiFi transfer, the phone is connected to the device's WiFi AP
which has no internet. Add a wait loop that polls for internet
connectivity before attempting to upload files to the cloud, preventing
immediate upload failures.

Co-Authored-By: Claude Opus 4.6 <[email protected]>
Copy link
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

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

Code Review

The pull request effectively addresses several key areas to improve WiFi transfer reliability and user experience. The immediate cancellation of WiFi transfers, the introduction of an inactivity timer instead of a fixed timeout, and the protection of SD card data during partial transfers are all significant improvements. Additionally, the new logic to wait for internet connectivity after a WiFi transfer before attempting cloud uploads enhances the robustness of the synchronization process.

Comment on lines +1165 to +1166
_activeTcpTransport = null;
_activeTransferCompleter = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

These assignments are redundant as _resetSyncState() is called shortly after (line 1189), which already sets _activeTcpTransport and _activeTransferCompleter to null. Centralizing cleanup logic in _resetSyncState() improves maintainability.

References
  1. Prefer using existing helper functions over inlining their logic, especially when they handle complex cases like fallbacks or error handling. Inlining can introduce subtle bugs by missing parts of the original logic. In this case, redundant assignments are being made when an existing cleanup function already handles the state reset.

Comment on lines +1239 to +1240
_activeTcpTransport = null;
_activeTransferCompleter = null;
Copy link
Contributor

Choose a reason for hiding this comment

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

high

These assignments are redundant. The _cleanupWifiSync method, which is called in this catch block (line 1251), already invokes _resetSyncState() (line 751), which handles setting _activeTcpTransport and _activeTransferCompleter to null. Removing these duplicate assignments will make the code cleaner and prevent potential confusion.

References
  1. Prefer using existing helper functions over inlining their logic, especially when they handle complex cases like fallbacks or error handling. Inlining can introduce subtle bugs by missing parts of the original logic. In this case, redundant assignments are being made when an existing cleanup function already handles the state reset.

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.

1 participant