2022-04-12 13:58:58 +00:00
|
|
|
/*global WEB_UI*/
|
|
|
|
|
2019-03-20 18:37:46 +00:00
|
|
|
const { platform } = require('../utils');
|
|
|
|
const assets = require('../../common/assets');
|
|
|
|
|
2019-03-21 18:11:47 +00:00
|
|
|
const size = 32;
|
2019-03-21 18:07:11 +00:00
|
|
|
const loaderWidth = 5;
|
2022-04-12 13:58:58 +00:00
|
|
|
const loaderColor = WEB_UI.COLORS.PRIMARY;
|
2019-03-21 18:07:11 +00:00
|
|
|
|
|
|
|
function drawCircle(canvas, context, color, lineWidth, outerWidth, percent) {
|
|
|
|
canvas.width = canvas.height = outerWidth;
|
|
|
|
context.translate(outerWidth * 0.5, outerWidth * 0.5);
|
|
|
|
context.rotate(-Math.PI * 0.5);
|
|
|
|
const radius = (outerWidth - lineWidth) * 0.5;
|
|
|
|
context.beginPath();
|
|
|
|
context.arc(0, 0, radius, 0, Math.PI * 2 * percent, false);
|
|
|
|
context.strokeStyle = color;
|
|
|
|
context.lineCap = 'square';
|
|
|
|
context.lineWidth = lineWidth;
|
|
|
|
context.stroke();
|
|
|
|
}
|
|
|
|
|
|
|
|
function drawNewFavicon(progressRatio) {
|
|
|
|
const canvas = document.createElement('canvas');
|
|
|
|
const context = canvas.getContext('2d');
|
|
|
|
drawCircle(canvas, context, '#efefef', loaderWidth, size, 1);
|
|
|
|
drawCircle(canvas, context, loaderColor, loaderWidth, size, progressRatio);
|
|
|
|
return canvas.toDataURL();
|
|
|
|
}
|
|
|
|
|
|
|
|
module.exports.updateFavicon = function(progressRatio) {
|
2019-03-20 18:37:46 +00:00
|
|
|
if (platform() === 'web') {
|
2019-03-21 22:22:16 +00:00
|
|
|
const link = document.querySelector("link[rel='icon'][sizes='32x32']");
|
2019-03-21 18:07:11 +00:00
|
|
|
const progress = progressRatio * 100;
|
2019-03-20 19:38:11 +00:00
|
|
|
if (progress === 0 || progress === 100) {
|
2019-03-20 18:37:46 +00:00
|
|
|
link.type = 'image/png';
|
2022-04-12 13:58:58 +00:00
|
|
|
link.href =
|
|
|
|
WEB_UI.CUSTOM_ASSETS.favicon_32px !== ''
|
|
|
|
? WEB_UI.CUSTOM_ASSETS.favicon_32px
|
|
|
|
: assets.get('favicon-32x32.png');
|
2019-03-20 18:37:46 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2019-03-21 18:07:11 +00:00
|
|
|
link.href = drawNewFavicon(progressRatio);
|
2019-03-20 18:37:46 +00:00
|
|
|
}
|
|
|
|
};
|