@@ -106,7 +106,7 @@ typedef ABI::Windows::Foundation::ITypedEventHandler<ABI::Windows::UI::Notificat
106
106
class ToastEventHandler :
107
107
public Microsoft::WRL::Implements<DesktopToastActivatedEventHandler, DesktopToastDismissedEventHandler, DesktopToastFailedEventHandler> {
108
108
public:
109
- ToastEventHandler::ToastEventHandler (const int render_process_id, const int notification_id);
109
+ ToastEventHandler::ToastEventHandler (const int render_process_id, const int notification_id, const content::PlatformNotificationData& params, const SkBitmap& icon );
110
110
~ToastEventHandler ();
111
111
112
112
// DesktopToastActivatedEventHandler
@@ -150,12 +150,15 @@ class ToastEventHandler :
150
150
private:
151
151
ULONG _ref;
152
152
const int _render_process_id, _notification_id;
153
+ // _params and _icon is stored for fallback to bubble notification
154
+ const content::PlatformNotificationData _params;
155
+ const SkBitmap _icon;
153
156
};
154
157
155
158
// ============= ToastEventHandler Implementation =============
156
159
157
- ToastEventHandler::ToastEventHandler (const int render_process_id, const int notification_id) :
158
- _ref (0 ), _render_process_id(render_process_id), _notification_id(notification_id) {
160
+ ToastEventHandler::ToastEventHandler (const int render_process_id, const int notification_id, const content::PlatformNotificationData& params, const SkBitmap& icon) :
161
+ _ref (0 ), _render_process_id(render_process_id), _notification_id(notification_id), _params(params), _icon(icon) {
159
162
}
160
163
161
164
ToastEventHandler::~ToastEventHandler () {
@@ -195,6 +198,7 @@ IFACEMETHODIMP ToastEventHandler::Invoke(_In_ IToastNotification* /* sender */,
195
198
if (fallBack) {
196
199
NotificationManagerToastWin::ForceDisable = true ;
197
200
delete nmtw;
201
+ NotificationManager::getSingleton ()->AddDesktopNotification (_params, _render_process_id, _notification_id, _icon);
198
202
}
199
203
return succeeded ? S_OK : E_FAIL;
200
204
}
@@ -244,6 +248,30 @@ HRESULT NotificationManagerToastWin::SetTextValues(_In_reads_(textValuesCount) c
244
248
return hr;
245
249
}
246
250
251
+ HRESULT NotificationManagerToastWin::SilentAudio (_In_ IXmlDocument *toastXml) {
252
+ ComPtr<IXmlNodeList> nodeList;
253
+ HRESULT hr = toastXml->GetElementsByTagName (StringReferenceWrapper (L" toast" ).Get (), &nodeList);
254
+ if (SUCCEEDED (hr)) {
255
+ ComPtr<IXmlNode> toastNode;
256
+ hr = nodeList->Item (0 , &toastNode);
257
+ if (SUCCEEDED (hr)) {
258
+ ComPtr<IXmlElement> soundElement;
259
+ hr = toastXml->CreateElement (StringReferenceWrapper (L" audio" ).Get (), &soundElement);
260
+ if (SUCCEEDED (hr)) {
261
+ hr = soundElement->SetAttribute (StringReferenceWrapper (L" silent" ).Get (), StringReferenceWrapper (L" true" ).Get ());
262
+ if (SUCCEEDED (hr)) {
263
+ ComPtr<IXmlNode> soundNode, appendedSoundNode;
264
+ hr = soundElement.As <IXmlNode>(&soundNode);
265
+ if (SUCCEEDED (hr)) {
266
+ hr = toastNode->AppendChild (soundNode.Get (), &appendedSoundNode);
267
+ }
268
+ }
269
+ }
270
+ }
271
+ }
272
+ return hr;
273
+ }
274
+
247
275
HRESULT NotificationManagerToastWin::SetImageSrc (_In_z_ const wchar_t *imagePath, _In_ IXmlDocument *toastXml) {
248
276
wchar_t imageSrc[MAX_PATH] = L" " ;
249
277
HRESULT hr = StringCchCat (imageSrc, ARRAYSIZE (imageSrc), imagePath);
@@ -304,13 +332,16 @@ HRESULT NotificationManagerToastWin::CreateToastXml(_In_ IToastNotificationManag
304
332
};
305
333
UINT32 textLengths[] = { params.title .length (), params.body .length () };
306
334
hr = SetTextValues (textValues, 2 , textLengths, *inputXml);
335
+ if (SUCCEEDED (hr)) {
336
+ hr = SilentAudio (*inputXml);
337
+ }
307
338
}
308
339
}
309
340
return hr;
310
341
}
311
342
312
343
HRESULT NotificationManagerToastWin::CreateToast (_In_ IToastNotificationManagerStatics *toastManager, _In_ IXmlDocument *xml,
313
- const int render_process_id, const int notification_id) {
344
+ const int render_process_id, const int notification_id, const content::PlatformNotificationData& params, const SkBitmap& icon ) {
314
345
ComPtr<IToastNotificationFactory> factory;
315
346
HRESULT hr = GetActivationFactory (StringReferenceWrapper (RuntimeClass_Windows_UI_Notifications_ToastNotification).Get (), &factory);
316
347
if (SUCCEEDED (hr)) {
@@ -319,7 +350,7 @@ HRESULT NotificationManagerToastWin::CreateToast(_In_ IToastNotificationManagerS
319
350
if (SUCCEEDED (hr)) {
320
351
// Register the event handlers
321
352
EventRegistrationToken activatedToken, dismissedToken, failedToken;
322
- ComPtr<ToastEventHandler> eventHandler = new ToastEventHandler (render_process_id, notification_id);
353
+ ComPtr<ToastEventHandler> eventHandler = new ToastEventHandler (render_process_id, notification_id, params, icon );
323
354
324
355
hr = toast->add_Activated (eventHandler.Get (), &activatedToken);
325
356
if (SUCCEEDED (hr)) {
@@ -384,7 +415,7 @@ bool NotificationManagerToastWin::AddDesktopNotification(const content::Platform
384
415
ComPtr<IXmlDocument> toastXml;
385
416
HRESULT hr = CreateToastXml (toastStatics_.Get (), params, icon, &toastXml);
386
417
if (SUCCEEDED (hr)) {
387
- hr = CreateToast (toastStatics_.Get (), toastXml.Get (), render_process_id, notification_id);
418
+ hr = CreateToast (toastStatics_.Get (), toastXml.Get (), render_process_id, notification_id, params, icon );
388
419
if (SUCCEEDED (hr))
389
420
DesktopNotificationPostDisplay (render_process_id, notification_id);
390
421
}
0 commit comments