Skip to content

Instantly share code, notes, and snippets.

@daemongh
Created November 3, 2015 23:17
Show Gist options
  • Save daemongh/58ce416bb1fa638174a0 to your computer and use it in GitHub Desktop.
Save daemongh/58ce416bb1fa638174a0 to your computer and use it in GitHub Desktop.
setBadge = function (text) {
if (process.platform === "darwin") {
app.dock.setBadge("" + text);
} else if (process.platform === "win32") {
var win = remote.getCurrentWindow();
if (text === "") {
win.setOverlayIcon(null, "");
return;
}
// Create badge
var canvas = document.createElement("canvas");
canvas.height = 140;
canvas.width = 140;
var ctx = canvas.getContext("2d");
ctx.fillStyle = "red";
ctx.beginPath();
ctx.ellipse(70, 70, 70, 70, 0, 0, 2 * Math.PI);
ctx.fill();
ctx.textAlign = "center";
ctx.fillStyle = "white";
if (text.length > 2) {
ctx.font = "75px sans-serif";
ctx.fillText("" + text, 70, 98);
} else if (text.length > 1) {
ctx.font = "100px sans-serif";
ctx.fillText("" + text, 70, 105);
} else {
ctx.font = "125px sans-serif";
ctx.fillText("" + text, 70, 112);
}
var badgeDataURL = canvas.toDataURL();
var img = NativeImage.createFromDataUrl(badgeDataURL);
win.setOverlayIcon(img, text);
}
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment