mirror of
https://jihulab.com/DGP-Studio/Snap.Hutao.git
synced 2025-11-19 21:02:53 +08:00
increase boot speed
This commit is contained in:
@@ -11,8 +11,11 @@ using Snap.Hutao.Message;
|
||||
using Snap.Hutao.Service;
|
||||
using Snap.Hutao.Win32;
|
||||
using System.IO;
|
||||
using Windows.Win32.Foundation;
|
||||
using Windows.Graphics;
|
||||
using Windows.UI;
|
||||
using Windows.Win32.Graphics.Dwm;
|
||||
using static Windows.Win32.PInvoke;
|
||||
|
||||
namespace Snap.Hutao.Core.Windowing;
|
||||
|
||||
@@ -65,22 +68,23 @@ internal sealed class ExtendedWindow<TWindow> : IRecipient<FlyoutOpenCloseMessag
|
||||
ExtendsContentIntoTitleBar();
|
||||
|
||||
Persistence.RecoverOrInit(options);
|
||||
UpdateImmersiveDarkMode(options.TitleBar, default!);
|
||||
|
||||
// appWindow.Show(true);
|
||||
// appWindow.Show can't bring window to top.
|
||||
options.Window.Activate();
|
||||
// options.Window.Activate();
|
||||
Persistence.BringToForeground(options.Hwnd);
|
||||
|
||||
AppOptions appOptions = serviceProvider.GetRequiredService<AppOptions>();
|
||||
UpdateSystemBackdrop(appOptions.BackdropType);
|
||||
appOptions.PropertyChanged += OnOptionsPropertyChanged;
|
||||
|
||||
bool subClassApplied = subclass.Initialize();
|
||||
logger.LogInformation("Apply {name} : {result}", nameof(WindowSubclass<TWindow>), subClassApplied ? "succeed" : "failed");
|
||||
|
||||
IMessenger messenger = serviceProvider.GetRequiredService<IMessenger>();
|
||||
messenger.Register(this);
|
||||
serviceProvider.GetRequiredService<IMessenger>().Register(this);
|
||||
|
||||
options.Window.Closed += OnWindowClosed;
|
||||
options.TitleBar.ActualThemeChanged += UpdateImmersiveDarkMode;
|
||||
}
|
||||
|
||||
private void OnOptionsPropertyChanged(object? sender, PropertyChangedEventArgs e)
|
||||
@@ -159,6 +163,12 @@ internal sealed class ExtendedWindow<TWindow> : IRecipient<FlyoutOpenCloseMessag
|
||||
appTitleBar.ButtonPressedForegroundColor = systemBaseHighColor;
|
||||
}
|
||||
|
||||
private unsafe void UpdateImmersiveDarkMode(FrameworkElement titleBar, object discard)
|
||||
{
|
||||
BOOL isDarkMode = Control.Theme.ThemeHelper.IsDarkMode(titleBar.ActualTheme);
|
||||
DwmSetWindowAttribute(options.Hwnd, DWMWINDOWATTRIBUTE.DWMWA_USE_IMMERSIVE_DARK_MODE, &isDarkMode, unchecked((uint)sizeof(BOOL)));
|
||||
}
|
||||
|
||||
private void UpdateDragRectangles(bool isFlyoutOpened = false)
|
||||
{
|
||||
AppWindowTitleBar appTitleBar = options.AppWindow.TitleBar;
|
||||
|
||||
@@ -74,6 +74,29 @@ internal static class Persistence
|
||||
return Math.Round(dpi / 96D, 2, MidpointRounding.AwayFromZero);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 将窗口设为前台窗口
|
||||
/// </summary>
|
||||
/// <param name="hwnd">窗口句柄</param>
|
||||
public static unsafe void BringToForeground(in HWND hwnd)
|
||||
{
|
||||
HWND fgHwnd = GetForegroundWindow();
|
||||
|
||||
uint threadIdHwnd = GetWindowThreadProcessId(hwnd);
|
||||
uint threadIdfgHwnd = GetWindowThreadProcessId(fgHwnd);
|
||||
|
||||
if (threadIdHwnd != threadIdfgHwnd)
|
||||
{
|
||||
AttachThreadInput(threadIdHwnd, threadIdfgHwnd, true);
|
||||
SetForegroundWindow(hwnd);
|
||||
AttachThreadInput(threadIdHwnd, threadIdfgHwnd, false);
|
||||
}
|
||||
else
|
||||
{
|
||||
SetForegroundWindow(hwnd);
|
||||
}
|
||||
}
|
||||
|
||||
private static void TransformToCenterScreen(ref RectInt32 rect)
|
||||
{
|
||||
DisplayArea displayArea = DisplayArea.GetFromRect(rect, DisplayAreaFallback.Primary);
|
||||
|
||||
@@ -14,6 +14,10 @@ DefSubclassProc
|
||||
RemoveWindowSubclass
|
||||
SetWindowSubclass
|
||||
|
||||
// DWMAPI
|
||||
DwmGetWindowAttribute
|
||||
DwmSetWindowAttribute
|
||||
|
||||
// GDI32
|
||||
GetDeviceCaps
|
||||
|
||||
@@ -30,10 +34,14 @@ WriteProcessMemory
|
||||
CoWaitForMultipleObjects
|
||||
|
||||
// USER32
|
||||
AttachThreadInput
|
||||
FindWindowEx
|
||||
GetDC
|
||||
GetDpiForWindow
|
||||
GetForegroundWindow
|
||||
GetWindowPlacement
|
||||
GetWindowThreadProcessId
|
||||
SetForegroundWindow
|
||||
|
||||
// WinRT
|
||||
IMemoryBufferByteAccess
|
||||
@@ -52,7 +52,8 @@
|
||||
Opacity="0.8"
|
||||
Style="{StaticResource SubtitleTextBlockStyle}"
|
||||
Text="{Binding Inner.Title}"
|
||||
TextTrimming="CharacterEllipsis"/>
|
||||
TextTrimming="CharacterEllipsis"
|
||||
TextWrapping="NoWrap"/>
|
||||
<TextBlock
|
||||
Opacity="0.6"
|
||||
Style="{StaticResource CaptionTextBlockStyle}"
|
||||
|
||||
@@ -88,7 +88,7 @@
|
||||
Value="{Binding LastOrangePull}"/>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="12,0"
|
||||
Margin="6,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource OrangeBrush}"
|
||||
@@ -121,7 +121,7 @@
|
||||
Value="{Binding LastPurplePull}"/>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="12,0"
|
||||
Margin="6,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource PurpleBrush}"
|
||||
@@ -168,7 +168,7 @@
|
||||
Value="{Binding LastOrangePull}"/>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="12,0"
|
||||
Margin="6,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource OrangeBrush}"
|
||||
@@ -201,7 +201,7 @@
|
||||
Value="{Binding LastPurplePull}"/>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="12,0"
|
||||
Margin="6,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource PurpleBrush}"
|
||||
@@ -248,7 +248,7 @@
|
||||
Value="{Binding LastOrangePull}"/>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="12,0"
|
||||
Margin="6,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource OrangeBrush}"
|
||||
@@ -281,7 +281,7 @@
|
||||
Value="{Binding LastPurplePull}"/>
|
||||
<TextBlock
|
||||
Grid.Column="0"
|
||||
Margin="12,0"
|
||||
Margin="6,0"
|
||||
HorizontalAlignment="Center"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{StaticResource PurpleBrush}"
|
||||
|
||||
Reference in New Issue
Block a user