Conversation
This commit introduces a major refactoring of the manager's data and state management by implementing the repository pattern and migrating from mutable `State` objects to `StateFlow` and `UiState` data classes in the ViewModels.
- **Introduce Repository Pattern:**
- Create `repository` and `model` packages to decouple data sources from the UI layer.
- Implement `SuperUserRepository`, `ModuleRepository`, `ModuleRepoRepository`, and `TemplateRepository` to handle data fetching and business logic.
- Move data fetching logic (local and remote) from ViewModels into these new repository classes.
- **State Management with `StateFlow` and `UiState`:**
- Replace individual `mutableStateOf` properties in `SuperUserViewModel`, `ModuleViewModel`, `ModuleRepoViewModel`, and `TemplateViewModel` with a single `UiState` data class per ViewModel.
- Use `StateFlow` to expose the `UiState`, providing a single source of truth for the UI and improving state predictability.
- Update Composable screens to collect state from the `uiState` `StateFlow`.
- **SuperUser Screen Enhancements:**
- The logic for grouping and sorting applications is now centralized within `SuperUserViewModel`.
- `GroupedApps` now includes a pre-calculated `ownerName` to simplify UI logic.
- Improved label and package name display by using `TextOverflow.Ellipsis` instead of `basicMarquee`.
- App list updates, including filtering and sorting, are now handled more efficiently.
- **Performance & Caching:**
- Add `AppIconCache` to implement a memory-based `LruCache` for application icons.
- This improves scrolling performance and reduces redundant icon loading, especially for high-resolution icons.
- **Minor Fixes & Cleanups:**
- Simplify logic in `ExecuteModuleAction.kt` and `WebViewHelper.kt` by directly using repositories.
- Corrected the application of the `enable_blur` setting in the settings screen.
u9521
suggested changes
Mar 1, 2026
u9521
reviewed
Mar 1, 2026
java.lang.IllegalStateException: This method can only be called on the main thread
at com.topjohnwu.superuser.internal.RootServiceManager.enforceMainThread(RootServiceManager.java:122)
at com.topjohnwu.superuser.internal.RootServiceManager.unbind(RootServiceManager.java:299)
at com.topjohnwu.superuser.ipc.RootService.unbind(RootService.java:157)
at me.weishu.kernelsu.ui.viewmodel.SuperUserViewModel.fetchAppList$lambda$0$reconnect(SuperUserViewModel.kt:208)
at me.weishu.kernelsu.ui.viewmodel.SuperUserViewModel.access$fetchAppList$lambda$0$reconnect(SuperUserViewModel.kt:41)
at me.weishu.kernelsu.ui.viewmodel.SuperUserViewModel$fetchAppList$2$allPackagesSlice$1.invokeSuspend(SuperUserViewModel.kt:224)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:34)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:100)
at kotlinx.coroutines.internal.LimitedDispatcher$Worker.run(LimitedDispatcher.kt:124)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:89)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:586)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:820)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:717)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:704)
Suppressed: kotlinx.coroutines.internal.DiagnosticCoroutineContextException: [StandaloneCoroutine{Cancelling}@57a530e, Dispatchers.Main.immediate]
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 commit introduces a major refactoring of the manager's data and state management by implementing the repository pattern and migrating from mutable
Stateobjects toStateFlowandUiStatedata classes in the ViewModels.Introduce Repository Pattern:
repositoryandmodelpackages to decouple data sources from the UI layer.SuperUserRepository,ModuleRepository,ModuleRepoRepository, andTemplateRepositoryto handle data fetching and business logic.State Management with
StateFlowandUiState:mutableStateOfproperties inSuperUserViewModel,ModuleViewModel,ModuleRepoViewModel, andTemplateViewModelwith a singleUiStatedata class per ViewModel.StateFlowto expose theUiState, providing a single source of truth for the UI and improving state predictability.uiStateStateFlow.SuperUser Screen Enhancements:
SuperUserViewModel.GroupedAppsnow includes a pre-calculatedownerNameto simplify UI logic.TextOverflow.Ellipsisinstead ofbasicMarquee.Performance & Caching:
AppIconCacheto implement a memory-basedLruCachefor application icons.Minor Fixes & Cleanups:
ExecuteModuleAction.ktandWebViewHelper.ktby directly using repositories.enable_blursetting in the settings screen.