Derive states from MainActivity alias enabled#47
Derive states from MainActivity alias enabled#47Goooler merged 13 commits intoderive-main-alias-statesfrom
Conversation
Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
6418245 to
b9c3ca5
Compare
There was a problem hiding this comment.
Pull request overview
This PR fixes the settings UI showing an incorrect “app icon hidden” state by deriving the hideAppIcon default from the launcher alias component’s enabled state instead of always defaulting to false.
Changes:
- Compute
UiStore.hideAppIcondefault based onPackageManager.getComponentEnabledSetting()forMainActivityAlias. - Reuse
hideAppIconinMainApplication.setupShortcuts()to decide whether to clear dynamic shortcuts. - Replace the old
mainActivityAliastop-level value with aContext.mainActivityAliashelper and update imports/usages.
Reviewed changes
Copilot reviewed 4 out of 4 changed files in this pull request and generated 4 comments.
| File | Description |
|---|---|
| design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt | Derives hideAppIcon default from launcher alias component state; introduces Context.mainActivityAlias. |
| app/src/main/java/com/github/kr328/clash/MainApplication.kt | Switches shortcut setup gating to use UiStore.hideAppIcon. |
| app/src/main/java/com/github/kr328/clash/MainActivity.kt | Removes the old mainActivityAlias top-level property. |
| app/src/main/java/com/github/kr328/clash/AppSettingsActivity.kt | Imports the new mainActivityAlias helper for component enable/disable. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt
Outdated
Show resolved
Hide resolved
| var hideAppIcon: Boolean by store.boolean( | ||
| key = "hide_app_icon", | ||
| defaultValue = false | ||
| defaultValue = context.packageManager.getComponentEnabledSetting( | ||
| ComponentName(context, context.mainActivityAlias) | ||
| ) == PackageManager.COMPONENT_ENABLED_STATE_DISABLED, | ||
| ) |
There was a problem hiding this comment.
This PackageManager.getComponentEnabledSetting(...) call is evaluated eagerly every time UiStore is constructed (because defaultValue is computed before it reaches the delegate). UiStore is created in non-UI paths (e.g., service start), so this adds an extra binder call even when hideAppIcon is never read. Consider deferring this lookup until the hide_app_icon key is actually read/missing (e.g., a specialized property getter, or a delegate that accepts a default-value supplier).
There was a problem hiding this comment.
Done in eb1245b. Added a boolean(key, defaultValueProvider: () -> Boolean) overload to Store and a contains(key) method to StoreProvider/SharedPreferenceProvider. The defaultValueProvider lambda is only invoked when the key is absent from SharedPreferences, so the PackageManager.getComponentEnabledSetting() call is deferred until hideAppIcon is actually read and only runs when no stored preference exists.
…re.kt Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Agent-Logs-Url: https://github.com/Goooler/ClashMetaForAndroid/sessions/69047dd6-90d5-4bb0-9b54-04e77f35c156 Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
This reverts commit eb1245b.
There was a problem hiding this comment.
Pull request overview
Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| var hideAppIcon: Boolean by store.boolean( | ||
| key = "hide_app_icon", | ||
| defaultValue = false | ||
| defaultValue = context.packageManager.getComponentEnabledSetting( | ||
| ComponentName(context, context.mainActivityAlias) | ||
| ).let { state -> | ||
| state != PackageManager.COMPONENT_ENABLED_STATE_ENABLED && | ||
| state != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT | ||
| }, |
There was a problem hiding this comment.
defaultValue is computed eagerly when UiStore is constructed, so PackageManager.getComponentEnabledSetting(...) (a binder call) will run even when hideAppIcon is never read (e.g., Context.startClashService() constructs UiStore just to read enableVpn). To avoid this overhead, the component-state lookup needs to be deferred until the hide_app_icon key is actually read and missing (e.g., add a defaultValueProvider/contains(key) mechanism in Store, or move the lookup into a custom getter for hideAppIcon).
This reverts commit df96231.
design/src/main/java/com/github/kr328/clash/design/store/UiStore.kt
Outdated
Show resolved
Hide resolved
|
Addressed to MetaCubeX#703. |
hideAppIcondefaulted tofalseregardless of the actualMainActivityAliascomponent state, causing the setting UI to show "not hidden" even when the alias was already disabled.Changes
UiStore.kt: ReplacedefaultValue = falsewith a lazydefaultValueProviderlambda that callsPackageManager.getComponentEnabledSetting()onMainActivityAlias— defaults totrueonly when the component is neitherCOMPONENT_ENABLED_STATE_ENABLEDnorCOMPONENT_ENABLED_STATE_DEFAULT. The lookup is deferred untilhideAppIconis first read and the key is absent from preferences, avoiding unnecessary binder calls in non-UI paths (e.g., service start).Store.kt: Added aboolean(key, defaultValueProvider: () -> Boolean)overload that invokes the supplier only when the key is not present in storage.StoreProvider.kt/Providers.kt: Addedcontains(key)to theStoreProviderinterface and implemented it inSharedPreferenceProvider.COMPONENT_ENABLED_STATE_DEFAULTandCOMPONENT_ENABLED_STATE_ENABLEDboth resolve tofalse(icon visible), matching the manifest default where the alias is enabled. All other states (includingCOMPONENT_ENABLED_STATE_DISABLED_USERandCOMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) resolve totrue(icon hidden).🔒 GitHub Advanced Security automatically protects Copilot coding agent pull requests. You can protect all pull requests by enabling Advanced Security for your repositories. Learn more about Advanced Security.