Skip to content
This repository has been archived by the owner on Nov 30, 2021. It is now read-only.

Commit

Permalink
Move createBadgeDataUrl() into separate utils file
Browse files Browse the repository at this point in the history
  • Loading branch information
aluxian committed Mar 15, 2017
1 parent bae9c98 commit e0d8db6
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 28 deletions.
30 changes: 30 additions & 0 deletions src/scripts/common/utils/graphics.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
function createBadgeDataUrl (text) {
const canvas = document.createElement('canvas');
canvas.height = 140;
canvas.width = 140;

const context = canvas.getContext('2d');
context.fillStyle = 'red';
context.beginPath();
context.ellipse(70, 70, 70, 70, 0, 0, 2 * Math.PI);
context.fill();
context.textAlign = 'center';
context.fillStyle = 'white';

if (text.length > 2) {
context.font = 'bold 65px "Segoe UI", sans-serif';
context.fillText('' + text, 70, 95);
} else if (text.length > 1) {
context.font = 'bold 85px "Segoe UI", sans-serif';
context.fillText('' + text, 70, 100);
} else {
context.font = 'bold 100px "Segoe UI", sans-serif';
context.fillText('' + text, 70, 105);
}

return canvas.toDataURL();
}

export default {
createBadgeDataUrl
};
30 changes: 2 additions & 28 deletions src/scripts/renderer/webview/listeners.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,37 +2,11 @@ import {shell, remote} from 'electron';

import webView from 'renderer/webview';
import platform from 'common/utils/platform';
import graphics from 'common/utils/graphics';
import files from 'common/utils/files';
import prefs from 'common/utils/prefs';
import urls from 'common/utils/urls';

function createBadgeDataUrl (text) {
const canvas = document.createElement('canvas');
canvas.height = 140;
canvas.width = 140;

const context = canvas.getContext('2d');
context.fillStyle = 'red';
context.beginPath();
context.ellipse(70, 70, 70, 70, 0, 0, 2 * Math.PI);
context.fill();
context.textAlign = 'center';
context.fillStyle = 'white';

if (text.length > 2) {
context.font = 'bold 65px "Segoe UI", sans-serif';
context.fillText('' + text, 70, 95);
} else if (text.length > 1) {
context.font = 'bold 85px "Segoe UI", sans-serif';
context.fillText('' + text, 70, 100);
} else {
context.font = 'bold 100px "Segoe UI", sans-serif';
context.fillText('' + text, 70, 105);
}

return canvas.toDataURL();
}

// Log console messages
webView.addEventListener('console-message', function (event) {
const msg = event.message.replace(/%c/g, '');
Expand All @@ -50,7 +24,7 @@ webView.addEventListener('page-title-updated', function () {
let badgeDataUrl = null;

if (platform.isWindows && count) {
badgeDataUrl = createBadgeDataUrl(count);
badgeDataUrl = graphics.createBadgeDataUrl(count);
}

log('notifying window of notif-count', count, !!badgeDataUrl || null);
Expand Down

0 comments on commit e0d8db6

Please sign in to comment.