From c2877ec3e3bb5f56147d5c51dbb0a1a3078e0e8c Mon Sep 17 00:00:00 2001 From: Krzysztof Andrelczyk Date: Tue, 18 Mar 2025 23:28:34 +0100 Subject: [PATCH] get bundle type out of patched variable --- plugins/updater/src/updater.rs | 105 ++---------------- plugins/updater/tests/app-updater/src/main.rs | 1 - 2 files changed, 8 insertions(+), 98 deletions(-) diff --git a/plugins/updater/src/updater.rs b/plugins/updater/src/updater.rs index 955a22e6..d7a2e547 100644 --- a/plugins/updater/src/updater.rs +++ b/plugins/updater/src/updater.rs @@ -356,111 +356,22 @@ pub struct Updater { current_exe_args: Vec, } -/// Linux (AppImage and Deb) -#[cfg(any( - target_os = "linux", - target_os = "dragonfly", - target_os = "freebsd", - target_os = "netbsd", - target_os = "openbsd" -))] -impl Updater { - - fn is_deb_package(&self) -> bool { - // First check if we're in a typical Debian installation path - let in_system_path = self.extract_path - .to_str() - .map(|p| p.starts_with("/usr")) - .unwrap_or(false); - - if !in_system_path { - return false; - } - - // Then verify it's actually a Debian-based system by checking for dpkg - let dpkg_exists = std::path::Path::new("/var/lib/dpkg").exists(); - let apt_exists = std::path::Path::new("/etc/apt").exists(); - - // Additional check for the package in dpkg database - let package_in_dpkg = if let Ok(output) = std::process::Command::new("dpkg") - .args(["-S", &self.extract_path.to_string_lossy()]) - .output() - { - output.status.success() - } else { - false - }; - - // Consider it a deb package only if: - // 1. We're in a system path AND - // 2. We have Debian package management tools AND - // 3. The binary is tracked by dpkg - dpkg_exists && apt_exists && package_in_dpkg - } - - fn is_rpm_package(&self) -> bool { - // First check if we're in a typical RPM installation path - let in_system_path = self.extract_path - .to_str() - .map(|p| p.starts_with("/usr")) - .unwrap_or(false); - - if !in_system_path { - return false; - } - // Then verify it's actually a Debian-based system by checking for dpkg - let rpm_exists = std::path::Path::new("/var/lib/rpm").exists(); - let etc_rpm_exists = std::path::Path::new("/etc/rpm").exists(); - // Additional check for the package in dpkg database - let package_in_rpm = if let Ok(output) = std::process::Command::new("rpm") - .args(["-qf", &self.extract_path.to_string_lossy()]) - .output() - { - output.status.success() - } else { - false - }; - - // Consider it a deb package only if: - // 1. We're in a system path AND - // 2. We have RPM package management tools AND - // 3. The binary is tracked by rpm - rpm_exists && etc_rpm_exists && package_in_rpm - } - - fn get_updater_installer(&self) -> Result> { - if std::env::var_os("APPIMAGE").is_some() { - Ok(Some(Installer::AppImage)) - } else if self.is_deb_package() { - Ok(Some(Installer::Deb)) - } else if self.is_rpm_package() { - Ok(Some(Installer::Rpm)) - } else { - Err(Error::UnknownInstaller) - } - } -} -#[cfg(target_os = "windows")] impl Updater { - fn get_updater_installer(&self) -> Result> { - Ok(Some(Installer::Msi)) - } - -} -#[cfg(target_os = "macos")] -impl Updater { fn get_updater_installer(&self) -> Result> { - Ok(None) + match tauri::__TAURI_BUNDLE_TYPE { + "DEB_BUNDLE" => Ok(Some(Installer::Deb)), + "RPM_BUNDLE" => Ok(Some(Installer::Rpm)), + "APP_BUNDLE" => Ok(Some(Installer::AppImage)), + "MSI_BUNDLE" => Ok(Some(Installer::Msi)), + "NSS_BUNDLE" => Ok(Some(Installer::Nsis)), + _ => Err(Error::UnknownInstaller) + } } -} - -impl Updater { - pub async fn check(&self) -> Result> { // we want JSON only let mut headers = self.headers.clone(); diff --git a/plugins/updater/tests/app-updater/src/main.rs b/plugins/updater/tests/app-updater/src/main.rs index bbe398b5..5f5566f8 100644 --- a/plugins/updater/tests/app-updater/src/main.rs +++ b/plugins/updater/tests/app-updater/src/main.rs @@ -9,7 +9,6 @@ use tauri_plugin_updater::UpdaterExt; fn main() { #[allow(unused_mut)] let mut context = tauri::generate_context!(); - tauri::Builder::default() .plugin(tauri_plugin_updater::Builder::new().build()) .setup(|app| {