11import _ from 'lodash' ;
22
33const WINDOW_TITLE_PATTERN = / ^ \s + W i n d o w \s # \d + \s W i n d o w \{ [ 0 - 9 a - f ] + \s \w + \s ( [ \w - ] + ) \} : $ / ;
4- const FRAME_PATTERN = / ^ \s + m F r a m e = \[ ( [ 0 - 9 . - ] + ) , ( [ 0 - 9 . - ] + ) \] \[ ( [ 0 - 9 . - ] + ) , ( [ 0 - 9 . - ] + ) \] / m;
5- const SURFACE_PATTERN = / ^ \s + S u r f a c e : \s s h o w n = ( t r u e | f a l s e ) / m;
4+ const FRAME_PATTERN = / \b m ? [ F f ] r a m e = \[ ( [ 0 - 9 . - ] + ) , ( [ 0 - 9 . - ] + ) \] \[ ( [ 0 - 9 . - ] + ) , ( [ 0 - 9 . - ] + ) \] / ;
5+ const VIEW_VISIBILITY_PATTERN = / \b m V i e w V i s i b i l i t y = ( 0 x [ 0 - 9 a - f A - F ] + ) / ;
6+ // https://developer.android.com/reference/android/view/View#VISIBLE
7+ const VIEW_VISIBLE = 0x0 ;
68const STATUS_BAR_WINDOW_NAME_PREFIX = 'StatusBar' ;
79const NAVIGATION_BAR_WINDOW_NAME_PREFIX = 'NavigationBar' ;
810const DEFAULT_WINDOW_PROPERTIES = {
@@ -43,12 +45,12 @@ function parseWindowProperties (name, props, log = null) {
4345 result . y = parseFloat ( frameMatch [ 2 ] ) ;
4446 result . width = parseFloat ( frameMatch [ 3 ] ) - result . x ;
4547 result . height = parseFloat ( frameMatch [ 4 ] ) - result . y ;
46- const visibilityMatch = SURFACE_PATTERN . exec ( propLines ) ;
48+ const visibilityMatch = VIEW_VISIBILITY_PATTERN . exec ( propLines ) ;
4749 if ( ! visibilityMatch ) {
4850 log ?. debug ( propLines ) ;
4951 throw new Error ( `Cannot parse the visibility value from '${ name } ' window properties` ) ;
5052 }
51- result . visible = visibilityMatch [ 1 ] === 'true' ;
53+ result . visible = parseInt ( visibilityMatch [ 1 ] , 16 ) === VIEW_VISIBLE ;
5254 return result ;
5355}
5456
@@ -65,29 +67,21 @@ function parseWindowProperties (name, props, log = null) {
6567function parseWindows ( lines , log = null ) {
6668 const windows = { } ;
6769 let currentWindowName = null ;
68- let windowNameRowIndent = null ;
6970 for ( const line of lines . split ( '\n' ) . map ( _ . trimEnd ) ) {
70- const currentIndent = line . length - _ . trimStart ( line ) . length ;
71- if ( _ . isNil ( windowNameRowIndent ) || currentIndent <= windowNameRowIndent ) {
72- const match = WINDOW_TITLE_PATTERN . exec ( line ) ;
73- if ( ! match ) {
74- currentWindowName = null ;
75- continue ;
76- }
71+ const match = WINDOW_TITLE_PATTERN . exec ( line ) ;
72+ if ( match ) {
7773 currentWindowName = match [ 1 ] ;
78- if ( _ . isNil ( windowNameRowIndent ) ) {
79- windowNameRowIndent = currentIndent ;
80- }
74+ windows [ currentWindowName ] = [ ] ;
8175 continue ;
8276 }
83- if ( ! currentWindowName || currentIndent <= windowNameRowIndent ) {
77+ if ( _ . trim ( line ) . length === 0 ) {
78+ currentWindowName = null ;
8479 continue ;
8580 }
8681
87- if ( ! _ . isArray ( windows [ currentWindowName ] ) ) {
88- windows [ currentWindowName ] = [ ] ;
82+ if ( currentWindowName && _ . isArray ( windows [ currentWindowName ] ) ) {
83+ windows [ currentWindowName ] . push ( line ) ;
8984 }
90- windows [ currentWindowName ] . push ( line ) ;
9185 }
9286 if ( _ . isEmpty ( windows ) ) {
9387 log ?. debug ( lines . join ( '\n' ) ) ;
0 commit comments