From ff16c67086bec09a59f10d84ec3fc43717b60072 Mon Sep 17 00:00:00 2001 From: Wenxi Zeng Date: Thu, 26 Oct 2023 11:02:58 -0700 Subject: [PATCH] fix plugin update with initial state twice (#193) --- .../segment/analytics/kotlin/core/platform/Timeline.kt | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/com/segment/analytics/kotlin/core/platform/Timeline.kt b/core/src/main/java/com/segment/analytics/kotlin/core/platform/Timeline.kt index d2b5daa7..adbc1a1e 100644 --- a/core/src/main/java/com/segment/analytics/kotlin/core/platform/Timeline.kt +++ b/core/src/main/java/com/segment/analytics/kotlin/core/platform/Timeline.kt @@ -71,10 +71,18 @@ internal class Timeline { plugins[plugin.type]?.add(plugin) with(analytics) { analyticsScope.launch(analyticsDispatcher) { - val systemSettings = store.currentState(System::class)?.settings + val systemState = store.currentState(System::class) + val systemSettings = systemState?.settings systemSettings?.let { // if we have settings then update plugin with it plugin.update(it, Plugin.UpdateType.Initial) + + if (!systemState.initialSettingsDispatched) { + store.dispatch( + System.ToggleSettingsDispatch(dispatched = true), + System::class + ) + } } } }