Skip to content

Commit f90a9c7

Browse files
authored
fix(android): gateway accent color is fetched but never applied to the app theme (#128702)
* fix(android): apply the gateway accent color to the Claw design theme The Android app fetched config.ui.seamColor into a StateFlow that no Compose surface consumed, so gateway accents were silently dropped. The accent now resolves with Control UI precedence (ui.prefs.accent over ui.seamColor) and overrides the Claw accent/accentSoft/accentBorder tokens in ShellScreen and OnboardingFlow; Material You system chrome is untouched. With no gateway accent set the hardcoded ClawDark/ClawLight palettes apply unchanged, replacing two mismatched hardcoded defaults. * fix(android): invoke branding refresh on connect and match gateway accent precedence ClawSweeper findings: refreshBrandingFromGateway had no call site (the accent state stayed null), and a present non-string user accent must not fall through to seamColor per the gateway's nullish selection. The refresh now runs in the post-connection coroutine alongside wake-word and exec-approval refreshes.
1 parent f8a52b9 commit f90a9c7

8 files changed

Lines changed: 116 additions & 17 deletions

File tree

‎apps/android/app/src/main/java/ai/openclaw/app/MainViewModel.kt‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -590,7 +590,7 @@ class MainViewModel private constructor(
590590
val healthLogsRefreshing: StateFlow<Boolean> = runtimeState(initial = false) { it.healthLogsRefreshing }
591591
val healthLogsErrorText: StateFlow<String?> = runtimeState(initial = null) { it.healthLogsErrorText }
592592
val pendingGatewayTrust: StateFlow<NodeRuntime.GatewayTrustPrompt?> = runtimeState(initial = null) { it.pendingGatewayTrust }
593-
val seamColorArgb: StateFlow<Long> = runtimeState(initial = 0xFF0EA5E9) { it.seamColorArgb }
593+
val gatewayAccentArgb: StateFlow<Long?> = runtimeState(initial = null) { it.gatewayAccentArgb }
594594
val mainSessionKey: StateFlow<String> = runtimeState(initial = "main") { it.mainSessionKey }
595595

596596
val cameraHud: StateFlow<CameraHudState?> = runtimeState(initial = null) { it.cameraHud }

‎apps/android/app/src/main/java/ai/openclaw/app/NodeRuntime.kt‎

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ import ai.openclaw.app.node.CameraCaptureManager
7272
import ai.openclaw.app.node.CameraHandler
7373
import ai.openclaw.app.node.ConnectionManager
7474
import ai.openclaw.app.node.ContactsHandler
75-
import ai.openclaw.app.node.DEFAULT_SEAM_COLOR_ARGB
7675
import ai.openclaw.app.node.DebugHandler
7776
import ai.openclaw.app.node.DeviceHandler
7877
import ai.openclaw.app.node.DeviceNotificationListenerService
@@ -91,8 +90,8 @@ import ai.openclaw.app.node.TalkHandler
9190
import ai.openclaw.app.node.asObjectOrNull
9291
import ai.openclaw.app.node.asStringOrNull
9392
import ai.openclaw.app.node.invokeErrorFromThrowable
94-
import ai.openclaw.app.node.parseHexColorArgb
9593
import ai.openclaw.app.node.readAndroidPermissionSnapshot
94+
import ai.openclaw.app.node.resolveGatewayAccentArgb
9695
import ai.openclaw.app.systemagent.SystemAgentChatController
9796
import ai.openclaw.app.systemagent.SystemAgentChatState
9897
import ai.openclaw.app.systemagent.SystemAgentGatewayAccess
@@ -1185,8 +1184,8 @@ class NodeRuntime private constructor(
11851184
private val _gatewayUpdateAvailable = MutableStateFlow<GatewayUpdateAvailableSummary?>(null)
11861185
val gatewayUpdateAvailable: StateFlow<GatewayUpdateAvailableSummary?> = _gatewayUpdateAvailable.asStateFlow()
11871186

1188-
private val _seamColorArgb = MutableStateFlow(DEFAULT_SEAM_COLOR_ARGB)
1189-
val seamColorArgb: StateFlow<Long> = _seamColorArgb.asStateFlow()
1187+
private val _gatewayAccentArgb = MutableStateFlow<Long?>(null)
1188+
val gatewayAccentArgb: StateFlow<Long?> = _gatewayAccentArgb.asStateFlow()
11901189
private val _modelCatalog = MutableStateFlow<List<GatewayModelSummary>>(emptyList())
11911190
val modelCatalog: StateFlow<List<GatewayModelSummary>> = _modelCatalog.asStateFlow()
11921191
private val _providerModelCatalog = MutableStateFlow<List<GatewayModelSummary>>(emptyList())
@@ -1407,7 +1406,7 @@ class NodeRuntime private constructor(
14071406
// Pairing capabilities require positive hello advertisement; an unknown catalog grants none.
14081407
_devicePairingCapabilities.value =
14091408
selectGatewayDevicePairingCapabilities(hello.methods.orEmpty(), operatorScopes)
1410-
_seamColorArgb.value = DEFAULT_SEAM_COLOR_ARGB
1409+
_gatewayAccentArgb.value = null
14111410
val mainSessionKey =
14121411
prepareMainSessionKey(resolveAgentIdFromMainSessionKey(hello.mainSessionKey))
14131412
// Create/adopt before history refresh; this keeps the first connected read on the
@@ -1426,6 +1425,7 @@ class NodeRuntime private constructor(
14261425
wearProxyBridge()?.publishConnection(connected = true, status = "Connected")
14271426
scope.launch {
14281427
subscribeOperatorSessionEvents()
1428+
refreshBrandingFromGateway()
14291429
refreshWakeWordsFromGateway()
14301430
refreshExecApprovalsFromGateway()
14311431
if (voiceReplySpeakerLazy.isInitialized()) {
@@ -1676,7 +1676,7 @@ class NodeRuntime private constructor(
16761676
replaceGatewayMethods(null)
16771677
_operatorScopes.value = emptyList()
16781678
_devicePairingCapabilities.value = GatewayDevicePairingCapabilities()
1679-
_seamColorArgb.value = DEFAULT_SEAM_COLOR_ARGB
1679+
_gatewayAccentArgb.value = null
16801680
_gatewayAgents.value = emptyList()
16811681
selectedChatAgentId = null
16821682
_modelCatalog.value = emptyList()
@@ -5532,11 +5532,9 @@ class NodeRuntime private constructor(
55325532
val res = requestGatewayData(gatewayScope, "config.get", "{}")
55335533
val root = json.parseToJsonElement(res).asObjectOrNull()
55345534
val config = root?.get("config").asObjectOrNull()
5535-
val ui = config?.get("ui").asObjectOrNull()
5536-
val raw = ui?.get("seamColor").asStringOrNull()?.trim()
5537-
val parsed = parseHexColorArgb(raw)
5535+
val parsed = resolveGatewayAccentArgb(config)
55385536
publishGatewayData(gatewayScope) {
5539-
_seamColorArgb.value = parsed ?: DEFAULT_SEAM_COLOR_ARGB
5537+
_gatewayAccentArgb.value = parsed
55405538
}
55415539
} catch (_: Throwable) {
55425540
// ignore

‎apps/android/app/src/main/java/ai/openclaw/app/node/NodeUtils.kt‎

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,6 @@ import kotlinx.serialization.json.JsonObject
88
import kotlinx.serialization.json.JsonPrimitive
99
import kotlinx.serialization.json.contentOrNull
1010

11-
/** Default canvas seam color used when gateway/user params omit a hex color. */
12-
const val DEFAULT_SEAM_COLOR_ARGB: Long = 0xFF4F7A9A
13-
1411
fun JsonElement?.asObjectOrNull(): JsonObject? = this as? JsonObject
1512

1613
/** Parses invoke params into a JSON object, returning null for absent/malformed input. */
@@ -78,6 +75,21 @@ fun parseHexColorArgb(raw: String?): Long? {
7875
return 0xFF000000L or rgb
7976
}
8077

78+
fun resolveGatewayAccentArgb(config: JsonObject?): Long? {
79+
val ui = config?.get("ui").asObjectOrNull()
80+
// Control UI precedence (gateway talk.config): a present user accent wins over the
81+
// operator seam color even when it is not a usable hex string; only an absent or
82+
// JSON-null accent falls through, matching the gateway's `??` selection.
83+
val chosen =
84+
ui
85+
?.get("prefs")
86+
.asObjectOrNull()
87+
?.get("accent")
88+
?.takeIf { it !is JsonNull }
89+
?: ui?.get("seamColor")
90+
return parseHexColorArgb((chosen as? JsonPrimitive)?.takeIf { it.isString }?.contentOrNull)
91+
}
92+
8193
/** Converts gateway invocation throwables into protocol code/message pairs. */
8294
fun invokeErrorFromThrowable(err: Throwable): Pair<String, String> {
8395
val parsed = parseInvokeErrorFromThrowable(err, fallbackMessage = "UNAVAILABLE: error")

‎apps/android/app/src/main/java/ai/openclaw/app/ui/OnboardingFlow.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,8 +410,9 @@ fun OnboardingFlow(
410410
modifier: Modifier = Modifier,
411411
) {
412412
val appearanceThemeMode by viewModel.appearanceThemeMode.collectAsState()
413+
val gatewayAccentArgb by viewModel.gatewayAccentArgb.collectAsState()
413414
val onboardingDark = appearanceThemeMode.isDark(systemDark = isSystemInDarkTheme())
414-
ClawDesignTheme(dark = onboardingDark) {
415+
ClawDesignTheme(dark = onboardingDark, accentArgb = gatewayAccentArgb) {
415416
val context = LocalContext.current
416417
val gatewayConnectionDisplay by viewModel.gatewayConnectionDisplay.collectAsState()
417418
val statusText = gatewayConnectionDisplay.statusText

‎apps/android/app/src/main/java/ai/openclaw/app/ui/ShellScreen.kt‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,9 +161,10 @@ fun ShellScreen(
161161
modifier: Modifier = Modifier,
162162
) {
163163
val appearanceThemeMode by viewModel.appearanceThemeMode.collectAsState()
164+
val gatewayAccentArgb by viewModel.gatewayAccentArgb.collectAsState()
164165
val shellDark = appearanceThemeMode.isDark(systemDark = isSystemInDarkTheme())
165166
OpenClawSystemBarAppearance(lightAppearance = !shellDark)
166-
ClawDesignTheme(dark = shellDark) {
167+
ClawDesignTheme(dark = shellDark, accentArgb = gatewayAccentArgb) {
167168
val nav = rememberSaveable(saver = ShellNavigation.Saver) { ShellNavigation() }
168169
var commandOpen by rememberSaveable { mutableStateOf(false) }
169170
var conversationScreenWasActive by rememberSaveable { mutableStateOf(false) }

‎apps/android/app/src/main/java/ai/openclaw/app/ui/design/ClawTheme.kt‎

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@ import androidx.compose.runtime.Immutable
1212
import androidx.compose.runtime.ReadOnlyComposable
1313
import androidx.compose.runtime.staticCompositionLocalOf
1414
import androidx.compose.ui.graphics.Color
15+
import androidx.compose.ui.graphics.compositeOver
16+
import androidx.compose.ui.graphics.lerp
1517
import androidx.compose.ui.text.TextStyle
1618
import androidx.compose.ui.text.font.Font
1719
import androidx.compose.ui.text.font.FontFamily
@@ -156,6 +158,19 @@ private val ClawLightColors =
156158
codeBorder = Color(0xFFD7DDE7),
157159
)
158160

161+
internal fun clawColorsForTheme(
162+
dark: Boolean,
163+
accentArgb: Long?,
164+
): ClawColors {
165+
val base = if (dark) ClawDarkColors else ClawLightColors
166+
val accent = accentArgb?.let(::Color) ?: return base
167+
return base.copy(
168+
accent = accent,
169+
accentSoft = accent.copy(alpha = if (dark) 0.25f else 0.08f).compositeOver(base.canvas),
170+
accentBorder = lerp(accent, Color.Black, 0.12f),
171+
)
172+
}
173+
159174
private val LocalClawColors = staticCompositionLocalOf { ClawDarkColors }
160175
private val LocalClawSpacing = staticCompositionLocalOf { ClawSpacing() }
161176
private val LocalClawRadii = staticCompositionLocalOf { ClawRadii() }
@@ -192,9 +207,10 @@ internal object ClawTheme {
192207
@Composable
193208
internal fun ClawDesignTheme(
194209
dark: Boolean = true,
210+
accentArgb: Long? = null,
195211
content: @Composable () -> Unit,
196212
) {
197-
val colors = if (dark) ClawDarkColors else ClawLightColors
213+
val colors = clawColorsForTheme(dark = dark, accentArgb = accentArgb)
198214
val typography = clawTypography(clawFontFamily)
199215

200216
CompositionLocalProvider(

‎apps/android/app/src/test/java/ai/openclaw/app/node/NodeUtilsTest.kt‎

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -62,4 +62,24 @@ class NodeUtilsTest {
6262
assertEquals(source, expected, parseJsonBooleanFlag(params, "includeAudio"))
6363
}
6464
}
65+
66+
@Test
67+
fun resolveGatewayAccentArgb_honorsUserPrecedenceAndHexFormats() {
68+
val cases =
69+
linkedMapOf(
70+
"""{"ui":{"prefs":{"accent":"#123456"},"seamColor":"#ABCDEF"}}""" to 0xFF123456L,
71+
"""{"ui":{"seamColor":"ABCDEF"}}""" to 0xFFABCDEFL,
72+
"""{"ui":{"prefs":{"accent":"invalid"},"seamColor":"#ABCDEF"}}""" to null,
73+
"""{"ui":{"prefs":{"accent":123},"seamColor":"#ABCDEF"}}""" to null,
74+
"""{"ui":{"prefs":{"accent":null},"seamColor":"#ABCDEF"}}""" to 0xFFABCDEFL,
75+
"""{"ui":{}}""" to null,
76+
"""{}""" to null,
77+
)
78+
79+
for ((source, expected) in cases) {
80+
val config = json.parseToJsonElement(source) as JsonObject
81+
assertEquals(source, expected, resolveGatewayAccentArgb(config))
82+
}
83+
assertNull(resolveGatewayAccentArgb(null))
84+
}
6585
}
Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,51 @@
1+
package ai.openclaw.app.ui.design
2+
3+
import androidx.compose.ui.graphics.Color
4+
import androidx.compose.ui.graphics.compositeOver
5+
import androidx.compose.ui.graphics.lerp
6+
import org.junit.Assert.assertEquals
7+
import org.junit.Assert.assertNotEquals
8+
import org.junit.Assert.assertSame
9+
import org.junit.Test
10+
11+
class ClawColorsTest {
12+
@Test
13+
fun nullAccentPreservesHardcodedDarkAndLightPalettes() {
14+
val expectedAccents =
15+
mapOf(
16+
true to Triple(Color(0xFF6EA8FF), Color(0xFF1A2A44), Color(0xFF5B93E8)),
17+
false to Triple(Color(0xFF1B5ACB), Color(0xFFEAF2FF), Color(0xFF174CA9)),
18+
)
19+
20+
for ((dark, expected) in expectedAccents) {
21+
val colors = clawColorsForTheme(dark = dark, accentArgb = null)
22+
23+
assertEquals(expected.first, colors.accent)
24+
assertEquals(expected.second, colors.accentSoft)
25+
assertEquals(expected.third, colors.accentBorder)
26+
assertSame(colors, clawColorsForTheme(dark = dark, accentArgb = null))
27+
}
28+
}
29+
30+
@Test
31+
fun gatewayAccentOverridesOnlyAccentTokensForBothPalettes() {
32+
val accent = Color(0xFFE84B35)
33+
34+
for (dark in listOf(true, false)) {
35+
val base = clawColorsForTheme(dark = dark, accentArgb = null)
36+
val colors = clawColorsForTheme(dark = dark, accentArgb = 0xFFE84B35L)
37+
38+
assertEquals(accent, colors.accent)
39+
assertEquals(accent.copy(alpha = if (dark) 0.25f else 0.08f).compositeOver(base.canvas), colors.accentSoft)
40+
assertEquals(lerp(accent, Color.Black, 0.12f), colors.accentBorder)
41+
assertNotEquals(accent, colors.accentSoft)
42+
assertNotEquals(accent, colors.accentBorder)
43+
assertNotEquals(base.accentSoft, colors.accentSoft)
44+
assertNotEquals(base.accentBorder, colors.accentBorder)
45+
assertEquals(
46+
base.copy(accent = colors.accent, accentSoft = colors.accentSoft, accentBorder = colors.accentBorder),
47+
colors,
48+
)
49+
}
50+
}
51+
}

0 commit comments

Comments
 (0)