Skip to content

Commit

Permalink
Add delayloaded tray icon thread, Fix static icon not showing up imme…
Browse files Browse the repository at this point in the history
…diately in some cases winsiderss#919
  • Loading branch information
dmex committed Jun 26, 2021
1 parent 9b18fe3 commit 606f47d
Showing 1 changed file with 54 additions and 10 deletions.
64 changes: 54 additions & 10 deletions ProcessHacker/notifico.c
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,52 @@ VOID PhNfLoadGuids(
}
}

VOID PhNfCreateIconThreadDelayed(
VOID
)
{
static PH_INITONCE initOnce = PH_INITONCE_INIT;
PPH_NF_ICON staticIcon = NULL;
ULONG iconCount = 0;

for (ULONG i = 0; i < PhTrayIconItemList->Count; i++)
{
PPH_NF_ICON icon = PhTrayIconItemList->Items[i];

if (!(icon->Flags & PH_NF_ICON_ENABLED))
continue;

if (icon->SubId == PH_TRAY_ICON_ID_PLAIN_ICON)
staticIcon = icon;

iconCount++;
}

if (iconCount && PhBeginInitOnce(&initOnce))
{
if (NT_SUCCESS(NtCreateEvent(
&PhpTrayIconEventHandle,
EVENT_ALL_ACCESS,
NULL,
SynchronizationEvent,
FALSE
)))
{
// Set the event when the only icon is the static icon. (dmex)
if (iconCount == 1 && staticIcon)
{
NtSetEvent(PhpTrayIconEventHandle, NULL);
}

// Use a seperate thread so we don't block the main GUI or
// the provider threads when explorer is not responding. (dmex)
PhCreateThread2(PhNfpTrayIconUpdateThread, NULL);
}

PhEndInitOnce(&initOnce);
}
}

VOID PhNfLoadStage2(
VOID
)
Expand Down Expand Up @@ -254,16 +300,7 @@ VOID PhNfLoadStage2(
// PhNfpAddNotifyIcon(icon);
//}

if (NT_SUCCESS(NtCreateEvent(
&PhpTrayIconEventHandle,
EVENT_ALL_ACCESS,
NULL,
SynchronizationEvent,
FALSE
)))
{
PhCreateThread2(PhNfpTrayIconUpdateThread, NULL);
}
PhNfCreateIconThreadDelayed();

PhRegisterCallback(
PhGetGeneralCallback(GeneralCallbackProcessProviderUpdatedEvent),
Expand All @@ -288,6 +325,11 @@ VOID PhNfUninitialization(

PhNfpRemoveNotifyIcon(icon);
}

if (PhpTrayIconEventHandle)
{
NtSetEvent(PhpTrayIconEventHandle, NULL);
}
}

VOID PhNfForwardMessage(
Expand Down Expand Up @@ -441,6 +483,8 @@ VOID PhNfSetVisibleIcon(
{
Icon->Flags |= PH_NF_ICON_ENABLED;
PhNfpAddNotifyIcon(Icon);

PhNfCreateIconThreadDelayed();
}
else
{
Expand Down

0 comments on commit 606f47d

Please sign in to comment.