diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs index 5b4bada8..67949e07 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/WindowController.cs @@ -122,13 +122,17 @@ internal sealed class WindowController private void OnOptionsPropertyChanged(object? sender, PropertyChangedEventArgs e) { - if (e.PropertyName is nameof(AppOptions.BackdropType)) + if (sender is not AppOptions options) { - if (sender is AppOptions options) - { - UpdateSystemBackdrop(options.BackdropType); - } + return; } + + _ = e.PropertyName switch + { + nameof(AppOptions.BackdropType) => UpdateSystemBackdrop(options.BackdropType), + nameof(AppOptions.ElementTheme) => UpdateElementTheme(options.ElementTheme), + _ => false, + }; } private void OnWindowClosed(object sender, WindowEventArgs args) @@ -158,7 +162,7 @@ internal sealed class WindowController } } - private void UpdateSystemBackdrop(BackdropType backdropType) + private bool UpdateSystemBackdrop(BackdropType backdropType) { window.SystemBackdrop = backdropType switch { @@ -168,6 +172,15 @@ internal sealed class WindowController BackdropType.Acrylic => new DesktopAcrylicBackdrop(), _ => null, }; + + return true; + } + + private bool UpdateElementTheme(ElementTheme theme) + { + ((FrameworkElement)window.Content).RequestedTheme = theme; + + return true; } private void UpdateTitleButtonColor() diff --git a/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs b/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs index 9b70a6db..1263d84f 100644 --- a/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs +++ b/src/Snap.Hutao/Snap.Hutao/Model/Entity/SettingEntry.Constant.cs @@ -13,6 +13,7 @@ internal sealed partial class SettingEntry public const string Culture = "Culture"; public const string SystemBackdropType = "SystemBackdropType"; + public const string ElementTheme = "ElementTheme"; public const string BackgroundImageType = "BackgroundImageType"; public const string AnnouncementRegion = "AnnouncementRegion"; diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.en.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.en.resx index 06220390..4c03eb10 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.en.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.en.resx @@ -60,45 +60,45 @@ : and then encoded with base64 encoding. --> - + - + - - - - + + + + - - + + - - + + - - - - + + + + - + - + @@ -186,6 +186,15 @@ No WebView2 Runtime detected + + Dark + + + Light + + + System + Export diff --git a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx index 2450ca89..eead6b9d 100644 --- a/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx +++ b/src/Snap.Hutao/Snap.Hutao/Resource/Localization/SH.resx @@ -189,6 +189,15 @@ [{0}] 热键 [{1}] 注册失败 + + 深色 + + + 浅色 + + + 跟随系统 + 导出 @@ -2627,6 +2636,12 @@ 评价软件 + + 更改窗体的颜色主题 + + + 颜色主题 + 贡献翻译 diff --git a/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs b/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs index 34a082be..b09b066b 100644 --- a/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs +++ b/src/Snap.Hutao/Snap.Hutao/Service/AppOptions.cs @@ -1,6 +1,7 @@ // Copyright (c) DGP Studio. All rights reserved. // Licensed under the MIT license. +using Microsoft.UI.Xaml; using Snap.Hutao.Core.Windowing; using Snap.Hutao.Model; using Snap.Hutao.Model.Entity; @@ -16,6 +17,7 @@ internal sealed partial class AppOptions : DbStoreOptions { private bool? isEmptyHistoryWishVisible; private BackdropType? backdropType; + private ElementTheme? elementTheme; private BackgroundImageType? backgroundImageType; private Region? region; private string? geetestCustomCompositeUrl; @@ -34,6 +36,19 @@ internal sealed partial class AppOptions : DbStoreOptions set => SetOption(ref backdropType, SettingEntry.SystemBackdropType, value, EnumToStringOrEmpty); } + public Lazy>> LazyElementThemes { get; } = new(() => + [ + new(SH.CoreWindowThemeLight, ElementTheme.Light), + new(SH.CoreWindowThemeDark, ElementTheme.Dark), + new(SH.CoreWindowThemeSystem, ElementTheme.Default), + ]); + + public ElementTheme ElementTheme + { + get => GetOption(ref elementTheme, SettingEntry.ElementTheme, EnumParse, ElementTheme.Default).Value; + set => SetOption(ref elementTheme, SettingEntry.ElementTheme, value, EnumToStringOrEmpty); + } + public List> BackgroundImageTypes { get; } = CollectionsNameValue.FromEnum(type => type.GetLocalizedDescription()); public BackgroundImageType BackgroundImageType diff --git a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml index ff1dd372..ce6b9618 100644 --- a/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml +++ b/src/Snap.Hutao/Snap.Hutao/View/Page/SettingPage.xaml @@ -314,6 +314,17 @@ SelectedItem="{Binding SelectedBackdropType, Mode=TwoWay}"/> + + + + + ? selectedBackdropType; + private NameValue? selectedElementTheme; private NameValue? selectedBackgroundImageType; private NameValue? selectedCulture; private NameValue? selectedRegion; @@ -94,6 +96,18 @@ internal sealed partial class SettingViewModel : Abstraction.ViewModel } } + public NameValue? SelectedElementTheme + { + get => selectedElementTheme ??= AppOptions.LazyElementThemes.Value.Single(t => t.Value == AppOptions.ElementTheme); + set + { + if (SetProperty(ref selectedElementTheme, value) && value is not null) + { + AppOptions.ElementTheme = value.Value; + } + } + } + public NameValue? SelectedBackgroundImageType { get => selectedBackgroundImageType ??= AppOptions.BackgroundImageTypes.Single(t => t.Value == AppOptions.BackgroundImageType);