From 8f2912225b451808200a56d91f7ad1c320bff178 Mon Sep 17 00:00:00 2001 From: tigerbot Date: Mon, 24 Apr 2017 15:11:42 -0600 Subject: [PATCH] update how/why the notifications fire --- index.html | 11 +++---- index.js | 8 ++--- notifications.js | 85 ++++++++++++++++++++++++------------------------ progress.js | 12 ++++--- 4 files changed, 59 insertions(+), 57 deletions(-) diff --git a/index.html b/index.html index 04acaee..1eaf9e3 100644 --- a/index.html +++ b/index.html @@ -5,23 +5,22 @@ - - - -

Notifications

- - + +
+

Drag and Drop Area

+
+ diff --git a/index.js b/index.js index 00bd55c..1082c57 100644 --- a/index.js +++ b/index.js @@ -17,8 +17,8 @@ function createWindow () { icon: path.join(__dirname, 'images', 'daplie-logo.png'), width: 800, height: 600, - minWidth: 195, - minHeight: 145, + minWidth: 280, + minHeight: 350, }); var tray = require('./tray'); @@ -28,8 +28,8 @@ function createWindow () { require('./progress').init(win); require('./drag-drop-main').init(win); - // Open the DevTools. - win.webContents.openDevTools(); + // // Open the DevTools. + // win.webContents.openDevTools(); win.webContents.on('will-navigate', function(e) { // Prevent drag-and-drop from navigating the Electron window, which can happen diff --git a/notifications.js b/notifications.js index 0346ecb..7b1b068 100644 --- a/notifications.js +++ b/notifications.js @@ -3,56 +3,55 @@ 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. -var timeoutId; -var stopped; -var count; +var count = 0; +var target = 0; +function notifyUser() { + ipc.send('notification', count, target); + count += 1; + var notif = new window.Notification('Annoying Alert ' + count, { + body: 'See what happens when you try to click on it.', + silent: true, + }); -function startNotifications() { - stopped = false; - count = 0; - if (timeoutId) { - clearTimeout(timeoutId); - } - - function notifyUser() { - timeoutId = null; - count += 1; - var notif = new window.Notification('Annoying Alert ' + count, { - body: 'See what happens when you try to click on it.', - silent: true, - }); - - // Notifications are unclickable on my system currently, not sure why. - notif.onclick = function () { - console.log('notification ' + count + ' clicked'); - notif.close(); - }; - notif.onclose = function () { - if (!stopped && count < 10) { - timeoutId = setTimeout(notifyUser, 5000); - } - }; - ipc.send('notification', count); - } - - timeoutId = setTimeout(notifyUser, 1000); + // On my system notifications are unclickable and seem to be unclosable as well, + // so not all of this code is fully tested. + notif.onclick = function () { + console.log('notification ' + count + ' clicked'); + notif.close(); + }; + notif.onclose = function () { + if (count < target) { + notifyUser(); + } + else { + count = 0; + target = 0; + ipc.send('notification', count, target); + } + }; } -function stopNotifications() { - stopped = true; - if (timeoutId) { - clearTimeout(timeoutId); - timeoutId = null; +function queueNotification() { + target += 1; + if (count === 0) { + notifyUser(); + } else { + ipc.send('notification', count-1, target); + } +} + +function clearQueue() { + target = count; + if (count > 0) { + ipc.send('notification', count-1, target); } - // Let the progress bar know that we are finished. - ipc.send('notification', 0); } document.body.addEventListener('click', function (ev) { - if (ev.target.classList.contains('start-notify')) { - startNotifications(); + if (ev.target.matches('.notify .queue')) { + queueNotification(); } - else if (ev.target.classList.contains('stop-notify')) { - stopNotifications(); + else if (ev.target.matches('.notify .clear')) { + clearQueue(); } }); diff --git a/progress.js b/progress.js index 7621412..8225fd0 100644 --- a/progress.js +++ b/progress.js @@ -11,8 +11,8 @@ function init(window) { } win = window; - ipc.on('notification', function (ev, count) { - updateProgress(count); + ipc.on('notification', function (ev, count, target) { + updateProgress(count, target); increaseBadge(); }); win.on('focus', clearBadge); @@ -27,8 +27,12 @@ function clearBadge() { app.setBadgeCount(0); } -function updateProgress(count) { - win.setProgressBar((count % 10)/10); +function updateProgress(count, target) { + if (count < 0 || count <= target) { + win.setProgressBar(0); + } else { + win.setProgressBar(count/target); + } } module.exports.init = init;