update how/why the notifications fire

This commit is contained in:
tigerbot 2017-04-24 15:11:42 -06:00
parent 1e77671156
commit 8f2912225b
4 changed files with 59 additions and 57 deletions

View File

@ -5,23 +5,22 @@
<meta charset="UTF-8"> <meta charset="UTF-8">
</head> </head>
<body> <body>
<script>require('./crash-reporter')</script>
<script>require('./notifications')</script>
<script>require('./drag-drop-render')</script>
<div class="notify"> <div class="notify">
<h3>Notifications</h3> <h3>Notifications</h3>
<button class="start-notify">Start</button> <button class="queue">Queue</button>
<button class="stop-notify">Stop</button> <button class="clear">Clear Queue</button>
</div> </div>
<script>require("./notifications")</script>
<div class="drag-n-drop"> <div class="drag-n-drop">
<h3>Drag and Drop Area</h3> <h3>Drag and Drop Area</h3>
<div class="file-container"></div> <div class="file-container"></div>
</div> </div>
<script>require("./drag-drop-render")</script>
<div> <div>
<button class="crasher">Crash Program</button> <button class="crasher">Crash Program</button>
</div> </div>
<script>require("./crash-reporter")</script>
</body> </body>
</html> </html>

View File

@ -17,8 +17,8 @@ function createWindow () {
icon: path.join(__dirname, 'images', 'daplie-logo.png'), icon: path.join(__dirname, 'images', 'daplie-logo.png'),
width: 800, width: 800,
height: 600, height: 600,
minWidth: 195, minWidth: 280,
minHeight: 145, minHeight: 350,
}); });
var tray = require('./tray'); var tray = require('./tray');
@ -28,8 +28,8 @@ function createWindow () {
require('./progress').init(win); require('./progress').init(win);
require('./drag-drop-main').init(win); require('./drag-drop-main').init(win);
// Open the DevTools. // // Open the DevTools.
win.webContents.openDevTools(); // win.webContents.openDevTools();
win.webContents.on('will-navigate', function(e) { win.webContents.on('will-navigate', function(e) {
// Prevent drag-and-drop from navigating the Electron window, which can happen // Prevent drag-and-drop from navigating the Electron window, which can happen

View File

@ -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 // This file runs in a render thread of the Electron app. It must be required (directly or
// indirectly) from one of the html files. // indirectly) from one of the html files.
var timeoutId; var count = 0;
var stopped; var target = 0;
var count; 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() { // On my system notifications are unclickable and seem to be unclosable as well,
stopped = false; // so not all of this code is fully tested.
count = 0; notif.onclick = function () {
if (timeoutId) { console.log('notification ' + count + ' clicked');
clearTimeout(timeoutId); notif.close();
} };
notif.onclose = function () {
function notifyUser() { if (count < target) {
timeoutId = null; notifyUser();
count += 1; }
var notif = new window.Notification('Annoying Alert ' + count, { else {
body: 'See what happens when you try to click on it.', count = 0;
silent: true, target = 0;
}); ipc.send('notification', count, target);
}
// 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);
} }
function stopNotifications() { function queueNotification() {
stopped = true; target += 1;
if (timeoutId) { if (count === 0) {
clearTimeout(timeoutId); notifyUser();
timeoutId = null; } 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) { document.body.addEventListener('click', function (ev) {
if (ev.target.classList.contains('start-notify')) { if (ev.target.matches('.notify .queue')) {
startNotifications(); queueNotification();
} }
else if (ev.target.classList.contains('stop-notify')) { else if (ev.target.matches('.notify .clear')) {
stopNotifications(); clearQueue();
} }
}); });

View File

@ -11,8 +11,8 @@ function init(window) {
} }
win = window; win = window;
ipc.on('notification', function (ev, count) { ipc.on('notification', function (ev, count, target) {
updateProgress(count); updateProgress(count, target);
increaseBadge(); increaseBadge();
}); });
win.on('focus', clearBadge); win.on('focus', clearBadge);
@ -27,8 +27,12 @@ function clearBadge() {
app.setBadgeCount(0); app.setBadgeCount(0);
} }
function updateProgress(count) { function updateProgress(count, target) {
win.setProgressBar((count % 10)/10); if (count < 0 || count <= target) {
win.setProgressBar(0);
} else {
win.setProgressBar(count/target);
}
} }
module.exports.init = init; module.exports.init = init;