@@ -23,6 +23,7 @@ var sleepTimes = []; //array of times to rest determined by algorithm
23
23
var meridians = [ ] ; //array to hold the merdians to respective sleepTimes if militaryTime is false
24
24
var tempTime = [ ] ; //used for a temperary purpose not sure if reffered to outside of function
25
25
var latestRelease = null ;
26
+ var upTimeJob = null ;
26
27
27
28
function setTime ( ) { //called when set wakeup time button is pressed
28
29
settings . set ( 'Version' , 'v1.4.2' )
@@ -198,12 +199,13 @@ function nodeJobs() {
198
199
}
199
200
try {
200
201
jobs [ 6 ] . cancel ( ) ;
202
+ upTimeJob . cancel ( ) ;
201
203
} catch ( e ) {
202
204
203
205
}
204
206
jobs [ 6 ] = schedule . scheduleJob ( sleepTimes [ 6 ] , setTime ) ;
205
207
206
- var j = schedule . scheduleJob ( '* */3 * * *' , function ( ) {
208
+ upTimeJob = schedule . scheduleJob ( '0 0 * * * *' , function ( ) {
207
209
upTimeJobs ( ) ;
208
210
} ) ;
209
211
}
@@ -286,7 +288,7 @@ function showUpTimeNotification() {
286
288
287
289
upTimeNotification = true ;
288
290
try {
289
- audio . play ( ) //play notifiation sound
291
+ audio . play ( ) ; //play notifiation sound
290
292
} catch ( e ) {
291
293
292
294
}
@@ -313,15 +315,18 @@ function showUpTimeNotification() {
313
315
upTimeNotification = false ;
314
316
notification . close ( ) ; //close the notification
315
317
} else if ( "Restart" ) {
316
- restart ( ) ; //restart the computer
318
+ confirmRestartNotification ( ) ;
319
+ notification . close ( ) ;
320
+ upTimeNotification = false ;
321
+
317
322
}
318
323
319
324
} )
320
325
}
321
326
}
322
327
function confirmShutdownNotification ( ) {
323
328
try {
324
- audio . play ( ) //play notifiation sound
329
+ audio . play ( ) ; //play notifiation sound
325
330
} catch ( e ) {
326
331
327
332
}
@@ -351,10 +356,41 @@ function confirmShutdownNotification() {
351
356
} )
352
357
}
353
358
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
+ }
354
390
355
391
function showLatestUpdateNotification ( updateType ) {
356
392
try {
357
- audio . play ( ) //play notifiation sound
393
+ audio . play ( ) ; //play notifiation sound
358
394
} catch ( e ) {
359
395
360
396
}
0 commit comments