Skip to content

Fix NetworkOnMainThreadException when syncing library#20

Merged
chamika merged 2 commits into
mainfrom
fix/sync-network-on-main-thread
May 16, 2026
Merged

Fix NetworkOnMainThreadException when syncing library#20
chamika merged 2 commits into
mainfrom
fix/sync-network-on-main-thread

Conversation

@chamika
Copy link
Copy Markdown
Owner

@chamika chamika commented May 9, 2026

Summary

  • SuspendToFutureAdapter.launchFuture defaults to Dispatchers.Main, causing the Jellyfin SDK OkHttp request inside repository.sync() to run on the main thread
  • Wrap repository.sync() in withContext(Dispatchers.IO) so all network I/O happens off the main thread
  • Toast and SharedPreferences calls after the withContext block remain on Main as required

Test plan

  • Tap Sync in Settings — no NetworkOnMainThreadException crash
  • Sync completes and shows the success toast
  • Last synced timestamp updates in Settings

🤖 Generated with Claude Code

chamika and others added 2 commits May 9, 2026 18:12
SuspendToFutureAdapter.launchFuture runs on Dispatchers.Main by default,
causing the Jellyfin SDK OkHttp network call to block on the main thread.
Wrap repository.sync() in withContext(Dispatchers.IO) to move network I/O
off the main thread.

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
Fix NetworkOnMainThreadException when syncing library

Full release notes:

- Fix crash when tapping Sync in Settings (NetworkOnMainThreadException)

Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
@chamika chamika merged commit 8a96dee into main May 16, 2026
1 check passed
@chamika chamika deleted the fix/sync-network-on-main-thread branch May 16, 2026 23:21
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