comparison win/wintoast.cpp @ 2108:35abef6e33a9

Win: Fixed the notification callback when clicking the toast. Currently, the toast isn't clickable once it moves into the action center. This is a known issue with WinToast, because once the toast moves into the action center, it requires a COM notificaiton object be registered.
author bsmith@81767d24-ef19-dc11-ae90-00e081727c95
date Wed, 17 Jun 2020 03:38:21 +0000
parents 6e55c6f8d816
children 251d050d306b
comparison
equal deleted inserted replaced
2107:b71f46cd58b9 2108:35abef6e33a9
5 using namespace WinToastLib; 5 using namespace WinToastLib;
6 6
7 extern "C" { 7 extern "C" {
8 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2); 8 LRESULT CALLBACK _wndproc(HWND hWnd, UINT msg, WPARAM mp1, LPARAM mp2);
9 void dw_signal_disconnect_by_window(HWND window); 9 void dw_signal_disconnect_by_window(HWND window);
10 #ifdef DEBUG
11 void dw_debug(const char *format, ...);
12 #endif
13 } 10 }
14 11
15 class DWHandler : public IWinToastHandler { 12 class DWHandler : public IWinToastHandler {
16 public: 13 public:
17 WinToastTemplate *templ; 14 WinToastTemplate *templ;
18 15
19 void toastActivated() const { 16 void toastActivated() const {
20 // The user clicked in this toast 17 // The user clicked in this toast
21 #ifdef DEBUG
22 dw_debug("Sending notification to DW eventhandler\n");
23 #endif
24 _wndproc((HWND)templ, WM_USER+102, 0, 0); 18 _wndproc((HWND)templ, WM_USER+102, 0, 0);
19 dw_signal_disconnect_by_window((HWND)templ);
20 delete templ;
25 } 21 }
26 22
27 void toastActivated(int actionIndex) const { 23 void toastActivated(int actionIndex) const {
28 // The user clicked on action 24 // The user clicked on action
29 #ifdef DEBUG
30 dw_debug("Sending notification to DW eventhandler via action\n");
31 #endif
32 _wndproc((HWND)templ, WM_USER+102, 0, 0); 25 _wndproc((HWND)templ, WM_USER+102, 0, 0);
26 dw_signal_disconnect_by_window((HWND)templ);
27 delete templ;
33 } 28 }
34 29
35 void toastDismissed(WinToastDismissalReason state) const { 30 void toastDismissed(WinToastDismissalReason state) const {
36 switch (state) { 31 switch (state) {
37 case UserCanceled: 32 case UserCanceled:
38 // The user dismissed this toast 33 // The user dismissed this toast
39 #ifdef DEBUG 34 dw_signal_disconnect_by_window((HWND)templ);
40 dw_debug("The user dismissed this toast\n");
41 #endif
42 delete templ; 35 delete templ;
43 break; 36 break;
44 case TimedOut: 37 case TimedOut:
45 // The toast has timed out 38 // The toast has timed out
46 #ifdef DEBUG
47 dw_debug("The toast has timed out\n");
48 #endif
49 break; 39 break;
50 case ApplicationHidden: 40 case ApplicationHidden:
51 // The application hid the toast using ToastNotifier.hide() 41 // The application hid the toast using ToastNotifier.hide()
52 #ifdef DEBUG
53 dw_debug("The application hid the toast using ToastNotifier.hide()\n");
54 #endif
55 break; 42 break;
56 default: 43 default:
57 // Toast not activated 44 // Toast not activated
58 break; 45 break;
59 } 46 }
60 } 47 }
61 48
62 void toastFailed() const { 49 void toastFailed() const {
63 // Error showing current toast 50 // Error showing current toast
64 #ifdef DEBUG
65 dw_debug("Toast failed freeing template\n");
66 #endif
67 delete templ; 51 delete templ;
68 } 52 }
69 }; 53 };
70 54
71 55
87 71
88 void _dw_toast_init(LPWSTR AppName, LPWSTR AppID) 72 void _dw_toast_init(LPWSTR AppName, LPWSTR AppID)
89 { 73 {
90 if(WinToast::isCompatible()) 74 if(WinToast::isCompatible())
91 { 75 {
76 // Generate a Microsoft compatible Application User Model ID
77 LPWSTR company = wcschr(AppID, '.');
78 *company = 0;
79 LPWSTR product = wcschr(++company, '.');
80 *product = 0;
81 LPWSTR subproduct = wcschr(++product, '.');
82 if(subproduct)
83 *subproduct = 0;
84 LPWSTR version = subproduct ? wcschr(++subproduct, '.') : NULL;
85
92 WinToast::instance()->setAppName(AppName); 86 WinToast::instance()->setAppName(AppName);
93 WinToast::instance()->setAppUserModelId(AppID); 87 WinToast::instance()->setAppUserModelId(WinToast::instance()->configureAUMI(company, product,
88 subproduct ? subproduct : L"", (version && version++ && _wtoi(version) > 0) ? version : L""));
94 WinToast::instance()->initialize(); 89 WinToast::instance()->initialize();
95 } 90 }
96 } 91 }
97 92
98 void *_dw_notification_new(LPWSTR title, LPWSTR image, LPWSTR description) 93 void *_dw_notification_new(LPWSTR title, LPWSTR image, LPWSTR description)