pr comment changes and progress line starts from top instead of right

Co-authored-by: timvisee <tim@visee.me>
This commit is contained in:
Ashesh Vidyut 2019-03-21 23:37:11 +05:30 committed by timvisee
parent 8d80ba1f69
commit a6a3cae5e9
No known key found for this signature in database
GPG key ID: B8DB720BC383E172
4 changed files with 37 additions and 44 deletions

View file

@ -1,48 +1,43 @@
const { platform } = require('../utils');
const assets = require('../../common/assets');
module.exports.updateFavicon = function(percentageString) {
const loaderWidth = 5;
const loaderColor = '#0090ed';
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 size = 32;
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) {
if (platform() === 'web') {
let progress = parseInt(percentageString.replace('%', ''));
const link = document.querySelector("link[rel*='icon']");
const progress = progressRatio * 100;
if (progress === 0 || progress === 100) {
const link = document.querySelector("link[rel*='icon']");
link.type = 'image/png';
link.href = assets.get('favicon-32x32.png');
document.getElementsByTagName('head')[0].appendChild(link);
return;
}
progress = progress * 0.01;
const link = document.querySelector("link[rel*='icon']");
const canvas = document.createElement('canvas');
const size = 32;
const loaderWidth = 5;
const loaderColor = '#0090ed';
const span = document.createElement('span');
span.textContent = percentageString;
const context = canvas.getContext('2d');
canvas.width = canvas.height = size;
context.translate(size * 0.5, size * 0.5);
const drawCircle = function(color, lineWidth, outerWidth, percent) {
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();
};
const drawNewFavicon = function() {
drawCircle('#efefef', loaderWidth, size, 1);
drawCircle(loaderColor, loaderWidth, size, progress);
};
drawNewFavicon(link);
link.href = canvas.toDataURL();
link.href = drawNewFavicon(progressRatio);
document.getElementsByTagName('head')[0].appendChild(link);
}
};