Merge branch 'favicon-progress' into 'master'
Show upload progress in favicon See merge request timvisee/send!5
This commit is contained in:
commit
f999c4c44f
|
@ -1,13 +1,14 @@
|
||||||
import FileSender from './fileSender';
|
|
||||||
import FileReceiver from './fileReceiver';
|
|
||||||
import { copyToClipboard, delay, openLinksInNewTab, percent } from './utils';
|
|
||||||
import * as metrics from './metrics';
|
import * as metrics from './metrics';
|
||||||
import { bytes, locale } from './utils';
|
import FileReceiver from './fileReceiver';
|
||||||
import okDialog from './ui/okDialog';
|
import FileSender from './fileSender';
|
||||||
import copyDialog from './ui/copyDialog';
|
import copyDialog from './ui/copyDialog';
|
||||||
|
import faviconProgressbar from './ui/faviconProgressbar';
|
||||||
|
import okDialog from './ui/okDialog';
|
||||||
import shareDialog from './ui/shareDialog';
|
import shareDialog from './ui/shareDialog';
|
||||||
import signupDialog from './ui/signupDialog';
|
import signupDialog from './ui/signupDialog';
|
||||||
import surveyDialog from './ui/surveyDialog';
|
import surveyDialog from './ui/surveyDialog';
|
||||||
|
import { bytes, locale } from './utils';
|
||||||
|
import { copyToClipboard, delay, openLinksInNewTab, percent } from './utils';
|
||||||
|
|
||||||
export default function(state, emitter) {
|
export default function(state, emitter) {
|
||||||
let lastRender = 0;
|
let lastRender = 0;
|
||||||
|
@ -29,6 +30,7 @@ export default function(state, emitter) {
|
||||||
if (updateTitle) {
|
if (updateTitle) {
|
||||||
emitter.emit('DOMTitleChange', percent(state.transfer.progressRatio));
|
emitter.emit('DOMTitleChange', percent(state.transfer.progressRatio));
|
||||||
}
|
}
|
||||||
|
faviconProgressbar.updateFavicon(state.transfer.progressRatio);
|
||||||
render();
|
render();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -37,6 +39,7 @@ export default function(state, emitter) {
|
||||||
document.addEventListener('focus', () => {
|
document.addEventListener('focus', () => {
|
||||||
updateTitle = false;
|
updateTitle = false;
|
||||||
emitter.emit('DOMTitleChange', 'Send');
|
emitter.emit('DOMTitleChange', 'Send');
|
||||||
|
faviconProgressbar.updateFavicon(0);
|
||||||
});
|
});
|
||||||
checkFiles();
|
checkFiles();
|
||||||
});
|
});
|
||||||
|
@ -83,6 +86,7 @@ export default function(state, emitter) {
|
||||||
|
|
||||||
emitter.on('cancel', () => {
|
emitter.on('cancel', () => {
|
||||||
state.transfer.cancel();
|
state.transfer.cancel();
|
||||||
|
faviconProgressbar.updateFavicon(0);
|
||||||
});
|
});
|
||||||
|
|
||||||
emitter.on('addFiles', async ({ files }) => {
|
emitter.on('addFiles', async ({ files }) => {
|
||||||
|
@ -161,6 +165,7 @@ export default function(state, emitter) {
|
||||||
state.storage.totalUploads += 1;
|
state.storage.totalUploads += 1;
|
||||||
const duration = Date.now() - start;
|
const duration = Date.now() - start;
|
||||||
metrics.completedUpload(archive, duration);
|
metrics.completedUpload(archive, duration);
|
||||||
|
faviconProgressbar.updateFavicon(0);
|
||||||
|
|
||||||
state.storage.addFile(ownedFile);
|
state.storage.addFile(ownedFile);
|
||||||
// TODO integrate password into /upload request
|
// TODO integrate password into /upload request
|
||||||
|
@ -264,6 +269,7 @@ export default function(state, emitter) {
|
||||||
duration,
|
duration,
|
||||||
password_protected: file.requiresPassword
|
password_protected: file.requiresPassword
|
||||||
});
|
});
|
||||||
|
faviconProgressbar.updateFavicon(0);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.message === '0') {
|
if (err.message === '0') {
|
||||||
// download cancelled
|
// download cancelled
|
||||||
|
|
|
@ -0,0 +1,41 @@
|
||||||
|
const { platform } = require('../utils');
|
||||||
|
const assets = require('../../common/assets');
|
||||||
|
|
||||||
|
const size = 32;
|
||||||
|
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 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') {
|
||||||
|
const link = document.querySelector("link[rel='icon'][sizes='32x32']");
|
||||||
|
const progress = progressRatio * 100;
|
||||||
|
if (progress === 0 || progress === 100) {
|
||||||
|
link.type = 'image/png';
|
||||||
|
link.href = assets.get('favicon-32x32.png');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
link.href = drawNewFavicon(progressRatio);
|
||||||
|
}
|
||||||
|
};
|
Loading…
Reference in New Issue