@@ -8,20 +8,39 @@ var DarkTheme = {
88 configEnabled : undefined ,
99} ;
1010
11- DarkTheme . isDarkThemeEnabled = function ( val ) {
12- return val === 0 || val === 2 && window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
11+ DarkTheme . isDarkThemeEnabled = function ( callback ) {
12+ if ( this . configEnabled === 0 ) {
13+ callback ( true ) ;
14+ } else if ( this . configEnabled === 2 ) {
15+ if ( GUI . isCordova ( ) ) {
16+ cordova . plugins . ThemeDetection . isDarkModeEnabled ( function ( success ) {
17+ callback ( success . value ) ;
18+ } , function ( error ) {
19+ console . log ( `cordova-plugin-theme-detection: ${ error } ` ) ;
20+ callback ( false ) ;
21+ } ) ;
22+ } else {
23+ const isEnabled = window . matchMedia && window . matchMedia ( '(prefers-color-scheme: dark)' ) . matches ;
24+ callback ( isEnabled ) ;
25+ }
26+ } else {
27+ callback ( false ) ;
28+ }
1329} ;
1430
1531DarkTheme . apply = function ( ) {
16- if ( this . isDarkThemeEnabled ( this . configEnabled ) ) {
17- this . applyDark ( ) ;
18- } else {
19- this . applyNormal ( ) ;
20- }
32+ const self = this ;
33+ this . isDarkThemeEnabled ( function ( isEnabled ) {
34+ if ( isEnabled ) {
35+ self . applyDark ( ) ;
36+ } else {
37+ self . applyNormal ( ) ;
38+ }
2139
22- if ( chrome . app . window !== undefined ) {
23- windowWatcherUtil . passValue ( chrome . app . window . get ( "receiver_msp" ) , 'darkTheme' , this . isDarkThemeEnabled ( this . configEnabled ) ) ;
24- }
40+ if ( chrome . app . window !== undefined ) {
41+ windowWatcherUtil . passValue ( chrome . app . window . get ( "receiver_msp" ) , 'darkTheme' , isEnabled ) ;
42+ }
43+ } ) ;
2544} ;
2645
2746DarkTheme . autoSet = function ( ) {
@@ -31,7 +50,7 @@ DarkTheme.autoSet = function() {
3150} ;
3251
3352DarkTheme . setConfig = function ( result ) {
34- if ( this . configEnabled != result ) {
53+ if ( this . configEnabled !== result ) {
3554 this . configEnabled = result ;
3655 this . apply ( ) ;
3756 }
0 commit comments