Skip to content

Commit 9c08ce5

Browse files
committed
simplified and moved back to regular icon
1 parent 4d606b3 commit 9c08ce5

File tree

3 files changed

+2
-98
lines changed

3 files changed

+2
-98
lines changed

App/App.xaml.cs

-1
Original file line numberDiff line numberDiff line change
@@ -107,7 +107,6 @@ public async Task ExitApplication()
107107
{
108108
_logger.LogDebug("exiting app");
109109
_handleWindowClosed = false;
110-
TitleBarIcon.DisposeIconsManager();
111110
Exit();
112111
var syncController = _services.GetRequiredService<ISyncSessionController>();
113112
await syncController.DisposeAsync();

App/Controls/PInvoke.cs

-39
This file was deleted.

App/Controls/TitleBarIcon.cs

+2-58
Original file line numberDiff line numberDiff line change
@@ -9,67 +9,11 @@ namespace Coder.Desktop.App.Controls
99
{
1010
public static class TitleBarIcon
1111
{
12-
private static readonly Lazy<IconsManager> _iconsManager = new(() => new IconsManager());
13-
1412
public static void SetTitlebarIcon(Window window)
1513
{
1614
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");
7317
}
7418
}
7519
}

0 commit comments

Comments
 (0)