| Index: lib/notificationHelper.js |
| =================================================================== |
| --- a/lib/notificationHelper.js |
| +++ b/lib/notificationHelper.js |
| @@ -1,6 +1,6 @@ |
| /* |
| * This file is part of Adblock Plus <https://adblockplus.org/>, |
| - * Copyright (C) 2006-2016 Eyeo GmbH |
| + * Copyright (C) 2006-2017 eyeo GmbH |
| * |
| * Adblock Plus is free software: you can redistribute it and/or modify |
| * it under the terms of the GNU General Public License version 3 as |
| @@ -33,6 +33,7 @@ |
| displayMethods.critical = ["icon", "notification", "popup"]; |
| displayMethods.question = ["notification"]; |
| displayMethods.normal = ["notification"]; |
| +displayMethods.relentless = ["notification"]; |
| displayMethods.information = ["icon", "popup"]; |
| function prepareNotificationIconAndPopup() |
| @@ -86,7 +87,7 @@ |
| } |
| ]; |
| } |
| - if (notificationType != "critical") |
| + if (["critical", "relentless"].indexOf(notificationType) == -1) |
| { |
| buttons.push({ |
| type: "configure", |
| @@ -132,7 +133,8 @@ |
| }); |
| break; |
| case "question": |
| - NotificationStorage.triggerQuestionListeners(activeNotification.id, buttonIndex == 0); |
| + NotificationStorage.triggerQuestionListeners(activeNotification.id, |
| + buttonIndex == 0); |
| NotificationStorage.markAsShown(activeNotification.id); |
| activeNotification.onClicked(); |
| break; |
| @@ -146,10 +148,13 @@ |
| function initChromeNotifications() |
| { |
| - // Chrome hides notifications in notification center when clicked so we need to clear them |
| + // Chrome hides notifications in notification center when clicked so |
| + // we need to clear them. |
| function clearActiveNotification(notificationId) |
| { |
| - if (activeNotification && activeNotification.type != "question" && !("links" in activeNotification)) |
| + if (activeNotification && |
| + activeNotification.type != "question" && |
| + !("links" in activeNotification)) |
| return; |
| chrome.notifications.clear(notificationId, wasCleared => |
| @@ -159,11 +164,13 @@ |
| }); |
| } |
| - chrome.notifications.onButtonClicked.addListener((notificationId, buttonIndex) => |
| - { |
| - notificationButtonClick(buttonIndex); |
| - clearActiveNotification(notificationId); |
| - }); |
| + chrome.notifications.onButtonClicked.addListener( |
| + (notificationId, buttonIndex) => |
| + { |
| + notificationButtonClick(buttonIndex); |
| + clearActiveNotification(notificationId); |
| + } |
| + ); |
| chrome.notifications.onClicked.addListener(clearActiveNotification); |
| chrome.notifications.onClosed.addListener(notificationClosed); |
| } |
| @@ -178,20 +185,23 @@ |
| { |
| let texts = NotificationStorage.getLocalizedTexts(notification); |
| let title = texts.title || ""; |
| - let message = texts.message ? texts.message.replace(/<\/?(a|strong)>/g, "") : ""; |
| + let message = (texts.message || "").replace(/<\/?(a|strong)>/g, ""); |
| let iconUrl = ext.getURL("icons/detailed/abp-128.png"); |
| let linkCount = (activeNotification.links || []).length; |
| if ("notifications" in chrome) |
| { |
| - activeButtons = getNotificationButtons(activeNotification.type, texts.message); |
| + activeButtons = getNotificationButtons(activeNotification.type, |
| + texts.message); |
| chrome.notifications.create("", { |
| type: "basic", |
| - title: title, |
| - iconUrl: iconUrl, |
| - message: message, |
| + title, |
| + iconUrl, |
| + message, |
| buttons: activeButtons.map(button => ({title: button.title})), |
| - priority: 2 // We use the highest priority to prevent the notification from closing automatically |
| + // We use the highest priority to prevent the notification |
| + // from closing automatically. |
| + priority: 2 |
| }); |
| } |
| else if ("Notification" in window && activeNotification.type != "question") |
| @@ -199,7 +209,7 @@ |
| if (linkCount > 0) |
| message += " " + ext.i18n.getMessage("notification_without_buttons"); |
| - let notification = new Notification( |
| + let widget = new Notification( |
| title, |
| { |
| lang: Utils.appLocale, |
| @@ -209,12 +219,12 @@ |
| } |
| ); |
| - notification.addEventListener("click", openNotificationLinks); |
| - notification.addEventListener("close", notificationClosed); |
| + widget.addEventListener("click", openNotificationLinks); |
| + widget.addEventListener("close", notificationClosed); |
| } |
| else |
| { |
| - let message = title + "\n" + message; |
| + message = title + "\n" + message; |
| if (linkCount > 0) |
| message += "\n\n" + ext.i18n.getMessage("notification_with_buttons"); |
| @@ -226,7 +236,10 @@ |
| } |
| } |
| prepareNotificationIconAndPopup(); |
| -}; |
| + |
| + if (notification.type !== "question") |
| + NotificationStorage.markAsShown(notification.id); |
| +} |
| /** |
| * Initializes the notification system. |