Skip to content

Commit 4bbabba

Browse files
authored
fix(windows): destroy the hwnd if tray creation fails, fixes #276 (#277)
1 parent 583bc5f commit 4bbabba

File tree

2 files changed

+8
-1
lines changed

2 files changed

+8
-1
lines changed

.changes/destroy-window-fix.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"tray-icon": patch
3+
---
4+
5+
Fix a problem on Windows platform where the created window was not destroyed correctly in case the tray icon creation fails.

src/platform_impl/windows/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,9 @@ impl TrayIcon {
127127
let hicon = attrs.icon.as_ref().map(|i| i.inner.as_raw_handle());
128128

129129
if !register_tray_icon(hwnd, internal_id, &hicon, &attrs.tooltip) {
130-
return Err(crate::Error::OsError(std::io::Error::last_os_error()));
130+
let result = Err(crate::Error::OsError(std::io::Error::last_os_error()));
131+
DestroyWindow(hwnd);
132+
return result;
131133
}
132134

133135
if let Some(menu) = &attrs.menu {

0 commit comments

Comments
 (0)