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">
|
<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>
|
||||||
|
|
8
index.js
8
index.js
|
@ -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
|
||||||
|
|
|
@ -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);
|
||||||
function startNotifications() {
|
|
||||||
stopped = false;
|
|
||||||
count = 0;
|
|
||||||
if (timeoutId) {
|
|
||||||
clearTimeout(timeoutId);
|
|
||||||
}
|
|
||||||
|
|
||||||
function notifyUser() {
|
|
||||||
timeoutId = null;
|
|
||||||
count += 1;
|
count += 1;
|
||||||
var notif = new window.Notification('Annoying Alert ' + count, {
|
var notif = new window.Notification('Annoying Alert ' + count, {
|
||||||
body: 'See what happens when you try to click on it.',
|
body: 'See what happens when you try to click on it.',
|
||||||
silent: true,
|
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 () {
|
notif.onclick = function () {
|
||||||
console.log('notification ' + count + ' clicked');
|
console.log('notification ' + count + ' clicked');
|
||||||
notif.close();
|
notif.close();
|
||||||
};
|
};
|
||||||
notif.onclose = function () {
|
notif.onclose = function () {
|
||||||
if (!stopped && count < 10) {
|
if (count < target) {
|
||||||
timeoutId = setTimeout(notifyUser, 5000);
|
notifyUser();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
count = 0;
|
||||||
|
target = 0;
|
||||||
|
ipc.send('notification', count, target);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
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();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
12
progress.js
12
progress.js
|
@ -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;
|
||||||
|
|
Loading…
Reference in New Issue