summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Dolgov <[email protected]>2021-03-09 17:22:22 +0300
committerAndrew Dolgov <[email protected]>2021-03-09 17:22:22 +0300
commit46847fd112b3c56f383af9ed2808e8451957bede (patch)
treee0d06089842ec719676c820e57c92b7f6c2f1087
parent9df7cbd5299359413d04233860031ae008c5b152 (diff)
can't use requestAnimationFrame in background
-rw-r--r--init.js65
1 files changed, 31 insertions, 34 deletions
diff --git a/init.js b/init.js
index 4689d89..d3e5891 100644
--- a/init.js
+++ b/init.js
@@ -4,49 +4,46 @@ require(['dojo/_base/kernel', 'dojo/ready'], function (dojo, ready) {
ready(function() {
function updateFaviconBadge(unread = 0, fresh = 0) {
- window.requestAnimationFrame(() => {
+ const canvas = document.createElement('canvas');
+ canvas.width = 16;
+ canvas.height = 16;
+ if (canvas.getContext) {
- const canvas = document.createElement('canvas');
- canvas.width = 16;
- canvas.height = 16;
- if (canvas.getContext) {
+ const link = App.find("link[rel='shortcut icon']");
- const link = App.find("link[rel='shortcut icon']");
+ const ctx = canvas.getContext('2d');
+ const img = new Image();
+ img.src = 'images/favicon.png';
+ img.onload = function() {
+ if (unread > 0 || fresh > 0) {
- const ctx = canvas.getContext('2d');
- const img = new Image();
- img.src = 'images/favicon.png';
- img.onload = function() {
- if (unread > 0 || fresh > 0) {
+ let bg_color = "#257aa7";
+ let count = unread;
- let bg_color = "#257aa7";
- let count = unread;
-
- if (fresh > 0) {
- count = fresh;
- bg_color = "#25a738";
- }
+ if (fresh > 0) {
+ count = fresh;
+ bg_color = "#25a738";
+ }
- if (count > 99)
- count = 99;
+ if (count > 99)
+ count = 99;
- ctx.fillStyle = bg_color;
- ctx.fillRect(0, 0, 16, 16);
+ ctx.fillStyle = bg_color;
+ ctx.fillRect(0, 0, 16, 16);
- ctx.fillStyle = 'white';
- ctx.font = 'bold 10px sans-serif';
- ctx.textAlign = 'center';
- ctx.fillText(count, 8, 11);
+ ctx.fillStyle = 'white';
+ ctx.font = 'bold 10px sans-serif';
+ ctx.textAlign = 'center';
+ ctx.fillText(count, 8, 11);
- } else {
- ctx.drawImage(img, 0, 0, 16, 16);
- }
+ } else {
+ ctx.drawImage(img, 0, 0, 16, 16);
+ }
- link.type = 'image/x-icon';
- link.href = canvas.toDataURL("image/x-icon");
- };
- }
- });
+ link.type = 'image/x-icon';
+ link.href = canvas.toDataURL("image/x-icon");
+ };
+ }
}
PluginHost.register(PluginHost.HOOK_COUNTERS_PROCESSED, () => {