diff --git a/src/core/sync.rs b/src/core/sync.rs index 127b1c9..220db7c 100644 --- a/src/core/sync.rs +++ b/src/core/sync.rs @@ -13,6 +13,8 @@ use std::process::Command; #[cfg(target_os = "windows")] use std::os::windows::process::CommandExt; +use super::utils::set_adb_serial; + const PM_LS_PKG: &str = "pm list packages"; const PM_C: &str = "pm clear"; @@ -327,7 +329,10 @@ pub async fn get_devices_list() -> Vec { return OperationResult::Retry(vec![]); } for device in RE.captures_iter(&devices) { - env::set_var(ANDROID_SERIAL, &device[1]); + #[allow(unsafe_code)] + unsafe { + set_adb_serial(&device[1]) + }; device_list.push(Phone { model: get_phone_brand(), android_sdk: get_android_sdk(), diff --git a/src/core/utils.rs b/src/core/utils.rs index dc5ac82..85268f6 100644 --- a/src/core/utils.rs +++ b/src/core/utils.rs @@ -5,10 +5,13 @@ use crate::gui::widgets::package_row::PackageRow; use chrono::offset::Utc; use chrono::{DateTime, Local}; use csv::Writer; +use std::ffi::OsStr; use std::path::PathBuf; use std::process::Command; use std::{fmt, fs}; +use super::sync::Phone; + /// Canonical shortened name of the application pub const NAME: &str = "UAD-ng"; /// Global environment variable to keep @@ -24,6 +27,15 @@ pub enum Error { DialogClosed, } +#[allow(unsafe_code)] +#[allow( + clippy::semicolon_if_nothing_returned, + reason = "fn must return whatever `set_var` returns" +)] +pub unsafe fn set_adb_serial>(device: D) { + std::env::set_var(ANDROID_SERIAL, device) +} + pub fn fetch_packages(uad_lists: &PackageHashMap, user_id: Option<&User>) -> Vec { let all_system_packages = list_all_system_packages(user_id); // installed and uninstalled packages let enabled_system_packages = hashset_system_packages(PackageState::Enabled, user_id); diff --git a/src/gui/mod.rs b/src/gui/mod.rs index e7ba1af..7d57111 100644 --- a/src/gui/mod.rs +++ b/src/gui/mod.rs @@ -6,7 +6,7 @@ use crate::core::sync::{get_devices_list, initial_load, perform_adb_commands, Co use crate::core::theme::Theme; use crate::core::uad_lists::UadListState; use crate::core::update::{get_latest_release, Release, SelfUpdateState, SelfUpdateStatus}; -use crate::core::utils::{string_to_theme, ANDROID_SERIAL, NAME}; +use crate::core::utils::{set_adb_serial, string_to_theme, ANDROID_SERIAL, NAME}; use iced::advanced::graphics::image::image_rs::ImageFormat; use iced::font; @@ -255,7 +255,10 @@ impl Application for UadGui { Message::DeviceSelected(s_device) => { self.selected_device = Some(s_device.clone()); self.view = View::List; - env::set_var(ANDROID_SERIAL, s_device.adb_id); + #[allow(unsafe_code)] + unsafe { + set_adb_serial(s_device.adb_id) + }; info!("{:-^65}", "-"); info!( "ANDROID_SDK: {} | DEVICE: {}", diff --git a/src/gui/views/list.rs b/src/gui/views/list.rs index 7729709..0eada22 100644 --- a/src/gui/views/list.rs +++ b/src/gui/views/list.rs @@ -8,11 +8,10 @@ use crate::core::uad_lists::{ load_debloat_lists, Opposite, PackageHashMap, PackageState, Removal, UadList, UadListState, }; use crate::core::utils::{ - export_selection, fetch_packages, open_url, ANDROID_SERIAL, EXPORT_FILE_NAME, NAME, + export_selection, fetch_packages, open_url, set_adb_serial, EXPORT_FILE_NAME, NAME, }; use crate::gui::style; use crate::gui::widgets::navigation_menu::ICONS; -use std::env; use std::path::PathBuf; use crate::gui::views::settings::Settings; @@ -864,12 +863,15 @@ impl List { } #[expect(clippy::unused_async, reason = "1 call-site")] - async fn init_apps_view(remote: bool, phone: Phone) -> (PackageHashMap, UadListState) { + async fn init_apps_view(remote: bool, device: Phone) -> (PackageHashMap, UadListState) { let uad_lists = load_debloat_lists(remote); match uad_lists { Ok(list) => { - env::set_var(ANDROID_SERIAL, phone.adb_id.clone()); - if phone.adb_id.is_empty() { + #[allow(unsafe_code)] + unsafe { + set_adb_serial(device.adb_id.clone()) + }; + if device.adb_id.is_empty() { error!("AppsView ready but no phone found"); } (list, UadListState::Done)