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 icon */ | 18 /** @module icon */ |
19 | 19 |
20 "use strict"; | 20 import {FilterNotifier} from "filterNotifier"; |
21 | |
22 const {FilterNotifier} = require("filterNotifier"); | |
23 | 21 |
24 const frameOpacities = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, | 22 const frameOpacities = [0.0, 0.1, 0.2, 0.3, 0.4, 0.5, 0.6, 0.7, 0.8, 0.9, |
25 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, | 23 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, 1.0, |
26 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]; | 24 0.9, 0.8, 0.7, 0.6, 0.5, 0.4, 0.3, 0.2, 0.1, 0.0]; |
27 const numberOfFrames = frameOpacities.length; | 25 const numberOfFrames = frameOpacities.length; |
28 | 26 |
29 let stopRequested = false; | 27 let stopRequested = false; |
30 let canUpdateIcon = true; | 28 let canUpdateIcon = true; |
31 let notRunning = Promise.resolve(); | 29 let notRunning = Promise.resolve(); |
32 let whitelistedState = new ext.PageMap(); | 30 let whitelistedState = new ext.PageMap(); |
(...skipping 143 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
176 if (animationStep > numberOfFrames) | 174 if (animationStep > numberOfFrames) |
177 { | 175 { |
178 clearInterval(interval); | 176 clearInterval(interval); |
179 ext.pages.onActivated.removeListener(onActivated); | 177 ext.pages.onActivated.removeListener(onActivated); |
180 canUpdateIcon = true; | 178 canUpdateIcon = true; |
181 } | 179 } |
182 }, 100); | 180 }, 100); |
183 }); | 181 }); |
184 } | 182 } |
185 | 183 |
186 let stopIconAnimation = | |
187 /** | 184 /** |
188 * Stops to animate the browser action icon | 185 * Stops to animate the browser action icon |
189 * after the current interval has been finished. | 186 * after the current interval has been finished. |
190 * | 187 * |
191 * @return {Promise} A promise that is fullfilled when | 188 * @return {Promise} A promise that is fullfilled when |
192 * the icon animation has been stopped. | 189 * the icon animation has been stopped. |
193 */ | 190 */ |
194 exports.stopIconAnimation = () => | 191 export const stopIconAnimation = () => |
195 { | 192 { |
196 stopRequested = true; | 193 stopRequested = true; |
197 return notRunning.then(() => | 194 return notRunning.then(() => |
198 { | 195 { |
199 stopRequested = false; | 196 stopRequested = false; |
200 }); | 197 }); |
201 }; | 198 }; |
202 | 199 |
203 /** | 200 /** |
204 * Starts to animate the browser action icon to indicate a pending notifcation. | 201 * Starts to animate the browser action icon to indicate a pending notifcation. |
205 * If the icon is already animated, it replaces the previous | 202 * If the icon is already animated, it replaces the previous |
206 * animation as soon as the current interval has been finished. | 203 * animation as soon as the current interval has been finished. |
207 * | 204 * |
208 * @param {string} type The notification type (i.e: "information" or | 205 * @param {string} type The notification type (i.e: "information" or |
209 * "critical".) | 206 * "critical".) |
210 */ | 207 */ |
211 exports.startIconAnimation = type => | 208 export const startIconAnimation = type => |
212 { | 209 { |
213 notRunning = new Promise(resolve => | 210 notRunning = new Promise(resolve => |
214 { | 211 { |
215 Promise.all([renderFrames(type), stopIconAnimation()]).then(results => | 212 Promise.all([renderFrames(type), stopIconAnimation()]).then(results => |
216 { | 213 { |
217 if (stopRequested) | 214 if (stopRequested) |
218 { | 215 { |
219 resolve(); | 216 resolve(); |
220 return; | 217 return; |
221 } | 218 } |
222 | 219 |
223 let frames = results[0]; | 220 let frames = results[0]; |
224 animateIcon(type, frames); | 221 animateIcon(type, frames); |
225 | 222 |
226 let interval = setInterval(() => | 223 let interval = setInterval(() => |
227 { | 224 { |
228 if (stopRequested) | 225 if (stopRequested) |
229 { | 226 { |
230 clearInterval(interval); | 227 clearInterval(interval); |
231 resolve(); | 228 resolve(); |
232 return; | 229 return; |
233 } | 230 } |
234 | 231 |
235 animateIcon(type, frames); | 232 animateIcon(type, frames); |
236 }, 10000); | 233 }, 10000); |
237 }); | 234 }); |
238 }); | 235 }); |
239 }; | 236 }; |
OLD | NEW |