From 1bef9e208687091698e6dc20fb8feedf8f6f7e27 Mon Sep 17 00:00:00 2001 From: Vladislav Nepogodin Date: Wed, 6 Jul 2022 22:30:28 +0400 Subject: [PATCH] =?UTF-8?q?=F0=9F=91=B7=20use=20best=20available=20pacman?= =?UTF-8?q?=20wrapper(also=20gui)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/alpm_helper.rs | 22 ++++++++++++++++++---- src/utils.rs | 16 ++++++++++++++++ 2 files changed, 34 insertions(+), 4 deletions(-) diff --git a/src/alpm_helper.rs b/src/alpm_helper.rs index 0818e96..0b9ee03 100644 --- a/src/alpm_helper.rs +++ b/src/alpm_helper.rs @@ -1,4 +1,5 @@ use crate::utils; +use crate::utils::PacmanWrapper; #[derive(Clone, Debug)] #[repr(C)] @@ -74,15 +75,28 @@ impl AlpmHelper { } fn install_apps(&self, pkg_list: &Vec, install: bool) -> bool { - let mut install_arg: &str = "-Sy"; if pkg_list.is_empty() { return false; - } else if !install { - install_arg = "-R"; } + let (cmd, escalate) = match install { + true => match utils::get_pacman_wrapper_gui() { + PacmanWrapper::Pamac => ("pamac-installer", false), + PacmanWrapper::Pak => ("pak -Sy", false), + PacmanWrapper::Yay => ("yay -Sy", false), + PacmanWrapper::Paru => ("paru -Sy", false), + _ => ("pacman -Sy", true), + }, + false => match utils::get_pacman_wrapper_gui() { + PacmanWrapper::Pamac => ("pamac-installer --remove", false), + PacmanWrapper::Pak => ("pak -R", false), + PacmanWrapper::Yay => ("yay -R", false), + PacmanWrapper::Paru => ("paru -R", false), + _ => ("pacman -R", true), + }, + }; let packages_do = pkg_list.iter().map(|s| s.to_string() + " ").collect::(); - let _ = utils::run_cmd_terminal(format!("pacman {} {}", install_arg, packages_do), true); + let _ = utils::run_cmd_terminal(format!("{} {}", cmd, packages_do), escalate); match install { true => self.app_installed(&pkg_list[0]), false => !self.app_installed(&pkg_list[0]), diff --git a/src/utils.rs b/src/utils.rs index a2045a0..43676f9 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,6 +10,7 @@ pub enum PacmanWrapper { Pak, Yay, Paru, + Pamac, Pacman, } @@ -105,6 +106,21 @@ pub fn get_pacman_wrapper() -> PacmanWrapper { PacmanWrapper::Pacman } +#[inline] +pub fn get_pacman_wrapper_gui() -> PacmanWrapper { + if Path::new("/sbin/pamac-installer").exists() { + return PacmanWrapper::Pamac; + } else if Path::new("/sbin/pak").exists() { + return PacmanWrapper::Pak; + } else if Path::new("/sbin/yay").exists() { + return PacmanWrapper::Yay; + } else if Path::new("/sbin/paru").exists() { + return PacmanWrapper::Paru; + } + + PacmanWrapper::Pacman +} + #[cfg(test)] mod test { use super::*;