electron-demo.js/progress.js

35 lines
643 B
JavaScript

var electron = require('electron');
var app = electron.app;
var ipc = electron.ipcMain;
var win;
function init(window) {
if (win) {
console.error("can't initialize badge/progress tracker multiple times");
return;
}
win = window;
ipc.on('notification', function (ev, count) {
updateProgress(count);
increaseBadge();
});
win.on('focus', clearBadge);
}
function increaseBadge() {
if (!win.isFocused()) {
app.setBadgeCount(app.getBadgeCount() + 1);
}
}
function clearBadge() {
app.setBadgeCount(0);
}
function updateProgress(count) {
win.setProgressBar((count % 10)/10);
}
module.exports.init = init;