Skip to content

Derive states from MainActivity alias enabled#47

Merged
Goooler merged 13 commits intoderive-main-alias-statesfrom
copilot/update-hideappicon-default-value
Apr 10, 2026
Merged

Derive states from MainActivity alias enabled#47
Goooler merged 13 commits intoderive-main-alias-statesfrom
copilot/update-hideappicon-default-value

Conversation

Copy link
Copy Markdown

Copilot AI commented Mar 10, 2026

hideAppIcon defaulted to false regardless of the actual MainActivityAlias component state, causing the setting UI to show "not hidden" even when the alias was already disabled.

Changes

  • UiStore.kt: Replace defaultValue = false with a lazy defaultValueProvider lambda that calls PackageManager.getComponentEnabledSetting() on MainActivityAlias — defaults to true only when the component is neither COMPONENT_ENABLED_STATE_ENABLED nor COMPONENT_ENABLED_STATE_DEFAULT. The lookup is deferred until hideAppIcon is first read and the key is absent from preferences, avoiding unnecessary binder calls in non-UI paths (e.g., service start).
  • Store.kt: Added a boolean(key, defaultValueProvider: () -> Boolean) overload that invokes the supplier only when the key is not present in storage.
  • StoreProvider.kt / Providers.kt: Added contains(key) to the StoreProvider interface and implemented it in SharedPreferenceProvider.
// Before
var hideAppIcon: Boolean by store.boolean(
    key = "hide_app_icon",
    defaultValue = false
)

// After
var hideAppIcon: Boolean by store.boolean(
    key = "hide_app_icon",
    defaultValueProvider = {
        context.packageManager.getComponentEnabledSetting(
            ComponentName(context, context.mainActivityAlias)
        ).let { state ->
            state != PackageManager.COMPONENT_ENABLED_STATE_ENABLED &&
                state != PackageManager.COMPONENT_ENABLED_STATE_DEFAULT
        }
    },
)

COMPONENT_ENABLED_STATE_DEFAULT and COMPONENT_ENABLED_STATE_ENABLED both resolve to false (icon visible), matching the manifest default where the alias is enabled. All other states (including COMPONENT_ENABLED_STATE_DISABLED_USER and COMPONENT_ENABLED_STATE_DISABLED_UNTIL_USED) resolve to true (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.

Copilot AI changed the title [WIP] Update default value of hideAppIcon based on mainActivityAlias Use mainActivityAlias enabled state as default for hideAppIcon Mar 10, 2026
@Goooler Goooler marked this pull request as ready for review March 10, 2026 11:12
Co-authored-by: Goooler <10363352+Goooler@users.noreply.github.com>
@Goooler Goooler force-pushed the copilot/update-hideappicon-default-value branch from 6418245 to b9c3ca5 Compare April 10, 2026 04:19
@Goooler Goooler changed the title Use mainActivityAlias enabled state as default for hideAppIcon Derive states from MainActivity alias enabled Apr 10, 2026
@Goooler Goooler requested a review from Copilot April 10, 2026 07:09
@Goooler Goooler changed the base branch from main to derive-main-alias-states April 10, 2026 07:10
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.hideAppIcon default based on PackageManager.getComponentEnabledSetting() for MainActivityAlias.
  • Reuse hideAppIcon in MainApplication.setupShortcuts() to decide whether to clear dynamic shortcuts.
  • Replace the old mainActivityAlias top-level value with a Context.mainActivityAlias helper 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.

Comment on lines 30 to 35
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,
)
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@copilot apply changes based on this feedback

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Reverted.

Goooler and others added 2 commits April 10, 2026 15:15
…re.kt

Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@Goooler Goooler changed the title Derive states from MainActivity alias enabled Derive states from MainActivity alias enabling Apr 10, 2026
Copilot AI changed the title Derive states from MainActivity alias enabling Derive states from MainActivity alias enabled Apr 10, 2026
Copilot AI requested a review from Goooler April 10, 2026 07:24
Copy link
Copy Markdown

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +30 to +37
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
},
Copy link

Copilot AI Apr 10, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Copilot uses AI. Check for mistakes.
@Goooler Goooler merged commit cab6ff7 into derive-main-alias-states Apr 10, 2026
1 check passed
@Goooler Goooler deleted the copilot/update-hideappicon-default-value branch April 10, 2026 08:27
@Goooler
Copy link
Copy Markdown
Owner

Goooler commented Apr 10, 2026

Addressed to MetaCubeX#703.

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.

3 participants