@@ -132,32 +132,48 @@ public static void SetLocale(string localeKey)
132
132
var app = Current as App ;
133
133
var targetLocale = app . Resources [ localeKey ] as ResourceDictionary ;
134
134
if ( targetLocale == null || targetLocale == app . _activeLocale )
135
- {
136
135
return ;
137
- }
138
136
139
137
if ( app . _activeLocale != null )
140
- {
141
138
app . Resources . MergedDictionaries . Remove ( app . _activeLocale ) ;
142
- }
143
139
144
140
app . Resources . MergedDictionaries . Add ( targetLocale ) ;
145
141
app . _activeLocale = targetLocale ;
146
142
}
147
143
148
- public static void SetTheme ( string theme )
144
+ public static void SetTheme ( string theme , string colorsFile )
149
145
{
146
+ var app = Current as App ;
147
+
150
148
if ( theme . Equals ( "Light" , StringComparison . OrdinalIgnoreCase ) )
151
- {
152
- Current . RequestedThemeVariant = ThemeVariant . Light ;
153
- }
149
+ app . RequestedThemeVariant = ThemeVariant . Light ;
154
150
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 )
155
156
{
156
- Current . RequestedThemeVariant = ThemeVariant . Dark ;
157
+ app . Resources . MergedDictionaries . Remove ( app . _colorOverrides ) ;
158
+ app . _colorOverrides = null ;
157
159
}
158
- else
160
+
161
+ if ( ! string . IsNullOrEmpty ( colorsFile ) && File . Exists ( colorsFile ) )
159
162
{
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
+ }
161
177
}
162
178
}
163
179
@@ -166,9 +182,7 @@ public static async void CopyText(string data)
166
182
if ( Current . ApplicationLifetime is IClassicDesktopStyleApplicationLifetime desktop )
167
183
{
168
184
if ( desktop . MainWindow . Clipboard is { } clipbord )
169
- {
170
185
await clipbord . SetTextAsync ( data ) ;
171
- }
172
186
}
173
187
}
174
188
@@ -256,7 +270,7 @@ public override void Initialize()
256
270
var pref = ViewModels . Preference . Instance ;
257
271
258
272
SetLocale ( pref . Locale ) ;
259
- SetTheme ( pref . Theme ) ;
273
+ SetTheme ( pref . Theme , pref . ColorOverrides ) ;
260
274
}
261
275
262
276
public override void OnFrameworkInitializationCompleted ( )
@@ -300,6 +314,7 @@ private static void ShowSelfUpdateResult(object data)
300
314
}
301
315
302
316
private ResourceDictionary _activeLocale = null ;
317
+ private ResourceDictionary _colorOverrides = null ;
303
318
private Models . INotificationReceiver _notificationReceiver = null ;
304
319
}
305
320
}
0 commit comments