@@ -70,6 +70,23 @@ const toggleApp = (): void => {
70
70
}
71
71
} ;
72
72
73
+ function checkDndExpirationOnStartup ( page : WebContents ) : void {
74
+ const expiration = ConfigUtil . getConfigItem ( "dndExpiration" , null ) ;
75
+
76
+ if ( expiration && Date . now ( ) > expiration ) {
77
+ const revert = DNDUtil . toggle ( ) ;
78
+ send ( page , "toggle-dnd" , revert . dnd , revert . newSettings ) ;
79
+ ConfigUtil . removeConfigItem ( "dndExpiration" ) ;
80
+ } else if ( expiration ) {
81
+ const timeLeft = expiration - Date . now ( ) ;
82
+ dndRevertTimeout = setTimeout ( ( ) => {
83
+ const revert = DNDUtil . toggle ( ) ;
84
+ send ( page , "toggle-dnd" , revert . dnd , revert . newSettings ) ;
85
+ ConfigUtil . removeConfigItem ( "dndExpiration" ) ;
86
+ } , timeLeft ) ;
87
+ }
88
+ }
89
+
73
90
function createMainWindow ( ) : BrowserWindow {
74
91
// Load the previous state with fallback to defaults
75
92
mainWindowState = windowStateKeeper ( {
@@ -272,7 +289,7 @@ function createMainWindow(): BrowserWindow {
272
289
}
273
290
274
291
const page = mainWindow . webContents ;
275
-
292
+ checkDndExpirationOnStartup ( page ) ;
276
293
page . on ( "dom-ready" , ( ) => {
277
294
if ( ConfigUtil . getConfigItem ( "startMinimized" , false ) ) {
278
295
mainWindow . hide ( ) ;
@@ -417,16 +434,21 @@ function createMainWindow(): BrowserWindow {
417
434
if ( result . dnd && duration && ! Number . isNaN ( duration ) ) {
418
435
if ( dndRevertTimeout ) clearTimeout ( dndRevertTimeout ) ;
419
436
437
+ const expirationTime = Date . now ( ) + duration * 60 * 1000 ;
438
+ ConfigUtil . setConfigItem ( "dndExpiration" , expirationTime ) ;
439
+
420
440
dndRevertTimeout = setTimeout (
421
441
( ) => {
422
442
const revert = DNDUtil . toggle ( ) ;
423
443
send ( _event . sender , "toggle-dnd" , revert . dnd , revert . newSettings ) ;
444
+ ConfigUtil . removeConfigItem ( "dndExpiration" ) ;
424
445
} ,
425
446
duration * 60 * 1000 ,
426
447
) ;
427
448
} else if ( dndRevertTimeout ) {
428
449
clearTimeout ( dndRevertTimeout ) ;
429
450
dndRevertTimeout = null ;
451
+ ConfigUtil . removeConfigItem ( "dndExpiration" ) ;
430
452
}
431
453
432
454
return ;
0 commit comments