Fix review comments from PRs and cleanups#147
Merged
Conversation
Agent-Logs-Url: https://github.com/Goooler/MihomoForAndroid/sessions/d0627b29-1c66-489f-b1c5-f651fcae1870 Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Goooler/MihomoForAndroid/sessions/d0627b29-1c66-489f-b1c5-f651fcae1870 Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
Copilot created this pull request from a session on behalf of
Goooler
April 27, 2026 02:03
View session
This reverts commit 16664c5.
There was a problem hiding this comment.
Pull request overview
This PR consolidates fixes responding to prior review feedback across multiple ViewModel refactor PRs, primarily around lifecycle/concurrency handling, background scoping, and a few UX/state correctness adjustments.
Changes:
- Replace ad-hoc
CoroutineScope(Dispatchers.IO)usages with the app-levelGlobalscope for “persist on dispose” operations in multiple settings ViewModels. - Improve lifecycle behavior in ViewModels: cancel/replace overlapping jobs (e.g., files fetch, proxy initial fetch) and adjust state updates to prevent repeated auto-save.
- Minor correctness/consistency fixes: restore
configurationEditablelogic, useAndroidViewModel.applicationfor string/resources, and localize the fallback “unknown” error in Properties.
Reviewed changes
Copilot reviewed 7 out of 7 changed files in this pull request and generated 1 comment.
Show a summary per file
| File | Description |
|---|---|
| app/src/main/kotlin/com/github/kr328/clash/settings/vm/OverrideSettingsViewModel.kt | Switch persist/reset override operations to Global.launch for non-viewModelScope work. |
| app/src/main/kotlin/com/github/kr328/clash/settings/vm/MetaFeatureSettingsViewModel.kt | Same Global.launch scoping change for persist/reset override operations. |
| app/src/main/kotlin/com/github/kr328/clash/settings/vm/AppSettingsViewModel.kt | Use AndroidViewModel.application property for component/icon operations. |
| app/src/main/kotlin/com/github/kr328/clash/settings/vm/AccessControlViewModel.kt | Use Global.launch for persist-on-dispose selection persistence/restart flow. |
| app/src/main/kotlin/com/github/kr328/clash/proxy/vm/ProxyViewModel.kt | Add initial-state job tracking and an initialized gate to avoid early ProfileLoaded handling; cancel/clear job on stop/clear. |
| app/src/main/kotlin/com/github/kr328/clash/profile/vm/PropertiesViewModel.kt | Prevent repeated auto-save by updating originalProfile on success; replace GlobalScope with Global; localize unknown-error fallback; use application for strings. |
| app/src/main/kotlin/com/github/kr328/clash/files/vm/FilesViewModel.kt | Restore configurationEditable condition; add cancel/replace for fetch job; move file operations to main-launched coroutines while keeping stack access on main. |
Comments suppressed due to low confidence (1)
app/src/main/kotlin/com/github/kr328/clash/files/vm/FilesViewModel.kt:156
fetch()cancels the previousfetchJob, but the launched coroutine catches allExceptions. When a job is canceled, it will typically throwCancellationException, which will be caught here and surfaced as an "Unknown error" message (and potentially overwrite a newer fetch result). Handle cancellation explicitly (rethrow/return onCancellationException) so normal cancel-and-replace doesn’t produce user-visible errors.
private fun fetch() {
fetchJob?.cancel()
val documentId = stack.lastOrNull() ?: root
if (root.isEmpty()) return
val inBaseDir = stack.isEmpty()
fetchJob = viewModelScope.launch {
try {
val files =
if (inBaseDir) {
val list = client.list(documentId)
val config = list.firstOrNull { it.id.endsWith("config.yaml") }
if (config == null || config.size > 0) list else listOf(config)
} else {
client.list(documentId)
}
uiState.update { it.copy(files = files, currentInBaseDir = inBaseDir) }
} catch (e: Exception) {
eventState.value = EventState.ShowMessage(e.message ?: "Unknown error")
}
}
💡 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.
Addresses Copilot review feedback across three ViewModel refactoring PRs (#143, #121, #127).
ProxyViewModel (#143)
nameIndexMapviaassociate {}instead ofindexOfper proxy (was O(groups × proxies))ReLaunchon init: added@Volatile initializedflag set at the end offetchInitialState();ProfileLoadedhandler early-returns until initializedfetchInitialStateJob, cancel-and-replace on eachonStart(), clear inonStop()/onCleared()FilesViewModel + FilesActivity (#121)
configurationEditableregression: restoreprofile.type == Profile.Type.Url(was incorrectly changed to!= Profile.Type.File)stackthread-safety:onDelete/onRename/onImportResult/onExportResultnow useviewModelScope.launch+withContext(Dispatchers.IO)sofetch()— and itsstackreads — always run on Mainfetch()now cancels the previousfetchJobbefore launching a new oneFilesActivityreplacescheckNotNull(intent.uuid)with a graceful earlyfinish()PropertiesViewModel (#127)
onStop()patch now calls.onSuccess { }to updateoriginalProfileand resethasUnsavedChanges, preventing re-patching on every subsequent stopGlobalScopeusage: replace withGlobal.launch(structured app-level scope used elsewhere in the codebase)"Unknown error"withR.string.unknownfor localization consistency