|
18 | 18 | using namespace Nickvision::App; |
19 | 19 | using namespace Nickvision::System; |
20 | 20 |
|
| 21 | +#ifdef _WIN32 |
| 22 | +static std::filesystem::path s_openPath; |
| 23 | + |
| 24 | +static LRESULT CALLBACK wndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) |
| 25 | +{ |
| 26 | + if(msg == WM_TRAYICON) |
| 27 | + { |
| 28 | + if(lParam == NIN_BALLOONUSERCLICK) |
| 29 | + { |
| 30 | + if(std::filesystem::exists(s_openPath)) |
| 31 | + { |
| 32 | + ShellExecuteA(hwnd, "open", s_openPath.string().c_str(), nullptr, nullptr, SW_SHOWDEFAULT); |
| 33 | + } |
| 34 | + } |
| 35 | + } |
| 36 | + else if(msg == WM_TIMER) |
| 37 | + { |
| 38 | + if(wParam == TIMER_ID) |
| 39 | + { |
| 40 | + KillTimer(hwnd, TIMER_ID); |
| 41 | + PostQuitMessage(0); |
| 42 | + } |
| 43 | + } |
| 44 | + else if(msg == WM_DESTROY) |
| 45 | + { |
| 46 | + PostQuitMessage(0); |
| 47 | + } |
| 48 | + return DefWindowProcA(hwnd, msg, wParam, lParam); |
| 49 | +} |
| 50 | +#endif |
| 51 | + |
21 | 52 | namespace Nickvision::Notifications |
22 | 53 | { |
23 | 54 | void ShellNotification::send(const ShellNotificationSentEventArgs& e, const AppInfo& info, const std::string& openText) |
24 | 55 | { |
25 | 56 | #ifdef _WIN32 |
| 57 | + s_openPath = e.getAction() == "open" ? e.getActionParam() : ""; |
26 | 58 | std::thread worker{ [e, info]() |
27 | 59 | { |
28 | | - static std::filesystem::path path{ e.getAction() == "open" ? e.getActionParam() : "" }; |
29 | 60 | std::string className{ "libnick_notification" }; |
30 | 61 | WNDCLASSA wc{}; |
31 | | - wc.lpfnWndProc = +[](HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam) -> LRESULT |
32 | | - { |
33 | | - if(msg == WM_TRAYICON) |
34 | | - { |
35 | | - if(lParam == NIN_BALLOONUSERCLICK) |
36 | | - { |
37 | | - if(std::filesystem::exists(path)) |
38 | | - { |
39 | | - ShellExecuteA(hwnd, "open", path.string().c_str(), nullptr, nullptr, SW_SHOWDEFAULT); |
40 | | - } |
41 | | - } |
42 | | - } |
43 | | - else if(msg == WM_TIMER) |
44 | | - { |
45 | | - if(wParam == TIMER_ID) |
46 | | - { |
47 | | - KillTimer(hwnd, TIMER_ID); |
48 | | - PostQuitMessage(0); |
49 | | - } |
50 | | - } |
51 | | - else if(msg == WM_DESTROY) |
52 | | - { |
53 | | - PostQuitMessage(0); |
54 | | - } |
55 | | - return DefWindowProcA(hwnd, msg, wParam, lParam); |
56 | | - }; |
| 62 | + wc.lpfnWndProc = wndProc; |
57 | 63 | wc.hInstance = GetModuleHandleA(nullptr); |
58 | 64 | wc.lpszClassName = className.c_str(); |
59 | 65 | RegisterClassA(&wc); |
|
0 commit comments