|
@@ -3,7 +3,7 @@ using CommunityToolkit.Mvvm.ComponentModel;
|
|
|
namespace YZWater.Core.Services;
|
|
namespace YZWater.Core.Services;
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
-/// 涓婚鍒囨崲鏈嶅姟锛堢函鐘舵佺鐞嗭紝涓嶄緷璧 Avalonia锛
|
|
|
|
|
|
|
+/// 涓婚鍒囨崲鏈嶅姟
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
public partial class ThemeService : ObservableObject
|
|
public partial class ThemeService : ObservableObject
|
|
|
{
|
|
{
|
|
@@ -13,20 +13,39 @@ public partial class ThemeService : ObservableObject
|
|
|
[ObservableProperty]
|
|
[ObservableProperty]
|
|
|
private bool _isDarkTheme = false;
|
|
private bool _isDarkTheme = false;
|
|
|
|
|
|
|
|
- /// <summary>
|
|
|
|
|
- /// 涓婚鍙樻洿浜嬩欢锛堢敱 App.axaml.cs 璁㈤槄鎵ц瀹為檯鍒囨崲锛
|
|
|
|
|
- /// </summary>
|
|
|
|
|
public event Action? ThemeChanged;
|
|
public event Action? ThemeChanged;
|
|
|
|
|
|
|
|
private ThemeService() { }
|
|
private ThemeService() { }
|
|
|
|
|
|
|
|
/// <summary>
|
|
/// <summary>
|
|
|
- /// 鍒囨崲涓婚
|
|
|
|
|
|
|
+ /// 浠庨厤缃姞杞戒富棰樺亸濂
|
|
|
|
|
+ /// </summary>
|
|
|
|
|
+ public void LoadFromConfig()
|
|
|
|
|
+ {
|
|
|
|
|
+ var config = ConfigService.GetConfig();
|
|
|
|
|
+ if (config != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ IsDarkTheme = config.IsDarkTheme;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /// <summary>
|
|
|
|
|
+ /// 鍒囨崲涓婚骞朵繚瀛
|
|
|
/// </summary>
|
|
/// </summary>
|
|
|
public void ToggleTheme()
|
|
public void ToggleTheme()
|
|
|
{
|
|
{
|
|
|
IsDarkTheme = !IsDarkTheme;
|
|
IsDarkTheme = !IsDarkTheme;
|
|
|
- Console.WriteLine($"[ThemeService] ToggleTheme: IsDarkTheme={IsDarkTheme}");
|
|
|
|
|
|
|
+ SaveToConfig();
|
|
|
ThemeChanged?.Invoke();
|
|
ThemeChanged?.Invoke();
|
|
|
}
|
|
}
|
|
|
|
|
+
|
|
|
|
|
+ private void SaveToConfig()
|
|
|
|
|
+ {
|
|
|
|
|
+ var config = ConfigService.GetConfig();
|
|
|
|
|
+ if (config != null)
|
|
|
|
|
+ {
|
|
|
|
|
+ config.IsDarkTheme = IsDarkTheme;
|
|
|
|
|
+ ConfigService.SaveConfig();
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
}
|
|
}
|