|
|
@@ -1,18 +1,22 @@
|
|
|
import { i18n, defaultImage, sendTabCmd, trueJoin } from '@/common';
|
|
|
+import ua from '@/common/ua';
|
|
|
import { addPublicCommands } from './message';
|
|
|
|
|
|
const openers = {};
|
|
|
|
|
|
addPublicCommands({
|
|
|
/** @return {Promise<string>} */
|
|
|
- async Notification({ image, text, title }, src, bgCallback) {
|
|
|
+ async Notification({ image, text, title, onclick }, src) {
|
|
|
const notificationId = await browser.notifications.create({
|
|
|
type: 'basic',
|
|
|
title: [title, IS_FIREFOX && i18n('extName')]::trueJoin(' - '), // Chrome already shows the name
|
|
|
message: text,
|
|
|
iconUrl: image || defaultImage,
|
|
|
+ ...!IS_FIREFOX && {
|
|
|
+ requireInteraction: !!onclick,
|
|
|
+ },
|
|
|
});
|
|
|
- const op = bgCallback || src && [src.tab.id, src.frameId];
|
|
|
+ const op = isFunction(onclick) ? onclick : src && [src.tab.id, src.frameId];
|
|
|
if (op) openers[notificationId] = op;
|
|
|
return notificationId;
|
|
|
},
|
|
|
@@ -32,8 +36,8 @@ browser.notifications.onClosed.addListener((id) => {
|
|
|
|
|
|
function notifyOpener(id, isClick) {
|
|
|
const op = openers[id];
|
|
|
- if (isFunction(op)) {
|
|
|
- op(isClick);
|
|
|
+ if (isClick && isFunction(op)) {
|
|
|
+ op();
|
|
|
} else if (op) {
|
|
|
sendTabCmd(op[0], isClick ? 'NotificationClick' : 'NotificationClose', id, {
|
|
|
frameId: op[1],
|