Index: lib/icon.js |
=================================================================== |
--- a/lib/icon.js |
+++ b/lib/icon.js |
@@ -27,6 +27,7 @@ |
let frameInterval = null; |
let animationInterval = null; |
+let onActivated = null; |
let whitelistedState = new ext.PageMap(); |
function loadImage(url) |
@@ -119,30 +120,37 @@ |
{ |
function playAnimation(frames) |
{ |
- let animationStep = 0; |
ext.pages.query({active: true}, pages => |
{ |
- function appendActivePage(page) |
+ let animationStep = 0; |
+ let opacity = 0; |
+ |
+ onActivated = page => |
{ |
pages.push(page); |
- } |
- ext.pages.onActivated.addListener(appendActivePage); |
+ setIcon(page, notificationType, opacity, frames); |
+ }; |
+ ext.pages.onActivated.addListener(onActivated); |
frameInterval = setInterval(() => |
{ |
- let opacity = frameOpacities[animationStep++]; |
- for (let page of pages) |
+ let oldOpacity = opacity; |
+ opacity = frameOpacities[animationStep++]; |
+ |
+ if (opacity != oldOpacity) |
{ |
- if (whitelistedState.has(page)) |
- setIcon(page, notificationType, opacity, frames); |
- }; |
+ for (let page of pages) |
+ { |
+ if (whitelistedState.has(page)) |
+ setIcon(page, notificationType, opacity, frames); |
+ } |
+ } |
if (animationStep > numberOfFrames) |
{ |
- animationStep = 0; |
clearInterval(frameInterval); |
- frameInterval = null; |
- ext.pages.onActivated.removeListener(appendActivePage); |
+ ext.pages.onActivated.removeListener(onActivated); |
+ frameInterval = onActivated = null; |
} |
}, 100); |
}); |
@@ -179,7 +187,9 @@ |
clearInterval(frameInterval); |
if (animationInterval != null) |
clearInterval(animationInterval); |
- frameInterval = animationInterval = null; |
+ if (onActivated) |
+ ext.pages.onActivated.removeListener(onActivated); |
+ frameInterval = animationInterval = onActivated = null; |
}; |
/** |