Skip to content

Commit

Permalink
[desktop] troubleshot the desktop notifications (not working using th…
Browse files Browse the repository at this point in the history
…e ARC browser)
  • Loading branch information
nxmatic committed Jul 10, 2024
1 parent 8625b40 commit 8e9f46f
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions src/main/desktop-notifier.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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;
});
});
Expand Down

0 comments on commit 8e9f46f

Please sign in to comment.