Skip to content

Conversation

@mathe00
Copy link
Contributor

@mathe00 mathe00 commented Nov 9, 2025

Fix race condition where AppReloader.restartApp() was called immediately after launching async restore, causing customizations to not be restored. Now wraps restore in withContext(Dispatchers.IO) and restarts only after DB writes complete. Added error handling for restore failures.

fixes #255

Type of Change

  • Bug Fix (user-facing)
  • Feature Request (user-facing)
  • Codebase Improvement (developer-facing)
  • Breaking Change (developer/user-facing)
  • Release (user-facing)
  • This change requires a documentation update

All Submissions

  • Checked for existing Pull Requests for the same update/change
  • Descriptive commit message with a short title
  • Self-reviewed code
  • Code comments, especially in complex areas
  • No new warnings or errors introduced
  • Changes made in a separate branch
  • Branch named with appropriate prefix (e.g., 'bug/', 'feat/', 'clean/', 'release/')

Before Opening Pull Request

Description of Changes

Changes Description

  1. Fixed race condition in AppReloader.restartApp() by ensuring async restore completes before app restart
  2. Wrapped database operations in withContext(Dispatchers.IO) to ensure proper thread handling
  3. Added comprehensive error handling for restore failures with appropriate user feedback
  4. Implemented proper synchronization between database writes and app restart sequence

Technical Details

The issue occurred when AppReloader.restartApp() was called immediately after launching the async restore process in MainActivity.kt. This led to a race condition where the app would restart before customizations were fully restored to the Room database.

The fix ensures:

  • All database operations are properly executed on the IO dispatcher
  • The app restart is triggered only after all database writes complete successfully
  • Users receive appropriate feedback when restore operations fail via toast message
  • No data corruption occurs during the restore-restart sequence

This PR addresses the race condition identified in issue #255 and implements the solution suggested by contributor @0xtanmoysamanta.

Test Device:

  • EasyLauncher version: Latest (v0.3.3)
  • Device name: N/A
  • Android version: Android 15
  • Other information: Successfully tested with backup files containing custom names, app ordering, hidden status, and favorite apps

Fix race condition where AppReloader.restartApp() was called immediately
after launching async restore, causing customizations to not be restored.
Now wraps restore in withContext(Dispatchers.IO) and restarts only after
DB writes complete. Added error handling for restore failures.
@mathe00
Copy link
Contributor Author

mathe00 commented Nov 9, 2025

I hope I've done everything right. This is my first real pull request/code contribution to a public project other than my own/my code. Please let me know if I've done anything wrong. 🙏

@CreativeCodeCat CreativeCodeCat merged commit 2b410a5 into CodeWorksCreativeHub:main Nov 9, 2025
1 check passed
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.

[Bug Report] App Customization Restore Doesn't Work - Race Condition on Restart

2 participants