Left: | ||
Right: |
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); |
kzar
2016/01/28 09:51:04
Arrow functions are for anonymous functions, if i
Sebastian Noack
2016/01/28 10:14:21
We have to assign to the global variable onActivat
kzar
2016/01/28 10:19:57
Acknowledged.
| |
129 pages.push(page); | 129 setIcon(page, notificationType, opacity, frames); |
130 setIcon(page, notificationType, opacity, frames); | 130 }; |
131 }; | 131 ext.pages.onActivated.addListener(onActivated); |
132 ext.pages.onActivated.addListener(onActivated); | 132 |
133 | 133 frameInterval = setInterval(() => |
134 frameInterval = setInterval(() => | 134 { |
135 let oldOpacity = opacity; | |
136 opacity = frameOpacities[animationStep++]; | |
137 | |
138 if (opacity != oldOpacity) | |
135 { | 139 { |
136 let oldOpacity = opacity; | 140 for (let page of pages) |
137 opacity = frameOpacities[animationStep++]; | |
138 | |
139 if (opacity != oldOpacity) | |
Sebastian Noack
2016/01/27 19:09:20
On my notebook (X230 with i7), I observed signific
kzar
2016/01/28 09:51:04
Of course, good idea.
| |
140 { | 141 { |
141 for (let page of pages) | 142 if (whitelistedState.has(page)) |
142 { | 143 setIcon(page, notificationType, opacity, frames); |
143 if (whitelistedState.has(page)) | |
144 setIcon(page, notificationType, opacity, frames); | |
145 } | |
146 } | 144 } |
147 | 145 } |
148 if (animationStep > numberOfFrames) | 146 |
149 { | 147 if (animationStep > numberOfFrames) |
150 clearInterval(frameInterval); | 148 { |
151 ext.pages.onActivated.removeListener(onActivated); | 149 clearInterval(frameInterval); |
152 frameInterval = onActivated = null; | 150 ext.pages.onActivated.removeListener(onActivated); |
153 } | 151 frameInterval = onActivated = null; |
154 }, 100); | 152 } |
155 }); | 153 }, 100); |
156 } | 154 }); |
157 | 155 } |
156 | |
157 function runAnimationLoop(notificationType) | |
158 { | |
158 renderFrames(notificationType).then(frames => | 159 renderFrames(notificationType).then(frames => |
159 { | 160 { |
160 playAnimation(frames); | 161 animateIcon(notificationType, frames); |
161 animationInterval = setInterval(() => { playAnimation(frames); }, 10000); | 162 animationInterval = setInterval(() => |
163 { | |
164 animateIcon(notificationType, frames); | |
165 }, 10000); | |
162 }); | 166 }); |
163 } | 167 } |
164 | 168 |
165 /** | 169 /** |
166 * Set the browser action icon for the given page, indicating whether | 170 * Set the browser action icon for the given page, indicating whether |
167 * adblocking is active there, and considering the icon animation. | 171 * adblocking is active there, and considering the icon animation. |
168 * | 172 * |
169 * @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 |
170 * @param {Boolean} whitelisted Whether the page has been whitelisted | 174 * @param {Boolean} whitelisted Whether the page has been whitelisted |
171 */ | 175 */ |
172 exports.updateIcon = function(page, whitelisted) | 176 exports.updateIcon = function(page, whitelisted) |
173 { | 177 { |
174 whitelistedState.set(page, whitelisted); | 178 whitelistedState.set(page, whitelisted); |
175 if (frameInterval == null) | 179 if (frameInterval == null) |
176 setIcon(page); | 180 setIcon(page); |
177 }; | 181 }; |
178 | 182 |
179 let stopIconAnimation = | 183 let stopIconAnimation = |
180 /** | 184 /** |
181 * Stops to animate the browser action icon. | 185 * Stops to animate the browser action icon. |
182 */ | 186 */ |
183 exports.stopIconAnimation = function() | 187 exports.stopIconAnimation = function() |
184 { | 188 { |
185 if (frameInterval != null) | 189 if (frameInterval != null) |
186 clearInterval(frameInterval); | 190 clearInterval(frameInterval); |
187 if (animationInterval != null) | 191 if (animationInterval != null) |
188 clearInterval(animationInterval); | 192 clearInterval(animationInterval); |
189 if (onActivated) | 193 if (onActivated) |
Sebastian Noack
2016/01/27 19:09:20
Yeah, that was the memory leak mentioned in the is
kzar
2016/01/28 09:51:04
Dang, good point. (Note, my stopAnimation closure
Sebastian Noack
2016/01/28 10:14:21
(Not really, it doesn't matter where you do the cl
| |
190 ext.pages.onActivated.removeListener(onActivated); | 194 ext.pages.onActivated.removeListener(onActivated); |
191 frameInterval = animationInterval = onActivated = null; | 195 frameInterval = animationInterval = onActivated = null; |
192 }; | 196 }; |
193 | 197 |
194 /** | 198 /** |
195 * 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. |
196 * | 200 * |
197 * @param {string} type The notification type (i.e: "information" or "critical" ) | 201 * @param {string} type The notification type (i.e: "information" or "critical" ) |
198 */ | 202 */ |
199 exports.startIconAnimation = function(type) | 203 exports.startIconAnimation = function(type) |
200 { | 204 { |
201 stopIconAnimation(); | 205 stopIconAnimation(); |
202 runAnimation(type); | 206 runAnimationLoop(type); |
203 }; | 207 }; |
LEFT | RIGHT |