-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
feat(feature-flag): enable runtime feature flag change #10103
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(feature-flag): enable runtime feature flag change #10103
Conversation
4d7bd2d to
579ebc2
Compare
579ebc2 to
cbf6eb7
Compare
wmontwe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the MutableFeatureFlagFactory mixes "define flags" and "mutate runtime overrides" in a way that feels hard to follow.
When the goal is that the factory defines the flags and their defaults while there is an optional runtime override, the best would be to keep "defaults" and "overrides" apart.
Rough idea:
interface FeatureFlagFactory {
fun createCatalog(): List<FeatureFlag>
}
interface FeatureFlagOverrides {
fun getAll(): Map<FeatureFlagKey, Boolean>
fun get(key: FeatureFlagKey): Boolean?
fun set(key: FeatureFlagKey, enabled: Boolean)
fun clear(key: FeatureFlagKey)
fun clearAll()
}
class InMemoryFeatureFlagProvider(
private val factory: FeatureFlagFactory,
private val overrides: FeatureFlagOverrides,
): FeatureFlagProvider {
// cache defaults privately
fun provide(key: FeatureFlagKey): FeatureFlagResult {
// answer from overrides first then fallback to defaults
}
}Then there could be a "in-memory" and a "no-op" version of FeatureFlagOverrides and injected based on the build type. This would allow us to use the override in daily too.
UI:
When changing a flag twice, the ui shows the modified indicator even when the setting returned to it's default state and requires to apply the changes. But there is no change to the defaults.
Design system additions are a good candidate for a separate PR.
...reflag/src/commonMain/kotlin/net/thunderbird/core/featureflag/InMemoryFeatureFlagProvider.kt
Outdated
Show resolved
Hide resolved
...ag/src/commonTest/kotlin/net/thunderbird/core/featureflag/InMemoryFeatureFlagProviderTest.kt
Show resolved
Hide resolved
...reflag/src/commonMain/kotlin/net/thunderbird/core/featureflag/InMemoryFeatureFlagProvider.kt
Show resolved
Hide resolved
.../designsystem/src/main/kotlin/net/thunderbird/core/ui/compose/designsystem/atom/pager/Tab.kt
Outdated
Show resolved
Hide resolved
...system/src/main/kotlin/net/thunderbird/core/ui/compose/designsystem/atom/tab/TabSecondary.kt
Show resolved
Hide resolved
...system/src/main/kotlin/net/thunderbird/core/ui/compose/designsystem/molecule/pager/TabRow.kt
Outdated
Show resolved
Hide resolved
...ain/kotlin/net/thunderbird/core/ui/compose/designsystem/template/pager/HorizontalTabPager.kt
Outdated
Show resolved
Hide resolved
I have moved the implementation of the Horizontal Pager to the PR #10131. Also included the implementation for the HorizontalPagerPrimary |
cbf6eb7 to
fddbc53
Compare
|
Hi @wmontwe, I've changed the implementation to something close to your suggestion. Please take a look and let me know if it is better now. |
501101f to
3810694
Compare
wmontwe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I left some comments.
Non-blocking: this sparks an idea around reactive feature flags. Probably a separate task.
interface FeatureFlagFactory {
fun createFeatureCatalog(): List<FeatureFlag>
}
// Change to:
interface FeatureCatalogProvider {
fun getCatalog: Flow<List<FeatureFlag>>
}then
class InMemoryFeatureFlagProvider(
featureCatalogProvider: FeatureCatalogProvider,
featureFlagOverrides: FeatureFlagOverrides,
mainDispatcher: CoroutineDispatcher = Dispatchers.Main,
scope: CoroutineScope = CoroutineScope(SupervisorJob() + mainDispatcher),
) : FeatureFlagProvider {
private val combinedFlags: StateFlow<Map<FeatureFlagKey, FeatureFlag>> =
combine(
featureCatalogProvider.getCatalog(),
featureFlagOverrides.overrides,
) { defaultsList, overridesMap ->
val defaults = defaultsList.associateBy { it.key }
val overrides = overridesMap.mapValues {
FeatureFlag(key = it.key, enabled = it.value)
}
defaults + overrides
}.stateIn(
scope = scope,
started = SharingStarted.Eagerly,
initialValue = emptyMap(),
)
override fun provide(key: FeatureFlagKey): FeatureFlagResult {
val enabled: Boolean? = combinedFlags.value[key]?.enabled
return when (enabled) {
null -> FeatureFlagResult.Unavailable
true -> FeatureFlagResult.Enabled
false -> FeatureFlagResult.Disabled
}
}
}
...reflag/src/commonMain/kotlin/net/thunderbird/core/featureflag/InMemoryFeatureFlagProvider.kt
Outdated
Show resolved
Hide resolved
...reflag/src/commonMain/kotlin/net/thunderbird/core/featureflag/InMemoryFeatureFlagProvider.kt
Show resolved
Hide resolved
...reflag/src/commonMain/kotlin/net/thunderbird/core/featureflag/InMemoryFeatureFlagProvider.kt
Outdated
Show resolved
Hide resolved
...reflag/src/commonMain/kotlin/net/thunderbird/core/featureflag/InMemoryFeatureFlagProvider.kt
Show resolved
Hide resolved
… interface to data class with enum for selected tab
3810694 to
13bae97
Compare
wmontwe
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you!
Resolves #10102.
Depends on #10131
This PR introduces the capability to enable and disable feature flags during runtime execution via the Secret debug screen.
Changes summary
AccountSetupFinishedLaunchertoMessageListLauncherScreen Recording
Screen.Recording.2025-11-13.at.8.56.57.AM.mp4