From 58c125311d5e9e65c38335499adcdf7668f99086 Mon Sep 17 00:00:00 2001 From: pyxis Date: Fri, 9 Feb 2024 13:27:59 +0900 Subject: [PATCH] fix #1 : adb devices not parsed on adb 34.0.5 --- src/device.rs | 17 ++++++++++++----- 1 file changed, 12 insertions(+), 5 deletions(-) diff --git a/src/device.rs b/src/device.rs index 2fd2dbf..fef886c 100644 --- a/src/device.rs +++ b/src/device.rs @@ -9,7 +9,10 @@ use wait_timeout::ChildExt; use crate::cli; lazy_static! { + // adb version 33.0.3-8952118 static ref ADB_DEVICES_PATTERN: Regex = Regex::new(r"(\S+)\s+(device|offline|recovery|fastbootd|sideload|unauthorized|disconnected|bootloader)?\s*usb:(\S+)\s(?:product:(\S+)\s+)?(?:model:(\S+)\s+)?(?:device:(\S+)\s+)?transport_id:(\S+)").unwrap(); + // adb_version 34.0.5-10900879 + static ref ADB_DEVICES_PATTERN_34: Regex = Regex::new(r"(\S+)\s+(device|offline|recovery|fastbootd|sideload|unauthorized|disconnected|bootloader)?\s*(\S+)\s(?:product:(\S+)\s+)?(?:model:(\S+)\s+)?(?:device:(\S+)\s+)?transport_id:(\S+)").unwrap(); } #[derive(Clone)] @@ -49,11 +52,15 @@ pub fn get_device_list() -> Vec { let lines: Vec = output_str.lines().map(|l| l.to_string()).collect(); let device_infos: Vec = lines .iter() - .filter_map(|line| ADB_DEVICES_PATTERN.captures(line)) - .map(|captures| DeviceInfo { - serial: captures.get(1).map_or("", |m| m.as_str()).to_string(), - state: captures.get(2).map_or("", |m| m.as_str()).to_string(), - model: captures.get(5).map_or("", |m| m.as_str()).to_string(), + .filter_map(|line| { + ADB_DEVICES_PATTERN + .captures(line) + .or_else(|| ADB_DEVICES_PATTERN_34.captures(line)) + .map(|captures| DeviceInfo { + serial: captures.get(1).map_or("", |m| m.as_str()).to_string(), + state: captures.get(2).map_or("", |m| m.as_str()).to_string(), + model: captures.get(5).map_or("", |m| m.as_str()).to_string(), + }) }) .map(|info| check_command_available(&info)) .collect();