Skip to content

Expose UiStore states as Flow#177

Merged
Goooler merged 4 commits into
trunkfrom
ui-store-flow
May 1, 2026
Merged

Expose UiStore states as Flow#177
Goooler merged 4 commits into
trunkfrom
ui-store-flow

Conversation

@Goooler
Copy link
Copy Markdown
Owner

@Goooler Goooler commented May 1, 2026

No description provided.

Comment thread app/src/main/kotlin/com/github/kr328/clash/store/UiStore.kt Outdated
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 updates the UI theming pipeline to react to UiStore preference changes via a Flow, so theme changes (notably dark mode) can propagate without explicitly recreating the current Activity.

Changes:

  • Add UiStore.valueState: StateFlow<ValueState> driven by SharedPreferences change callbacks.
  • Update MainActivity to collect uiStore.valueState and feed darkMode into MihomoTheme.
  • Remove the manual Activity.recreate() workaround on dark mode changes in AppSettingsScreen, and simplify MihomoTheme to accept DarkMode directly.

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 3 comments.

File Description
app/src/main/kotlin/com/github/kr328/clash/ui/theme/Theme.kt Removes internal UiStore creation; theme now depends on a passed-in DarkMode.
app/src/main/kotlin/com/github/kr328/clash/store/UiStore.kt Introduces valueState as a StateFlow reflecting current preference values.
app/src/main/kotlin/com/github/kr328/clash/settings/ui/AppSettingsScreen.kt Removes Activity.recreate() on dark mode changes; delegates directly to the ViewModel updater.
app/src/main/kotlin/com/github/kr328/clash/MainActivity.kt Collects uiStore.valueState and wires darkMode into MihomoTheme.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread app/src/main/kotlin/com/github/kr328/clash/store/UiStore.kt Outdated
Comment thread app/src/main/kotlin/com/github/kr328/clash/store/UiStore.kt Outdated
Comment thread app/src/main/kotlin/com/github/kr328/clash/MainActivity.kt
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 +19 to +22
private val _valueState by unsafeLazy {
val flow = MutableStateFlow(readValueState())
preferences.registerOnSharedPreferenceChangeListener { _, _ -> flow.value = readValueState() }
flow
Copy link

Copilot AI May 1, 2026

Choose a reason for hiding this comment

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

valueState registers a SharedPreferences change listener via a lambda, but the listener instance isn’t retained and therefore cannot be unregistered. Any UiStore instance whose valueState is accessed will be kept alive by SharedPreferences, and if multiple UiStore instances are created over time (e.g., MainActivity recreation), listeners will accumulate and all of them will recompute readValueState() on every preference change. Consider storing the listener in a property and providing a way to unregister it (lifecycle-aware close()), or exposing valueState via a callbackFlow { ... awaitClose { unregister } } / shareIn so it’s automatically cleaned up when no longer collected.

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

Choose a reason for hiding this comment

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

This is fine.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

@Goooler Goooler merged commit 8ed31a3 into trunk May 1, 2026
7 checks passed
@Goooler Goooler deleted the ui-store-flow branch May 1, 2026 09:57
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.

2 participants