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-2016 Eyeo GmbH | 3 * Copyright (C) 2006-2016 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 |
(...skipping 21 matching lines...) Expand all Loading... |
32 displayMethods.question = ["notification"]; | 32 displayMethods.question = ["notification"]; |
33 displayMethods.normal = ["notification"]; | 33 displayMethods.normal = ["notification"]; |
34 displayMethods.information = ["icon", "popup"]; | 34 displayMethods.information = ["icon", "popup"]; |
35 | 35 |
36 let platform = require("info").platform; | 36 let platform = require("info").platform; |
37 let canUseChromeNotifications = platform == "chromium" && "notifications" in chr
ome; | 37 let canUseChromeNotifications = platform == "chromium" && "notifications" in chr
ome; |
38 | 38 |
39 function prepareNotificationIconAndPopup() | 39 function prepareNotificationIconAndPopup() |
40 { | 40 { |
41 let animateIcon = shouldDisplay("icon", activeNotification.type); | 41 let animateIcon = shouldDisplay("icon", activeNotification.type); |
42 activeNotification.onClicked = function() | 42 activeNotification.onClicked = () => |
43 { | 43 { |
44 if (animateIcon) | 44 if (animateIcon) |
45 stopIconAnimation(); | 45 stopIconAnimation(); |
46 notificationClosed(); | 46 notificationClosed(); |
47 }; | 47 }; |
48 if (animateIcon) | 48 if (animateIcon) |
49 startIconAnimation(activeNotification.type); | 49 startIconAnimation(activeNotification.type); |
50 } | 50 } |
51 | 51 |
52 function getNotificationButtons(notificationType, message) | 52 function getNotificationButtons(notificationType, message) |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
116 switch (activeButtons[buttonIndex].type) | 116 switch (activeButtons[buttonIndex].type) |
117 { | 117 { |
118 case "link": | 118 case "link": |
119 ext.pages.open(Utils.getDocLink(activeNotification.links[buttonIndex])); | 119 ext.pages.open(Utils.getDocLink(activeNotification.links[buttonIndex])); |
120 break; | 120 break; |
121 case "open-all": | 121 case "open-all": |
122 openNotificationLinks(); | 122 openNotificationLinks(); |
123 break; | 123 break; |
124 case "configure": | 124 case "configure": |
125 Prefs.notifications_showui = true; | 125 Prefs.notifications_showui = true; |
126 ext.showOptions(function(page) | 126 ext.showOptions(page => |
127 { | 127 { |
128 page.sendMessage({ | 128 page.sendMessage({ |
129 type: "app.respond", | 129 type: "app.respond", |
130 action: "focusSection", | 130 action: "focusSection", |
131 args: ["notifications"] | 131 args: ["notifications"] |
132 }); | 132 }); |
133 }); | 133 }); |
134 break; | 134 break; |
135 case "question": | 135 case "question": |
136 NotificationStorage.triggerQuestionListeners(activeNotification.id, button
Index == 0); | 136 NotificationStorage.triggerQuestionListeners(activeNotification.id, button
Index == 0); |
137 NotificationStorage.markAsShown(activeNotification.id); | 137 NotificationStorage.markAsShown(activeNotification.id); |
138 activeNotification.onClicked(); | 138 activeNotification.onClicked(); |
139 break; | 139 break; |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
143 function notificationClosed() | 143 function notificationClosed() |
144 { | 144 { |
145 activeNotification = null; | 145 activeNotification = null; |
146 } | 146 } |
147 | 147 |
148 function initChromeNotifications() | 148 function initChromeNotifications() |
149 { | 149 { |
150 // Chrome hides notifications in notification center when clicked so we need t
o clear them | 150 // Chrome hides notifications in notification center when clicked so we need t
o clear them |
151 function clearActiveNotification(notificationId) | 151 function clearActiveNotification(notificationId) |
152 { | 152 { |
153 if (activeNotification && activeNotification.type != "question" && !("links"
in activeNotification)) | 153 if (activeNotification && activeNotification.type != "question" && !("links"
in activeNotification)) |
154 return; | 154 return; |
155 | 155 |
156 chrome.notifications.clear(notificationId, function(wasCleared) | 156 chrome.notifications.clear(notificationId, wasCleared => |
157 { | 157 { |
158 if (wasCleared) | 158 if (wasCleared) |
159 notificationClosed(); | 159 notificationClosed(); |
160 }); | 160 }); |
161 } | 161 } |
162 | 162 |
163 chrome.notifications.onButtonClicked.addListener(function(notificationId, butt
onIndex) | 163 chrome.notifications.onButtonClicked.addListener((notificationId, buttonIndex)
=> |
164 { | 164 { |
165 notificationButtonClick(buttonIndex); | 165 notificationButtonClick(buttonIndex); |
166 clearActiveNotification(notificationId); | 166 clearActiveNotification(notificationId); |
167 }); | 167 }); |
168 chrome.notifications.onClicked.addListener(clearActiveNotification); | 168 chrome.notifications.onClicked.addListener(clearActiveNotification); |
169 chrome.notifications.onClosed.addListener(notificationClosed); | 169 chrome.notifications.onClosed.addListener(notificationClosed); |
170 } | 170 } |
171 | 171 |
172 function showNotification(notification) | 172 function showNotification(notification) |
173 { | 173 { |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
225 else if (approved) | 225 else if (approved) |
226 openNotificationLinks(); | 226 openNotificationLinks(); |
227 } | 227 } |
228 } | 228 } |
229 prepareNotificationIconAndPopup(); | 229 prepareNotificationIconAndPopup(); |
230 }; | 230 }; |
231 | 231 |
232 /** | 232 /** |
233 * Initializes the notification system. | 233 * Initializes the notification system. |
234 */ | 234 */ |
235 exports.initNotifications = function() | 235 exports.initNotifications = () => |
236 { | 236 { |
237 if (canUseChromeNotifications) | 237 if (canUseChromeNotifications) |
238 initChromeNotifications(); | 238 initChromeNotifications(); |
239 initAntiAdblockNotification(); | 239 initAntiAdblockNotification(); |
240 }; | 240 }; |
241 | 241 |
242 /** | 242 /** |
243 * Gets the active notification to be shown if any. | 243 * Gets the active notification to be shown if any. |
244 * | 244 * |
245 * @return {?object} | 245 * @return {?object} |
246 */ | 246 */ |
247 exports.getActiveNotification = function() | 247 exports.getActiveNotification = () => activeNotification; |
248 { | |
249 return activeNotification; | |
250 }; | |
251 | 248 |
252 let shouldDisplay = | 249 let shouldDisplay = |
253 /** | 250 /** |
254 * Determines whether a given display method should be used for a | 251 * Determines whether a given display method should be used for a |
255 * specified notification type. | 252 * specified notification type. |
256 * | 253 * |
257 * @param {string} method Display method: icon, notification or popup | 254 * @param {string} method Display method: icon, notification or popup |
258 * @param {string} notificationType | 255 * @param {string} notificationType |
259 * @return {boolean} | 256 * @return {boolean} |
260 */ | 257 */ |
261 exports.shouldDisplay = function(method, notificationType) | 258 exports.shouldDisplay = (method, notificationType) => |
262 { | 259 { |
263 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 260 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
264 return methods.indexOf(method) > -1; | 261 return methods.indexOf(method) > -1; |
265 }; | 262 }; |
266 | 263 |
267 ext.pages.onLoading.addListener(page => | 264 ext.pages.onLoading.addListener(page => |
268 { | 265 { |
269 NotificationStorage.showNext(stringifyURL(page.url)); | 266 NotificationStorage.showNext(stringifyURL(page.url)); |
270 }); | 267 }); |
271 | 268 |
272 NotificationStorage.addShowListener(showNotification); | 269 NotificationStorage.addShowListener(showNotification); |
OLD | NEW |