Skip to content

Commit 43eb147

Browse files
authored
fix: tray icon disappears after explorer restart (#85)
1 parent c4389be commit 43eb147

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

packages/tray_manager/windows/tray_manager_plugin.cpp

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -214,6 +214,21 @@ std::optional<LRESULT> TrayManagerPlugin::HandleWindowProc(HWND hWnd,
214214
tray_icon_setted = false;
215215
_ApplyIcon();
216216
}
217+
} else if (message == WM_POWERBROADCAST) {
218+
// Handle power management events (sleep/wake)
219+
switch (wParam) {
220+
case PBT_APMRESUMEAUTOMATIC:
221+
case PBT_APMRESUMESUSPEND:
222+
// System is resuming from sleep/hibernation
223+
if (tray_icon_setted) {
224+
// Restore the tray icon after system wakes up
225+
tray_icon_setted = false;
226+
_ApplyIcon();
227+
}
228+
break;
229+
default:
230+
break;
231+
}
217232
}
218233
return result;
219234
}
@@ -261,10 +276,21 @@ void TrayManagerPlugin::_ApplyIcon() {
261276
if (tray_icon_setted) {
262277
Shell_NotifyIcon(NIM_MODIFY, &nid);
263278
} else {
279+
HICON hIconBackup = nid.hIcon;
280+
WCHAR szTipBackup[128];
281+
StringCchCopy(szTipBackup, _countof(szTipBackup), nid.szTip);
282+
283+
ZeroMemory(&nid, sizeof(NOTIFYICONDATA));
264284
nid.cbSize = sizeof(NOTIFYICONDATA);
265285
nid.hWnd = GetMainWindow();
286+
nid.uID = 1;
287+
nid.hIcon = hIconBackup;
288+
StringCchCopy(nid.szTip, _countof(nid.szTip), szTipBackup);
266289
nid.uCallbackMessage = WM_MYMESSAGE;
267290
nid.uFlags = NIF_MESSAGE | NIF_ICON;
291+
if (nid.szTip[0] != '\0') {
292+
nid.uFlags |= NIF_TIP;
293+
}
268294
Shell_NotifyIcon(NIM_ADD, &nid);
269295
}
270296

0 commit comments

Comments
 (0)