diff --git a/src/Snap.Hutao/Snap.Hutao/Control/Helper/FrameworkElementHelper.cs b/src/Snap.Hutao/Snap.Hutao/Control/Helper/FrameworkElementHelper.cs index 45bc1950..ac36e619 100644 --- a/src/Snap.Hutao/Snap.Hutao/Control/Helper/FrameworkElementHelper.cs +++ b/src/Snap.Hutao/Snap.Hutao/Control/Helper/FrameworkElementHelper.cs @@ -7,6 +7,8 @@ namespace Snap.Hutao.Control.Helper; [SuppressMessage("", "SH001")] [DependencyProperty("SquareLength", typeof(double), 0D, nameof(OnSquareLengthChanged), IsAttached = true, AttachedType = typeof(FrameworkElement))] +[DependencyProperty("IsActualThemeBindingEnabled", typeof(bool), false, nameof(OnIsActualThemeBindingEnabled), IsAttached = true, AttachedType = typeof(FrameworkElement))] +[DependencyProperty("ActualTheme", typeof(ElementTheme), ElementTheme.Default, IsAttached = true, AttachedType = typeof(FrameworkElement))] public sealed partial class FrameworkElementHelper { private static void OnSquareLengthChanged(DependencyObject dp, DependencyPropertyChangedEventArgs e) @@ -15,4 +17,22 @@ public sealed partial class FrameworkElementHelper element.Width = (double)e.NewValue; element.Height = (double)e.NewValue; } + + private static void OnIsActualThemeBindingEnabled(DependencyObject dp, DependencyPropertyChangedEventArgs e) + { + FrameworkElement element = (FrameworkElement)dp; + if ((bool)e.NewValue) + { + element.ActualThemeChanged += OnActualThemeChanged; + } + else + { + element.ActualThemeChanged -= OnActualThemeChanged; + } + + static void OnActualThemeChanged(FrameworkElement sender, object args) + { + SetActualTheme(sender, sender.ActualTheme); + } + } } \ No newline at end of file diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/InputActiveDesktopAcrylicBackdrop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/InputActiveDesktopAcrylicBackdrop.cs index 5e37a079..4f2b0c15 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/InputActiveDesktopAcrylicBackdrop.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/InputActiveDesktopAcrylicBackdrop.cs @@ -10,7 +10,7 @@ using System.Collections.Concurrent; namespace Snap.Hutao.Core.Windowing.Backdrop; // https://github.com/microsoft/microsoft-ui-xaml/blob/winui3/release/1.5-stable/controls/dev/Materials/DesktopAcrylicBackdrop/DesktopAcrylicBackdrop.cpp -internal sealed class InputActiveDesktopAcrylicBackdrop : SystemBackdrop +internal sealed partial class InputActiveDesktopAcrylicBackdrop : SystemBackdrop { private readonly ConcurrentDictionary controllers = []; @@ -18,11 +18,10 @@ internal sealed class InputActiveDesktopAcrylicBackdrop : SystemBackdrop { base.OnTargetConnected(target, xamlRoot); - DesktopAcrylicController newController = new(); SystemBackdropConfiguration configuration = GetDefaultSystemBackdropConfiguration(target, xamlRoot); - configuration.IsInputActive = true; + DesktopAcrylicController newController = new(); newController.AddSystemBackdropTarget(target); newController.SetSystemBackdropConfiguration(configuration); controllers.TryAdd(target, newController); diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/TransparentBackdrop.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/TransparentBackdrop.cs index dd8319aa..3b9f09c7 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/TransparentBackdrop.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/Backdrop/TransparentBackdrop.cs @@ -39,15 +39,19 @@ internal sealed class TransparentBackdrop : SystemBackdrop, IBackdropNeedEraseBa } } - protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop connectedTarget, XamlRoot xamlRoot) + protected override void OnTargetConnected(ICompositionSupportsSystemBackdrop target, XamlRoot xamlRoot) { + base.OnTargetConnected(target, xamlRoot); + brush ??= Compositor.CreateColorBrush(tintColor); - connectedTarget.SystemBackdrop = brush; + target.SystemBackdrop = brush; } - protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop disconnectedTarget) + protected override void OnTargetDisconnected(ICompositionSupportsSystemBackdrop target) { - disconnectedTarget.SystemBackdrop = null; + base.OnTargetDisconnected(target); + + target.SystemBackdrop = null; if (compositorLock is not null) { diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml index 3187eab1..1cd48309 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconContextMenu.xaml @@ -2,8 +2,10 @@ x:Class="Snap.Hutao.Core.Windowing.NotifyIcon.NotifyIconContextMenu" xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:cw="using:CommunityToolkit.WinUI" xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" + xmlns:shch="using:Snap.Hutao.Control.Helper" xmlns:shcm="using:Snap.Hutao.Control.Markup" xmlns:shcwb="using:Snap.Hutao.Core.Windowing.Backdrop" xmlns:shv="using:Snap.Hutao.ViewModel" @@ -30,7 +32,10 @@ - + (ref MemoryMarshal.GetArrayDataReference(MD5.HashData(Encoding.UTF8.GetBytes(iconFile.Path)))); - xamlHostWindow = new(); + xamlHostWindow = new(serviceProvider); messageWindow = new() { @@ -46,8 +46,6 @@ internal sealed class NotifyIconController : IDisposable messageWindow.Dispose(); NotifyIconMethods.Delete(id); icon.Dispose(); - - xamlHostWindow.Dispose(); } public RECT GetRect() diff --git a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs index 7a2deb84..74f3058c 100644 --- a/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs +++ b/src/Snap.Hutao/Snap.Hutao/Core/Windowing/NotifyIcon/NotifyIconXamlHostWindow.cs @@ -15,11 +15,9 @@ using static Snap.Hutao.Win32.User32; namespace Snap.Hutao.Core.Windowing.NotifyIcon; -internal sealed class NotifyIconXamlHostWindow : Window, IDisposable, IWindowNeedEraseBackground +internal sealed class NotifyIconXamlHostWindow : Window, IWindowNeedEraseBackground { - private readonly XamlWindowSubclass subclass; - - public NotifyIconXamlHostWindow() + public NotifyIconXamlHostWindow(IServiceProvider serviceProvider) { Content = new Border(); @@ -36,10 +34,7 @@ internal sealed class NotifyIconXamlHostWindow : Window, IDisposable, IWindowNee presenter.SetBorderAndTitleBar(false, false); } - subclass = new(this); - subclass.Initialize(); - - Activate(); + this.InitializeController(serviceProvider); } public void ShowFlyoutAt(FlyoutBase flyout, Point point, RECT icon) @@ -60,9 +55,4 @@ internal sealed class NotifyIconXamlHostWindow : Window, IDisposable, IWindowNee ShowMode = FlyoutShowMode.Transient, }); } - - public void Dispose() - { - subclass.Dispose(); - } } \ No newline at end of file