From 46847fd112b3c56f383af9ed2808e8451957bede Mon Sep 17 00:00:00 2001 From: Andrew Dolgov Date: Tue, 9 Mar 2021 17:22:22 +0300 Subject: can't use requestAnimationFrame in background --- init.js | 65 +++++++++++++++++++++++++++++++---------------------------------- 1 file 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, () => { -- cgit v1.2.3