5#include <condition_variable>
11#define PANO_BALLOON_MS 5000
15#define PANO_MAX_QUEUED_BALLOONS 4
22static std::mutex g_Lock;
23static std::condition_variable g_Wake;
24static std::deque<Balloon> g_Queue;
25static size_t g_Dropped = 0;
26static bool g_WorkerStarted =
false;
29static void ShowBalloon(
const Balloon& balloon)
31 NOTIFYICONDATAA nid = {};
32 nid.cbSize =
sizeof(NOTIFYICONDATAA);
33 nid.hWnd = GetActiveWindow();
34 nid.uFlags = NIF_MESSAGE | NIF_ICON | NIF_TIP | NIF_INFO;
36 nid.dwInfoFlags = NIIF_INFO | NIIF_USER;
37 nid.uVersion = NOTIFYICON_VERSION_4;
41 nid.hIcon = (HICON)LoadImageA(NULL, icon.c_str(), IMAGE_ICON, 128, 128, LR_LOADFROMFILE | LR_SHARED);
42 if (nid.hIcon == NULL) {
47 StringCchCopyA(nid.szInfoTitle, ARRAYSIZE(nid.szInfoTitle), balloon.
Title.c_str());
48 StringCchCopyA(nid.szTip, ARRAYSIZE(nid.szTip),
"Panoptes EDR");
49 StringCchCopyA(nid.szInfo, ARRAYSIZE(nid.szInfo), balloon.
Text.c_str());
51 Shell_NotifyIconA(NIM_ADD, &nid);
53 Shell_NotifyIconA(NIM_DELETE, &nid);
57static void BalloonThread()
62 std::unique_lock<std::mutex> lock(g_Lock);
63 g_Wake.wait(lock, [] {
return !g_Queue.empty() || g_Dropped > 0; });
64 if (!g_Queue.empty()) {
65 next = std::move(g_Queue.front());
69 next.
Title =
"Panoptes EDR Detection";
70 next.
Text = std::to_string(g_Dropped) +
" more detections. See C:\\ProgramData\\Panoptes\\Logs";
80 std::lock_guard<std::mutex> guard(g_Lock);
81 if (!g_WorkerStarted) {
83 std::thread(BalloonThread).detach();
84 g_WorkerStarted =
true;
90 g_Queue.push_back({ pszTitle, pszText });
static BOOL ShowTrayIconBalloon(LPCSTR pszTitle, LPCSTR pszText)
Queues a tray icon balloon notification and returns at once. A background thread shows queued balloon...
#define PANO_MAX_QUEUED_BALLOONS
std::string GetExecutableDirectory()