LEFT | RIGHT |
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 98 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 imageData[size] = context.getImageData(0, 0, size, size); | 109 imageData[size] = context.getImageData(0, 0, size, size); |
110 } | 110 } |
111 frames["" + opacity + whitelisted] = imageData; | 111 frames["" + opacity + whitelisted] = imageData; |
112 } | 112 } |
113 } | 113 } |
114 | 114 |
115 return frames; | 115 return frames; |
116 }); | 116 }); |
117 } | 117 } |
118 | 118 |
119 function runAnimation(notificationType) | 119 function animateIcon(notificationType, frames) |
120 { | 120 { |
121 function playAnimation(frames) | 121 ext.pages.query({active: true}, pages => |
122 { | 122 { |
123 ext.pages.query({active: true}, pages => | 123 let animationStep = 0; |
124 { | 124 let opacity = 0; |
125 let animationStep = 0; | 125 |
126 let opacity = 0; | 126 onActivated = page => |
127 | 127 { |
128 onActivated = page => | 128 pages.push(page); |
| 129 setIcon(page, notificationType, opacity, frames); |
| 130 }; |
| 131 ext.pages.onActivated.addListener(onActivated); |
| 132 |
| 133 frameInterval = setInterval(() => |
| 134 { |
| 135 let oldOpacity = opacity; |
| 136 opacity = frameOpacities[animationStep++]; |
| 137 |
| 138 if (opacity != oldOpacity) |
129 { | 139 { |
130 pages.push(page); | 140 for (let page of pages) |
131 setIcon(page, notificationType, opacity, frames); | 141 { |
132 }; | 142 if (whitelistedState.has(page)) |
133 ext.pages.onActivated.addListener(onActivated); | 143 setIcon(page, notificationType, opacity, frames); |
134 | 144 } |
135 frameInterval = setInterval(() => | 145 } |
| 146 |
| 147 if (animationStep > numberOfFrames) |
136 { | 148 { |
137 let oldOpacity = opacity; | 149 clearInterval(frameInterval); |
138 opacity = frameOpacities[animationStep++]; | 150 ext.pages.onActivated.removeListener(onActivated); |
139 | 151 frameInterval = onActivated = null; |
140 if (opacity != oldOpacity) | 152 } |
141 { | 153 }, 100); |
142 for (let page of pages) | 154 }); |
143 { | 155 } |
144 if (whitelistedState.has(page)) | 156 |
145 setIcon(page, notificationType, opacity, frames); | 157 function runAnimationLoop(notificationType) |
146 } | 158 { |
147 } | |
148 | |
149 if (animationStep > numberOfFrames) | |
150 { | |
151 clearInterval(frameInterval); | |
152 ext.pages.onActivated.removeListener(onActivated); | |
153 frameInterval = onActivated = null; | |
154 } | |
155 }, 100); | |
156 }); | |
157 } | |
158 | |
159 renderFrames(notificationType).then(frames => | 159 renderFrames(notificationType).then(frames => |
160 { | 160 { |
161 playAnimation(frames); | 161 animateIcon(notificationType, frames); |
162 animationInterval = setInterval(() => { playAnimation(frames); }, 10000); | 162 animationInterval = setInterval(() => |
| 163 { |
| 164 animateIcon(notificationType, frames); |
| 165 }, 10000); |
163 }); | 166 }); |
164 } | 167 } |
165 | 168 |
166 /** | 169 /** |
167 * Set the browser action icon for the given page, indicating whether | 170 * Set the browser action icon for the given page, indicating whether |
168 * adblocking is active there, and considering the icon animation. | 171 * adblocking is active there, and considering the icon animation. |
169 * | 172 * |
170 * @param {Page} page The page to set the browser action icon for | 173 * @param {Page} page The page to set the browser action icon for |
171 * @param {Boolean} whitelisted Whether the page has been whitelisted | 174 * @param {Boolean} whitelisted Whether the page has been whitelisted |
172 */ | 175 */ |
(...skipping 20 matching lines...) Expand all Loading... |
193 }; | 196 }; |
194 | 197 |
195 /** | 198 /** |
196 * Starts to animate the browser action icon to indicate a pending notifcation. | 199 * Starts to animate the browser action icon to indicate a pending notifcation. |
197 * | 200 * |
198 * @param {string} type The notification type (i.e: "information" or "critical"
) | 201 * @param {string} type The notification type (i.e: "information" or "critical"
) |
199 */ | 202 */ |
200 exports.startIconAnimation = function(type) | 203 exports.startIconAnimation = function(type) |
201 { | 204 { |
202 stopIconAnimation(); | 205 stopIconAnimation(); |
203 runAnimation(type); | 206 runAnimationLoop(type); |
204 }; | 207 }; |
LEFT | RIGHT |