@@ -19,37 +19,55 @@ class ImmichFrame {
1919
2020 inSleepMode : boolean = false ;
2121
22+ private timeoutId : number | null = null ;
23+
2224 public static getInstance ( ) : ImmichFrame {
2325 if ( ! ImmichFrame . instance ) {
2426 ImmichFrame . instance = new ImmichFrame ( ) ;
2527 }
2628 return ImmichFrame . instance ;
2729 }
2830
29- public dimScreen ( ) : void {
30- fetch ( `${ this . BASE_URL } /${ this . endpoints . DIM } ` ) . catch ( ( error ) =>
31- console . error ( "Error dimming ImmichFrame screen:" , error ) ,
32- ) ;
31+ public async dimScreen ( ) : Promise < void > {
32+ try {
33+ await fetch ( `${ this . BASE_URL } /${ this . endpoints . DIM } ` , {
34+ signal : AbortSignal . timeout ( 5000 ) ,
35+ } ) ;
36+ } catch ( error ) {
37+ console . debug ( "Error dimming ImmichFrame screen:" , error ) ;
38+ }
3339 }
3440
35- public undimScreen ( ) : void {
36- fetch ( `${ this . BASE_URL } /${ this . endpoints . UNDIM } ` ) . catch ( ( error ) =>
37- console . error ( "Error undimming ImmichFrame screen:" , error ) ,
38- ) ;
41+ public async undimScreen ( ) : Promise < void > {
42+ try {
43+ await fetch ( `${ this . BASE_URL } /${ this . endpoints . UNDIM } ` , {
44+ signal : AbortSignal . timeout ( 5000 ) ,
45+ } ) ;
46+ } catch ( error ) {
47+ console . debug ( "Error undimming ImmichFrame screen:" , error ) ;
48+ }
3949 }
4050
41- public setScreensaverState ( enable : boolean ) : void {
51+ public async setScreensaverState ( enable : boolean ) : Promise < void > {
4252 try {
53+ if ( this . timeoutId ) {
54+ clearTimeout ( this . timeoutId ) ;
55+ this . timeoutId = null ;
56+ }
57+
4358 if ( enable ) {
4459 if ( this . inSleepMode ) return ;
4560
4661 this . inSleepMode = true ;
4762
48- setTimeout ( ( ) => this . dimScreen ( ) , this . SCREENSAVER_DELAY_MS ) ;
63+ this . timeoutId = setTimeout ( async ( ) => {
64+ await this . dimScreen ( ) ;
65+ this . timeoutId = null ;
66+ } , this . SCREENSAVER_DELAY_MS ) ;
4967 } else {
5068 if ( ! this . inSleepMode ) return ;
5169
52- this . undimScreen ( ) ;
70+ await this . undimScreen ( ) ;
5371
5472 this . inSleepMode = false ;
5573
0 commit comments