Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix infinite loop in tray icon handling #133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions include/tray.c
Original file line number Diff line number Diff line change
Expand Up @@ -45,8 +45,21 @@ int UpdateTray() {

// Only add or modify if not hidden or if balloon will be displayed
if (!hide || tray.uFlags&NIF_INFO) {
// Try until it succeeds, sleep 100 ms between each attempt
while (Shell_NotifyIcon((tray_added?NIM_MODIFY:NIM_ADD),&tray) == FALSE) {
// Try 3 times, sleep 100 ms between each attempt
int i=1;
while (Shell_NotifyIcon(tray_added? NIM_MODIFY: NIM_ADD, &tray) == FALSE) {
// Maybe we tried to re-add an already existing tray?
// Win10 DPI change cause a WM_TASKBARCREATED message!
// In this case we can try to just update the tray.
if (!tray_added && Shell_NotifyIcon(NIM_MODIFY, &tray)) {
// Sucess
tray_added = 1;
return 0;
}
if (i > 2) {
return 1; // Failde all attempts
}
i++;
Sleep(100);
}
// Success
Expand Down