Left: | ||
Right: |
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 |
(...skipping 188 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
199 let notificationOptions = { | 199 let notificationOptions = { |
200 type: "basic", | 200 type: "basic", |
201 title, | 201 title, |
202 iconUrl, | 202 iconUrl, |
203 message, | 203 message, |
204 buttons: activeButtons.map(button => ({title: button.title})), | 204 buttons: activeButtons.map(button => ({title: button.title})), |
205 // We use the highest priority to prevent the notification | 205 // We use the highest priority to prevent the notification |
206 // from closing automatically. | 206 // from closing automatically. |
207 priority: 2 | 207 priority: 2 |
208 }; | 208 }; |
209 browser.notifications.create("", notificationOptions, () => | 209 |
210 // Firefox and Opera don't support buttons. Firefox throws synchronously, | |
211 // while Opera gives an asynchronous error. Wrapping the promise like | |
212 // this, turns the synchronus error on Firefox into a promise rejection. | |
kzar
2018/03/19 08:34:59
Nit: Spelling of "synchronous"
Sebastian Noack
2018/03/19 16:58:23
Done.
| |
213 new Promise(resolve => | |
210 { | 214 { |
211 // Opera does not support the addition of buttons to notifications. | 215 resolve(browser.notifications.create(notificationOptions)); |
212 // Question type notfications always include buttons. | 216 }).catch(() => |
213 if (browser.runtime.lastError && activeNotification.type != "question") | 217 { |
218 // Without buttons, showing notifications of the type "question" is | |
219 // pointless. For other notifications, retry with the buttons removed. | |
220 if (activeNotification.type != "question") | |
214 { | 221 { |
215 delete notificationOptions.buttons; | 222 delete notificationOptions.buttons; |
216 browser.notifications.create("", notificationOptions); | 223 browser.notifications.create(notificationOptions); |
217 } | 224 } |
218 }); | 225 }); |
219 } | 226 } |
220 else if ("Notification" in window && activeNotification.type != "question") | 227 else if ("Notification" in window && activeNotification.type != "question") |
221 { | 228 { |
222 if (linkCount > 0) | 229 if (linkCount > 0) |
223 { | 230 { |
224 message += " " + browser.i18n.getMessage( | 231 message += " " + browser.i18n.getMessage( |
225 "notification_without_buttons" | 232 "notification_without_buttons" |
226 ); | 233 ); |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
293 let methods = displayMethods[notificationType] || defaultDisplayMethods; | 300 let methods = displayMethods[notificationType] || defaultDisplayMethods; |
294 return methods.includes(method); | 301 return methods.includes(method); |
295 }; | 302 }; |
296 | 303 |
297 ext.pages.onLoading.addListener(page => | 304 ext.pages.onLoading.addListener(page => |
298 { | 305 { |
299 NotificationStorage.showNext(stringifyURL(page.url)); | 306 NotificationStorage.showNext(stringifyURL(page.url)); |
300 }); | 307 }); |
301 | 308 |
302 NotificationStorage.addShowListener(showNotification); | 309 NotificationStorage.addShowListener(showNotification); |
OLD | NEW |