2017-05-19 19:19:43 +00:00
|
|
|
'use strict';
|
|
|
|
|
2017-04-21 21:41:37 +00:00
|
|
|
var electron = require('electron');
|
|
|
|
var app = electron.app;
|
|
|
|
var ipc = electron.ipcMain;
|
|
|
|
|
|
|
|
var win;
|
|
|
|
|
|
|
|
function increaseBadge() {
|
|
|
|
if (!win.isFocused()) {
|
|
|
|
app.setBadgeCount(app.getBadgeCount() + 1);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
function clearBadge() {
|
|
|
|
app.setBadgeCount(0);
|
|
|
|
}
|
|
|
|
|
2017-04-24 21:11:42 +00:00
|
|
|
function updateProgress(count, target) {
|
|
|
|
if (count < 0 || count <= target) {
|
|
|
|
win.setProgressBar(0);
|
|
|
|
} else {
|
|
|
|
win.setProgressBar(count/target);
|
|
|
|
}
|
2017-04-21 21:41:37 +00:00
|
|
|
}
|
|
|
|
|
2017-05-19 19:19:43 +00:00
|
|
|
function init(window) {
|
|
|
|
if (win) {
|
|
|
|
console.error("can't initialize badge/progress tracker multiple times");
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
win = window;
|
|
|
|
|
|
|
|
ipc.on('notification', function (ev, count, target) {
|
|
|
|
updateProgress(count, target);
|
|
|
|
increaseBadge();
|
|
|
|
});
|
|
|
|
win.on('focus', clearBadge);
|
|
|
|
}
|
|
|
|
|
2017-04-21 21:41:37 +00:00
|
|
|
module.exports.init = init;
|