From 8e9f46f595430408911e1be942ca5e769af83a61 Mon Sep 17 00:00:00 2001 From: "Stephane Lacoin (aka nxmatic)" Date: Wed, 10 Jul 2024 21:42:36 +0200 Subject: [PATCH] [desktop] troubleshot the desktop notifications (not working using the ARC browser) --- src/main/desktop-notifier.js | 25 +++++++++++++++++++------ 1 file changed, 19 insertions(+), 6 deletions(-) diff --git a/src/main/desktop-notifier.js b/src/main/desktop-notifier.js index 16d4183c..0d1c259d 100644 --- a/src/main/desktop-notifier.js +++ b/src/main/desktop-notifier.js @@ -46,6 +46,7 @@ class DesktopNotifier extends ServiceWorkerComponent { return new Promise((resolve, reject) => { chrome.notifications.create(namespacedIdOf(id), options, (notificationId) => { if (chrome.runtime.lastError) { + // log the error console.groupCollapsed('Notification Error'); console.warn('Failed to create notification'); console.error(chrome.runtime.lastError); @@ -58,14 +59,26 @@ class DesktopNotifier extends ServiceWorkerComponent { error.info = { id: notificationId, options }; return reject(error); } + + // always log the notification + console.groupCollapsed('Created notification'); + console.info('Notification ID:', notificationId); + console.info('Options:', options); + console.groupEnd(); + + // resolve if no acknowledge required if (!options.requireInteraction) { - return resolve(notificationId); + return resolve(notificationId); } - chrome.notifications.onClicked.addListener((clickedId) => { - if (clickedId === notificationId) { - resolve(notificationId); - } - }); + + // wait for user acknowledge + const resolveIfMatchingId = (clickedId) => { + if (clickedId !== notificationId) return; + resolve(notificationId); + }; + chrome.notifications.onClicked.addListener(resolveIfMatching) + + // let's the caller informed of the asynch condition return undefined; }); });