| OLD | NEW |
| 1 /* | 1 /* |
| 2 * This file is part of Adblock Plus <https://adblockplus.org/>, | 2 * This file is part of Adblock Plus <https://adblockplus.org/>, |
| 3 * Copyright (C) 2006-present eyeo GmbH | 3 * Copyright (C) 2006-present eyeo GmbH |
| 4 * | 4 * |
| 5 * Adblock Plus is free software: you can redistribute it and/or modify | 5 * Adblock Plus is free software: you can redistribute it and/or modify |
| 6 * it under the terms of the GNU General Public License version 3 as | 6 * it under the terms of the GNU General Public License version 3 as |
| 7 * published by the Free Software Foundation. | 7 * published by the Free Software Foundation. |
| 8 * | 8 * |
| 9 * Adblock Plus is distributed in the hope that it will be useful, | 9 * Adblock Plus is distributed in the hope that it will be useful, |
| 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of | 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 12 * GNU General Public License for more details. | 12 * GNU General Public License for more details. |
| 13 * | 13 * |
| 14 * You should have received a copy of the GNU General Public License | 14 * You should have received a copy of the GNU General Public License |
| 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. | 15 * along with Adblock Plus. If not, see <http://www.gnu.org/licenses/>. |
| 16 */ | 16 */ |
| 17 | 17 |
| 18 /** @module notificationHelper */ | 18 /** @module notificationHelper */ |
| 19 | 19 |
| 20 "use strict"; | 20 import {startIconAnimation, stopIconAnimation} from "icon"; |
| 21 | 21 import {Utils} from "utils"; |
| 22 const {startIconAnimation, stopIconAnimation} = require("icon"); | 22 import {Notification as NotificationStorage} from "notification"; |
| 23 const {Utils} = require("utils"); | 23 import {stringifyURL} from "url"; |
| 24 const {Notification: NotificationStorage} = require("notification"); | 24 import {initAntiAdblockNotification} from "antiadblockInit"; |
| 25 const {stringifyURL} = require("url"); | 25 import {Prefs} from "prefs"; |
| 26 const {initAntiAdblockNotification} = require("antiadblockInit"); | 26 import {showOptions} from "options"; |
| 27 const {Prefs} = require("prefs"); | |
| 28 const {showOptions} = require("options"); | |
| 29 | 27 |
| 30 let activeNotification = null; | 28 let activeNotification = null; |
| 31 let activeButtons = null; | 29 let activeButtons = null; |
| 32 let defaultDisplayMethods = ["popup"]; | 30 let defaultDisplayMethods = ["popup"]; |
| 33 let displayMethods = Object.create(null); | 31 let displayMethods = Object.create(null); |
| 34 displayMethods.critical = ["icon", "notification", "popup"]; | 32 displayMethods.critical = ["icon", "notification", "popup"]; |
| 35 displayMethods.question = ["notification"]; | 33 displayMethods.question = ["notification"]; |
| 36 displayMethods.normal = ["notification"]; | 34 displayMethods.normal = ["notification"]; |
| 37 displayMethods.relentless = ["notification"]; | 35 displayMethods.relentless = ["notification"]; |
| 38 displayMethods.information = ["icon", "popup"]; | 36 displayMethods.information = ["icon", "popup"]; |
| (...skipping 219 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 } | 256 } |
| 259 prepareNotificationIconAndPopup(); | 257 prepareNotificationIconAndPopup(); |
| 260 | 258 |
| 261 if (notification.type !== "question") | 259 if (notification.type !== "question") |
| 262 NotificationStorage.markAsShown(notification.id); | 260 NotificationStorage.markAsShown(notification.id); |
| 263 } | 261 } |
| 264 | 262 |
| 265 /** | 263 /** |
| 266 * Initializes the notification system. | 264 * Initializes the notification system. |
| 267 */ | 265 */ |
| 268 exports.initNotifications = () => | 266 export const initNotifications = () => |
| 269 { | 267 { |
| 270 if ("notifications" in browser) | 268 if ("notifications" in browser) |
| 271 initChromeNotifications(); | 269 initChromeNotifications(); |
| 272 initAntiAdblockNotification(); | 270 initAntiAdblockNotification(); |
| 273 }; | 271 }; |
| 274 | 272 |
| 275 /** | 273 /** |
| 276 * Gets the active notification to be shown if any. | 274 * Gets the active notification to be shown if any. |
| 277 * | 275 * |
| 278 * @return {?object} | 276 * @return {?object} |
| 279 */ | 277 */ |
| 280 exports.getActiveNotification = () => activeNotification; | 278 export const getActiveNotification = () => activeNotification; |
| 281 | 279 |
| 282 let shouldDisplay = | |
| 283 /** | 280 /** |
| 284 * Determines whether a given display method should be used for a | 281 * Determines whether a given display method should be used for a |
| 285 * specified notification type. | 282 * specified notification type. |
| 286 * | 283 * |
| 287 * @param {string} method Display method: icon, notification or popup | 284 * @param {string} method Display method: icon, notification or popup |
| 288 * @param {string} notificationType | 285 * @param {string} notificationType |
| 289 * @return {boolean} | 286 * @return {boolean} |
| 290 */ | 287 */ |
| 291 exports.shouldDisplay = (method, notificationType) => | 288 export const shouldDisplay = (method, notificationType) => |
| 292 { | 289 { |
| 293 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 290 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
| 294 return methods.includes(method); | 291 return methods.includes(method); |
| 295 }; | 292 }; |
| 296 | 293 |
| 297 ext.pages.onLoading.addListener(page => | 294 ext.pages.onLoading.addListener(page => |
| 298 { | 295 { |
| 299 NotificationStorage.showNext(stringifyURL(page.url)); | 296 NotificationStorage.showNext(stringifyURL(page.url)); |
| 300 }); | 297 }); |
| 301 | 298 |
| 302 NotificationStorage.addShowListener(showNotification); | 299 NotificationStorage.addShowListener(showNotification); |
| OLD | NEW |