From 3f39165b817ec85b2574faf8546ecd55c527b39c Mon Sep 17 00:00:00 2001 From: Meik Date: Thu, 5 Mar 2026 12:40:08 +0100 Subject: [PATCH] Honor WebAPI button colors without background override --- libs/configHelper.cs | 58 +++++++++++++++++++++++++++++++++++++------- 1 file changed, 49 insertions(+), 9 deletions(-) diff --git a/libs/configHelper.cs b/libs/configHelper.cs index b2169ed..f9829b5 100644 --- a/libs/configHelper.cs +++ b/libs/configHelper.cs @@ -234,6 +234,24 @@ namespace C4IT_CustomerPanel.libs return ((0.2126 * color.R) + (0.7152 * color.G) + (0.0722 * color.B)) / 255.0; } + private static bool TryGetConfiguredUiColor(Dictionary uiColors, string key, out Color color) + { + color = Colors.Transparent; + + if (uiColors == null || !uiColors.TryGetValue(key, out string rawColor) || string.IsNullOrWhiteSpace(rawColor)) + return false; + + try + { + color = ConverterHelper.ColorConvertFromString(rawColor); + return true; + } + catch + { + return false; + } + } + private static void ApplyBackgroundDerivedResources(Color baseColor) { bool isLightBackground = GetRelativeLuminance(baseColor) >= 0.55; @@ -1000,25 +1018,42 @@ namespace C4IT_CustomerPanel.libs { try { - Color backgroundColor = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["backgroundColor"]); - Color headerColor = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["headerColor"]); + var uiColors = cpConfig?._uiColors; + + Color backgroundColor = TryGetConfiguredUiColor(uiColors, "backgroundColor", out Color configuredBackground) + ? configuredBackground + : ConverterHelper.ColorConvertFromString(Properties.Resources.backgroundColor); + Color headerColor = TryGetConfiguredUiColor(uiColors, "headerColor", out Color configuredHeader) + ? configuredHeader + : ConverterHelper.ColorConvertFromString(Properties.Resources.headerColor); + + bool hasConfiguredActiveColor = TryGetConfiguredUiColor(uiColors, "activeButtonColor", out Color configuredActiveButtonColor); + bool hasConfiguredInactiveColor = TryGetConfiguredUiColor(uiColors, "inactiveButtonColor", out Color configuredInactiveButtonColor); System.Windows.Application.Current.Resources["headerColor"] = new SolidColorBrush(headerColor); ApplyBackgroundDerivedResources(backgroundColor); + + // Active/Inactive button colors must come directly from config (WebAPI), not be overridden by derived background shades. + System.Windows.Application.Current.Resources["activeButtonColor"] = new SolidColorBrush( + hasConfiguredActiveColor ? configuredActiveButtonColor : ConverterHelper.ColorConvertFromString(Properties.Resources.activeButtonColor)); + System.Windows.Application.Current.Resources["inactiveButtonColor"] = new SolidColorBrush( + hasConfiguredInactiveColor ? configuredInactiveButtonColor : ConverterHelper.ColorConvertFromString(Properties.Resources.inactiveButtonColor)); + ApplyHeaderDerivedResources(headerColor); + + LogEntry($"[Theme] activeButtonColor source={(hasConfiguredActiveColor ? "webapi" : "default")} value={((SolidColorBrush)System.Windows.Application.Current.Resources["activeButtonColor"]).Color}", LogLevels.Debug); } catch { - cpConfig._uiColors["inactiveButtonColor"] = Properties.Resources.inactiveButtonColor; - cpConfig._uiColors["backgroundColor"] = Properties.Resources.backgroundColor; - cpConfig._uiColors["headerColor"] = Properties.Resources.headerColor; - cpConfig._uiColors["activeButtonColor"] = Properties.Resources.activeButtonColor; - - Color fallbackBackground = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["backgroundColor"]); - Color fallbackHeader = (Color)ConverterHelper.ColorConvertFromString(cpConfig._uiColors["headerColor"]); + Color fallbackBackground = ConverterHelper.ColorConvertFromString(Properties.Resources.backgroundColor); + Color fallbackHeader = ConverterHelper.ColorConvertFromString(Properties.Resources.headerColor); + Color fallbackActive = ConverterHelper.ColorConvertFromString(Properties.Resources.activeButtonColor); + Color fallbackInactive = ConverterHelper.ColorConvertFromString(Properties.Resources.inactiveButtonColor); System.Windows.Application.Current.Resources["headerColor"] = new SolidColorBrush(fallbackHeader); ApplyBackgroundDerivedResources(fallbackBackground); + System.Windows.Application.Current.Resources["activeButtonColor"] = new SolidColorBrush(fallbackActive); + System.Windows.Application.Current.Resources["inactiveButtonColor"] = new SolidColorBrush(fallbackInactive); ApplyHeaderDerivedResources(fallbackHeader); } @@ -1349,6 +1384,11 @@ namespace C4IT_CustomerPanel.libs cpConfig = JsonConvert.DeserializeObject(json); cpConfig._encryptedApiToken = CustomerPanelSecurePassword.Instance.Decode(cpConfig._encryptedApiToken); + + if (cpConfig?._uiColors != null && cpConfig._uiColors.TryGetValue("activeButtonColor", out string apiActiveColor) && !string.IsNullOrWhiteSpace(apiActiveColor)) + LogEntry($"[Config API] activeButtonColor={apiActiveColor}", LogLevels.Debug); + else + LogEntry("[Config API] activeButtonColor missing or empty", LogLevels.Warning); } catch (Exception E) {