refactor: rm dead code, and fix some lints

This commit is contained in:
Rudxain 2025-03-06 02:40:06 -04:00
commit 6743b4d4af
No known key found for this signature in database
GPG key ID: 0DAC837DDEF8E96C
4 changed files with 4 additions and 42 deletions

View file

@ -41,7 +41,6 @@
use regex::Regex;
use serde::{Deserialize, Serialize};
use std::sync::LazyLock;
use std::{collections::HashSet, process::Command};
#[cfg(target_os = "windows")]
use std::os::windows::process::CommandExt;
@ -61,11 +60,11 @@ pub fn to_trimmed_utf8(v: Vec<u8>) -> String {
///
/// [More info here](https://developer.android.com/tools/adb)
#[derive(Debug)]
pub struct ACommand(Command);
pub struct ACommand(std::process::Command);
impl ACommand {
/// `adb` command builder
pub fn new() -> Self {
Self(Command::new("adb"))
Self(std::process::Command::new("adb"))
}
/// `shell` sub-command builder.
///
@ -107,11 +106,6 @@ impl ACommand {
})
.collect())
}
/// Reboots default device
pub fn reboot(mut self) -> Result<String, String> {
self.0.arg("reboot");
self.run()
}
/// General executor
fn run(self) -> Result<String, String> {
let mut cmd = self.0;
@ -230,8 +224,6 @@ const PACK_PREFIX: &str = "package:";
pub const PM_CLEAR_PACK: &str = "pm clear";
const INVALID_PKG_ID: &str = "One of these is wrong: `PackageId` regex, ADB implementation. Or the spec now allows a wider char-set";
/// Builder object for an Android Package Manager command.
///
/// [More info](https://developer.android.com/tools/adb#pm)
@ -244,8 +236,6 @@ impl PmCommand {
/// `Ok` variant:
/// - isn't sorted
/// - duplicates never _seem_ to happen, but don't assume uniqueness
///
/// See also [`list_packages_sys_parsed`]
pub fn list_packages_sys(
mut self,
f: Option<PmListPacksFlag>,
@ -267,31 +257,11 @@ impl PmCommand {
.lines()
.map(|p_ln| {
debug_assert!(p_ln.starts_with(PACK_PREFIX));
let p_id = &p_ln[PACK_PREFIX.len()..];
//#[cfg(debug_assertions)]
//PackageId::new(p_id).expect(INVALID_PKG_ID);
String::from(p_id)
String::from(&p_ln[PACK_PREFIX.len()..])
})
.collect()
})
}
/// `list packages -s` sub-command, pre-validated.
/// This is strongly-typed, at the cost of regex & hash overhead.
///
/// See also [`list_packages_sys`]
pub fn list_packages_sys_parsed(
self,
f: Option<PmListPacksFlag>,
user_id: Option<u16>,
) -> Result<HashSet<PackageId>, String> {
Ok(self
.list_packages_sys(f, user_id)?
.into_iter()
.map(|p| PackageId::new(p).expect(INVALID_PKG_ID))
.collect())
}
/// `list users` sub-command.
/// Output isn't parsed, because

View file

@ -1,17 +1,13 @@
use crate::CACHE_DIR;
use crate::core::config::{Config, DeviceSettings};
use crate::core::sync::{CorePackage, Phone, User, apply_pkg_state_commands};
use crate::core::utils::DisplayablePath;
use crate::gui::widgets::package_row::PackageRow;
use serde::{Deserialize, Serialize};
use std::sync::LazyLock;
use std::{
fs,
path::{Path, PathBuf},
};
pub static BACKUP_DIR: LazyLock<PathBuf> = LazyLock::new(|| CACHE_DIR.join("backups"));
#[derive(Default, Deserialize, Serialize, Debug, Clone, PartialEq, Eq)]
pub struct PhoneBackup {
pub device_id: String,
@ -138,7 +134,6 @@ pub fn restore_backup(
};
for (i, backup_package) in u.packages.iter().enumerate() {
let package: CorePackage = match packages[index]
.iter()
.find(|x| x.name == backup_package.name)

View file

@ -59,7 +59,6 @@ impl std::fmt::Display for User {
#[derive(Debug, Clone)]
pub enum CommandType {
PackageManager(PackageInfo),
Shell,
}
/// An enum to contain different variants for errors yielded by ADB.
@ -83,7 +82,6 @@ pub async fn adb_shell_command<S: AsRef<str>>(
let label = match &command_type {
CommandType::PackageManager(p) => &p.removal,
CommandType::Shell => "Shell",
};
let mut cmd = Command::new("adb");

View file

@ -148,7 +148,7 @@ impl List {
self.loading_state = LoadingState::RestoringDevice(
self.phone_packages[i_user][p.index].name.clone(),
);
}
};
} else {
self.loading_state = LoadingState::RestoringDevice("Error [TODO]".to_string());
}
@ -307,7 +307,6 @@ impl List {
Err(AdbError::Generic(err)) => {
self.error_modal = Some(err);
}
_ => {}
}
Command::none()
}