update how/why the notifications fire
This commit is contained in:
parent
1e77671156
commit
8f2912225b
11
index.html
11
index.html
|
@ -5,23 +5,22 @@
|
|||
<meta charset="UTF-8">
|
||||
</head>
|
||||
<body>
|
||||
<script>require('./crash-reporter')</script>
|
||||
<script>require('./notifications')</script>
|
||||
<script>require('./drag-drop-render')</script>
|
||||
|
||||
<div class="notify">
|
||||
<h3>Notifications</h3>
|
||||
<button class="start-notify">Start</button>
|
||||
<button class="stop-notify">Stop</button>
|
||||
<button class="queue">Queue</button>
|
||||
<button class="clear">Clear Queue</button>
|
||||
</div>
|
||||
<script>require("./notifications")</script>
|
||||
|
||||
<div class="drag-n-drop">
|
||||
<h3>Drag and Drop Area</h3>
|
||||
<div class="file-container"></div>
|
||||
</div>
|
||||
<script>require("./drag-drop-render")</script>
|
||||
|
||||
<div>
|
||||
<button class="crasher">Crash Program</button>
|
||||
</div>
|
||||
<script>require("./crash-reporter")</script>
|
||||
</body>
|
||||
</html>
|
||||
|
|
8
index.js
8
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
|
||||
|
|
|
@ -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;
|
||||
|
||||
function startNotifications() {
|
||||
stopped = false;
|
||||
count = 0;
|
||||
if (timeoutId) {
|
||||
clearTimeout(timeoutId);
|
||||
}
|
||||
|
||||
function notifyUser() {
|
||||
timeoutId = null;
|
||||
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,
|
||||
});
|
||||
|
||||
// Notifications are unclickable on my system currently, not sure why.
|
||||
// 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 (!stopped && count < 10) {
|
||||
timeoutId = setTimeout(notifyUser, 5000);
|
||||
if (count < target) {
|
||||
notifyUser();
|
||||
}
|
||||
else {
|
||||
count = 0;
|
||||
target = 0;
|
||||
ipc.send('notification', count, target);
|
||||
}
|
||||
};
|
||||
ipc.send('notification', count);
|
||||
}
|
||||
|
||||
timeoutId = setTimeout(notifyUser, 1000);
|
||||
}
|
||||
|
||||
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();
|
||||
}
|
||||
});
|
||||
|
|
12
progress.js
12
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;
|
||||
|
|
Loading…
Reference in New Issue