@@ -132,32 +132,48 @@ public static void SetLocale(string localeKey)
132132 var app = Current as App ;
133133 var targetLocale = app . Resources [ localeKey ] as ResourceDictionary ;
134134 if ( targetLocale == null || targetLocale == app . _activeLocale )
135- {
136135 return ;
137- }
138136
139137 if ( app . _activeLocale != null )
140- {
141138 app . Resources . MergedDictionaries . Remove ( app . _activeLocale ) ;
142- }
143139
144140 app . Resources . MergedDictionaries . Add ( targetLocale ) ;
145141 app . _activeLocale = targetLocale ;
146142 }
147143
148- public static void SetTheme ( string theme )
144+ public static void SetTheme ( string theme , string colorsFile )
149145 {
146+ var app = Current as App ;
147+
150148 if ( theme . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) )
151- {
152- Current . RequestedThemeVariant = ThemeVariant . Light ;
153- }
149+ app . RequestedThemeVariant = ThemeVariant . Light ;
154150 else if ( theme . Equals ( "Dark" , StringComparison . OrdinalIgnoreCase ) )
151+ app . RequestedThemeVariant = ThemeVariant . Dark ;
152+ else
153+ app . RequestedThemeVariant = ThemeVariant . Default ;
154+
155+ if ( app . _colorOverrides != null )
155156 {
156- Current . RequestedThemeVariant = ThemeVariant . Dark ;
157+ app . Resources . MergedDictionaries . Remove ( app . _colorOverrides ) ;
158+ app . _colorOverrides = null ;
157159 }
158- else
160+
161+ if ( ! string . IsNullOrEmpty ( colorsFile ) && File . Exists ( colorsFile ) )
159162 {
160- Current . RequestedThemeVariant = ThemeVariant . Default ;
163+ try
164+ {
165+ var resDic = new ResourceDictionary ( ) ;
166+
167+ var schema = JsonSerializer . Deserialize ( File . ReadAllText ( colorsFile ) , JsonCodeGen . Default . DictionaryStringString ) ;
168+ foreach ( var kv in schema )
169+ resDic [ kv . Key ] = Color . Parse ( kv . Value ) ;
170+
171+ app . Resources . MergedDictionaries . Add ( resDic ) ;
172+ app . _colorOverrides = resDic ;
173+ }
174+ catch
175+ {
176+ }
161177 }
162178 }
163179
@@ -166,9 +182,7 @@ public static async void CopyText(string data)
166182 if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
167183 {
168184 if ( desktop . MainWindow . Clipboard is { } clipbord )
169- {
170185 await clipbord . SetTextAsync ( data ) ;
171- }
172186 }
173187 }
174188
@@ -256,7 +270,7 @@ public override void Initialize()
256270 var pref = ViewModels . Preference . Instance ;
257271
258272 SetLocale ( pref . Locale ) ;
259- SetTheme ( pref . Theme ) ;
273+ SetTheme ( pref . Theme , pref . ColorOverrides ) ;
260274 }
261275
262276 public override void OnFrameworkInitializationCompleted ( )
@@ -300,6 +314,7 @@ private static void ShowSelfUpdateResult(object data)
300314 }
301315
302316 private ResourceDictionary _activeLocale = null ;
317+ private ResourceDictionary _colorOverrides = null ;
303318 private Models . INotificationReceiver _notificationReceiver = null ;
304319 }
305320}
0 commit comments