Resolve start/stop toggle state race conditions on HomeScreen - #320
Merged
Merged
Conversation
There was a problem hiding this comment.
Pull request overview
This PR aims to eliminate race conditions from repeated start/stop toggles on the HomeScreen by introducing an explicit “transition in progress” UI/VM state and guarding the toggle action while service state changes are pending.
Changes:
- Added
UiState.isTransitioningtoHomeViewModel, with lifecycle-managed reset and a 10s timeout fallback. - Updated
HomeScreenstatus card to display a loading state (icon/text) and suppress toggling during transitions; reset transition state when VPN permission is cancelled. - Added a unit test to validate
isTransitioningtransitions across start/stop.
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.
| File | Description |
|---|---|
| ui/home/src/main/kotlin/com/github/kr328/clash/home/vm/HomeViewModel.kt | Introduces isTransitioning, transition timeout handling, and permission-denial reset to prevent repeated toggles during service state changes. |
| ui/home/src/main/kotlin/com/github/kr328/clash/home/ui/HomeScreen.kt | Renders a loading state on the status card during transitions and handles VPN permission cancellation by resetting transition state. |
| ui/home/src/test/kotlin/com/github/kr328/clash/home/vm/HomeViewModelTest.kt | Adds a test verifying isTransitioning flips on toggle and resets on clashRunning changes. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR resolves the issue where the start/stop status card toggling on the HomeScreen doesn't always take effect or can be clicked repeatedly, leading to race conditions in the background service.
Changes:
isTransitioninginHomeViewModel'sUiStateto disable toggle button clicking and display a Loading state (withTabbyIcons.BaselineSyncandCommonR.string.loading) when start/stop is in progress.whenexpression syntax.isTransitioningflow.