@@ -12,6 +12,7 @@ import {
1212 parsePermissionTarget ,
1313 type PermissionSettingOptions ,
1414} from '../permission-utils.ts' ;
15+ import { parseAppearanceAction } from '../appearance.ts' ;
1516
1617const ALIASES : Record < string , { type : 'intent' | 'package' ; value : string } > = {
1718 settings : { type : 'intent' , value : 'android.settings.SETTINGS' } ,
@@ -733,16 +734,6 @@ function parseSettingState(state: string): boolean {
733734 throw new AppError ( 'INVALID_ARGS' , `Invalid setting state: ${ state } ` ) ;
734735}
735736
736- type AppearanceAction = 'light' | 'dark' | 'toggle' ;
737-
738- function parseAppearanceAction ( state : string ) : AppearanceAction {
739- const normalized = state . trim ( ) . toLowerCase ( ) ;
740- if ( normalized === 'light' ) return 'light' ;
741- if ( normalized === 'dark' ) return 'dark' ;
742- if ( normalized === 'toggle' ) return 'toggle' ;
743- throw new AppError ( 'INVALID_ARGS' , `Invalid appearance state: ${ state } . Use light|dark|toggle.` ) ;
744- }
745-
746737async function resolveAndroidAppearanceTarget (
747738 device : DeviceInfo ,
748739 state : string ,
@@ -767,17 +758,17 @@ async function resolveAndroidAppearanceTarget(
767758 stderr : currentResult . stderr ,
768759 } ) ;
769760 }
761+ if ( current === 'auto' ) return 'dark' ;
770762 return current === 'dark' ? 'light' : 'dark' ;
771763}
772764
773- function parseAndroidAppearance ( stdout : string , stderr : string ) : 'light' | 'dark' | null {
774- const output = `${ stdout } \n${ stderr } ` . toLowerCase ( ) ;
775- if ( output . includes ( 'night mode: yes' ) ) return 'dark' ;
776- if ( output . includes ( 'night mode: no' ) ) return 'light' ;
777- if ( / \b d a r k \b / . test ( output ) ) return 'dark' ;
778- if ( / \b l i g h t \b / . test ( output ) ) return 'light' ;
779- if ( / \b y e s \b / . test ( output ) ) return 'dark' ;
780- if ( / \b n o \b / . test ( output ) ) return 'light' ;
765+ function parseAndroidAppearance ( stdout : string , stderr : string ) : 'light' | 'dark' | 'auto' | null {
766+ const match = / n i g h t m o d e : \s * ( y e s | n o | a u t o ) \b / i. exec ( `${ stdout } \n${ stderr } ` ) ;
767+ if ( ! match ) return null ;
768+ const value = match [ 1 ] . toLowerCase ( ) ;
769+ if ( value === 'yes' ) return 'dark' ;
770+ if ( value === 'no' ) return 'light' ;
771+ if ( value === 'auto' ) return 'auto' ;
781772 return null ;
782773}
783774
0 commit comments