@@ -9,67 +9,11 @@ namespace Coder.Desktop.App.Controls
9
9
{
10
10
public static class TitleBarIcon
11
11
{
12
- private static readonly Lazy < IconsManager > _iconsManager = new ( ( ) => new IconsManager ( ) ) ;
13
-
14
12
public static void SetTitlebarIcon ( Window window )
15
13
{
16
14
var hwnd = WindowNative . GetWindowHandle ( window ) ;
17
- var theme = window . Content is FrameworkElement fe
18
- ? fe . ActualTheme
19
- : ElementTheme . Default ;
20
- _iconsManager . Value . SetTitlebarIcon ( hwnd , theme == ElementTheme . Dark ) ;
21
- }
22
-
23
- public static void DisposeIconsManager ( )
24
- {
25
- _iconsManager . Value . Dispose ( ) ;
26
- }
27
- }
28
-
29
- #pragma warning disable CsWinRT1028 // Class does not need to be partial, it's an SDK bug:
30
- public class IconsManager : IDisposable
31
- #pragma warning restore CsWinRT1028 // Class is not marked partial
32
- {
33
- private nint hIconDark ;
34
- private nint hIconLight ;
35
- private const string iconPathDark = "Assets/coder_icon_32_dark.ico" ;
36
- private const string iconPathLight = "Assets/coder_icon_32_light.ico" ;
37
- public IconsManager ( ) {
38
- hIconDark = PInvoke . LoadImage (
39
- IntPtr . Zero ,
40
- iconPathDark ,
41
- PInvoke . IMAGE_ICON ,
42
- 0 ,
43
- 0 ,
44
- PInvoke . LR_LOADFROMFILE
45
- ) ;
46
- hIconLight = PInvoke . LoadImage (
47
- IntPtr . Zero ,
48
- iconPathLight ,
49
- PInvoke . IMAGE_ICON ,
50
- 0 ,
51
- 0 ,
52
- PInvoke . LR_LOADFROMFILE
53
- ) ;
54
- }
55
-
56
- public void SetTitlebarIcon ( nint windowHandle , bool isDarkTheme )
57
- {
58
- PInvoke . SendMessage ( windowHandle , PInvoke . WM_SETICON , ( IntPtr ) PInvoke . ICON_SMALL , isDarkTheme ? hIconDark : hIconLight ) ;
59
- PInvoke . SendMessage ( windowHandle , PInvoke . WM_SETICON , ( IntPtr ) PInvoke . ICON_BIG , isDarkTheme ? hIconLight : hIconDark ) ;
60
- }
61
-
62
- public void Dispose ( )
63
- {
64
- if ( hIconDark != IntPtr . Zero )
65
- {
66
- PInvoke . DestroyIcon ( hIconDark ) ;
67
- }
68
- if ( hIconLight != IntPtr . Zero )
69
- {
70
- PInvoke . DestroyIcon ( hIconLight ) ;
71
- }
72
- GC . SuppressFinalize ( this ) ;
15
+ var windowId = Win32Interop . GetWindowIdFromWindow ( hwnd ) ;
16
+ AppWindow . GetFromWindowId ( windowId ) . SetIcon ( "coder.ico" ) ;
73
17
}
74
18
}
75
19
}
0 commit comments