Skip to content

Commit

Permalink
fix #1 : adb devices not parsed on adb 34.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
pyxis committed Feb 9, 2024
1 parent 385544e commit 58c1253
Showing 1 changed file with 12 additions and 5 deletions.
17 changes: 12 additions & 5 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down Expand Up @@ -49,11 +52,15 @@ pub fn get_device_list() -> Vec<DeviceInfo> {
let lines: Vec<String> = output_str.lines().map(|l| l.to_string()).collect();
let device_infos: Vec<DeviceInfo> = 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();
Expand Down

0 comments on commit 58c1253

Please sign in to comment.