|
8 | 8 | using Serilog; |
9 | 9 | using Serilog.Events; |
10 | 10 | using Serilog.Sinks.SystemConsole.Themes; |
| 11 | +using System.Extensions.Core; |
11 | 12 | using System.Runtime.InteropServices; |
12 | 13 |
|
13 | 14 | namespace Daybreak.Launch; |
@@ -73,13 +74,30 @@ private static bool StopHostedServices(PhotinoBlazorApp app, CancellationTokenSo |
73 | 74 |
|
74 | 75 | private static void SetupRoundedWindows(PhotinoBlazorApp app) |
75 | 76 | { |
76 | | - var hwnd = app.MainWindow.WindowHandle; |
77 | | - var preference = NativeMethods.DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND; |
78 | | - NativeMethods.DwmSetWindowAttribute( |
79 | | - hwnd, |
80 | | - NativeMethods.DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, |
81 | | - ref preference, |
82 | | - sizeof(uint)); |
| 77 | + var scopedLogger = app.Services.GetRequiredService<ILogger<Launcher>>().CreateScopedLogger(); |
| 78 | + try |
| 79 | + { |
| 80 | + // DWMWA_WINDOW_CORNER_PREFERENCE is only supported on Windows 11 (Build 22000+) |
| 81 | + if (!OperatingSystem.IsWindowsVersionAtLeast(10, 0, 22000)) |
| 82 | + { |
| 83 | + scopedLogger.LogWarning("Rounded corners are not supported on this version of Windows."); |
| 84 | + return; |
| 85 | + } |
| 86 | + |
| 87 | + |
| 88 | + var hwnd = app.MainWindow.WindowHandle; |
| 89 | + var preference = NativeMethods.DWM_WINDOW_CORNER_PREFERENCE.DWMWCP_ROUND; |
| 90 | + NativeMethods.DwmSetWindowAttribute( |
| 91 | + hwnd, |
| 92 | + NativeMethods.DWMWINDOWATTRIBUTE.DWMWA_WINDOW_CORNER_PREFERENCE, |
| 93 | + ref preference, |
| 94 | + sizeof(uint)); |
| 95 | + scopedLogger.LogDebug("Setup rounded corners"); |
| 96 | + } |
| 97 | + catch (Exception ex) |
| 98 | + { |
| 99 | + scopedLogger.LogError(ex, "Failed to set rounded corners on window."); |
| 100 | + } |
83 | 101 | } |
84 | 102 |
|
85 | 103 | private static void SetupBorderless(PhotinoBlazorApp app) |
|
0 commit comments