@@ -41,22 +41,19 @@ impl WindowsInfo {
4141 }
4242
4343 fn parse_top_app ( dump : & str ) -> Vec < i32 > {
44- let focused_app_line = match dump
44+ let Some ( focused_app_line) = dump
4545 . lines ( )
4646 . find ( |line| line. trim ( ) . starts_with ( "mFocusedApp=" ) )
47- {
48- Some ( line) => line,
49- None => return Vec :: new ( ) ,
47+ else {
48+ return Vec :: new ( ) ;
5049 } ;
51-
52- let package_name = match Self :: extract_package_name ( focused_app_line) {
53- Some ( name) => name,
54- None => return Vec :: new ( ) ,
50+ let Some ( package_name) = Self :: extract_package_name ( focused_app_line) else {
51+ return Vec :: new ( ) ;
5552 } ;
5653
5754 // Try modern parser, if it fails, fall back to legacy parser.
58- let pid = Self :: parse_a16_format ( dump, & package_name)
59- . or_else ( || Self :: parse_a15_format ( dump, & package_name) ) ;
55+ let pid = Self :: parse_a16_format ( dump, package_name)
56+ . or_else ( || Self :: parse_a15_format ( dump, package_name) ) ;
6057
6158 pid. map_or_else ( Vec :: new, |p| vec ! [ p] )
6259 }
@@ -73,11 +70,7 @@ impl WindowsInfo {
7370 fn parse_a16_format ( dump : & str , package_name : & str ) -> Option < i32 > {
7471 let mut in_target_window_section = false ;
7572 for line in dump. lines ( ) {
76- if !in_target_window_section {
77- if line. contains ( "Window #" ) && line. contains ( package_name) {
78- in_target_window_section = true ;
79- }
80- } else {
73+ if in_target_window_section {
8174 if line. contains ( "mSession=" ) {
8275 let session_part = line. split ( "mSession=" ) . nth ( 1 ) ?;
8376 let content_start = session_part. find ( '{' ) ? + 1 ;
@@ -91,6 +84,8 @@ impl WindowsInfo {
9184 if line. contains ( "Window #" ) {
9285 return None ;
9386 }
87+ } else if line. contains ( "Window #" ) && line. contains ( package_name) {
88+ in_target_window_section = true ;
9489 }
9590 }
9691 None
@@ -111,12 +106,11 @@ impl WindowsInfo {
111106 }
112107
113108 let trimmed_line = line. trim ( ) ;
114- if trimmed_line. starts_with ( "mPackageName=" ) {
115- if let Some ( pkg) = trimmed_line. split ( '=' ) . nth ( 1 ) {
116- if pkg == package_name {
117- return last_pid_found;
118- }
119- }
109+ if trimmed_line. starts_with ( "mPackageName=" )
110+ && let Some ( pkg) = trimmed_line. split ( '=' ) . nth ( 1 )
111+ && pkg == package_name
112+ {
113+ return last_pid_found;
120114 }
121115 }
122116 None
0 commit comments