Skip to content

Commit bf47952

Browse files
author
Alex Epstein
committed
Fix uptime jobs bug
Former-commit-id: d17529f [formerly b88683e] Former-commit-id: 813567d
1 parent eb6571b commit bf47952

File tree

1 file changed

+41
-5
lines changed

1 file changed

+41
-5
lines changed

js/script.js

+41-5
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ var sleepTimes = []; //array of times to rest determined by algorithm
2323
var meridians = []; //array to hold the merdians to respective sleepTimes if militaryTime is false
2424
var tempTime = []; //used for a temperary purpose not sure if reffered to outside of function
2525
var latestRelease = null;
26+
var upTimeJob = null;
2627

2728
function setTime() { //called when set wakeup time button is pressed
2829
settings.set('Version','v1.4.2')
@@ -198,12 +199,13 @@ function nodeJobs() {
198199
}
199200
try {
200201
jobs[6].cancel();
202+
upTimeJob.cancel();
201203
} catch (e) {
202204

203205
}
204206
jobs[6] = schedule.scheduleJob(sleepTimes[6], setTime);
205207

206-
var j = schedule.scheduleJob('* */3 * * *', function(){
208+
upTimeJob = schedule.scheduleJob('0 0 * * * *', function(){
207209
upTimeJobs();
208210
});
209211
}
@@ -286,7 +288,7 @@ function showUpTimeNotification() {
286288

287289
upTimeNotification = true;
288290
try {
289-
audio.play() //play notifiation sound
291+
audio.play(); //play notifiation sound
290292
} catch (e) {
291293

292294
}
@@ -313,15 +315,18 @@ function showUpTimeNotification() {
313315
upTimeNotification = false;
314316
notification.close(); //close the notification
315317
} else if ("Restart") {
316-
restart(); //restart the computer
318+
confirmRestartNotification();
319+
notification.close();
320+
upTimeNotification = false;
321+
317322
}
318323

319324
})
320325
}
321326
}
322327
function confirmShutdownNotification() {
323328
try {
324-
audio.play() //play notifiation sound
329+
audio.play(); //play notifiation sound
325330
} catch (e) {
326331

327332
}
@@ -351,10 +356,41 @@ function confirmShutdownNotification() {
351356
})
352357
}
353358

359+
function confirmRestartNotification() {
360+
try {
361+
audio.play(); //play notifiation sound
362+
} catch (e) {
363+
364+
}
365+
const notification = notifier.notify('Insomnia', { //Notification
366+
message: 'Confirm Restart',
367+
icon: iconPath,
368+
buttons: ['Cancel', 'Confirm'],
369+
vetical: true,
370+
duration: 20000,
371+
})
372+
373+
notification.on('clicked', () => { //how to behave when notification is clicked
374+
notification.close();
375+
})
376+
377+
notification.on('swipedRight', () => { //how to behave when notification is swipedRight
378+
notification.close();
379+
})
380+
381+
notification.on('buttonClicked', (text, buttonIndex, options) => { //how to behave if one of the buttons was pressed
382+
if (text === 'Cancel') {
383+
notification.close(); //close the notification
384+
} else if ("Confirm") {
385+
restart(); //shutdown the computer
386+
}
387+
388+
})
389+
}
354390

355391
function showLatestUpdateNotification(updateType) {
356392
try {
357-
audio.play() //play notifiation sound
393+
audio.play(); //play notifiation sound
358394
} catch (e) {
359395

360396
}

0 commit comments

Comments
 (0)