diff --git a/index.js b/index.js index dabd020..58e3319 100644 --- a/index.js +++ b/index.js @@ -22,11 +22,9 @@ function createWindow () { var tray = require('./tray'); tray.init(win); - var menu = require('./menu'); - menu.init(win); - - var drag = require('./drag-drop-main'); - drag.init(win); + require('./menu').init(win); + require('./progress').init(win); + require('./drag-drop-main').init(win); // Open the DevTools. win.webContents.openDevTools(); diff --git a/notifications.js b/notifications.js index 645ff9a..8a8c050 100644 --- a/notifications.js +++ b/notifications.js @@ -1,4 +1,6 @@ ;(function () { + var electron = require('electron'); + var ipc = electron.ipcRenderer; // This file runs in a render thread of the Electron app. It must be required (directly or // indirectly) from one of the html files. @@ -16,8 +18,11 @@ notif.close(); }; notif.onclose = function () { - setTimeout(notifyUser, 5000); + if (count < 10) { + setTimeout(notifyUser, 5000); + } }; + ipc.send('notification', count); } setTimeout(notifyUser, 1000); }()); diff --git a/progress.js b/progress.js new file mode 100644 index 0000000..7621412 --- /dev/null +++ b/progress.js @@ -0,0 +1,34 @@ +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;