From 1eb49350e910dc98f4cedf4e00a707f8160cf531 Mon Sep 17 00:00:00 2001 From: Thien Tran Date: Tue, 3 Jun 2025 15:15:57 +0800 Subject: [PATCH] add is_library_available command --- src-tauri/Cargo.toml | 2 +- src-tauri/src/core/utils/mod.rs | 12 ++++++++++++ src-tauri/src/lib.rs | 1 + 3 files changed, 14 insertions(+), 1 deletion(-) diff --git a/src-tauri/Cargo.toml b/src-tauri/Cargo.toml index b6a8b4936..8677902d6 100644 --- a/src-tauri/Cargo.toml +++ b/src-tauri/Cargo.toml @@ -56,9 +56,9 @@ serde_yaml = "0.9.34" hmac = "0.12.1" sha2 = "0.10.9" base64 = "0.22.1" +libloading = "0.8.7" [target.'cfg(windows)'.dependencies] -libloading = "0.8.7" libc = "0.2.172" [target.'cfg(not(any(target_os = "android", target_os = "ios")))'.dependencies] diff --git a/src-tauri/src/core/utils/mod.rs b/src-tauri/src/core/utils/mod.rs index b0bdad838..2a144eafb 100644 --- a/src-tauri/src/core/utils/mod.rs +++ b/src-tauri/src/core/utils/mod.rs @@ -151,3 +151,15 @@ pub fn decompress(app: tauri::AppHandle, path: &str, output_dir: &str) -> Result Ok(()) } + +// check if a system library is available +#[tauri::command] +pub fn is_library_available(library: &str) -> bool { + match unsafe { libloading::Library::new(library) } { + Ok(_) => true, + Err(e) => { + log::info!("Library {} is not available: {}", library, e); + false + } + } +} diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs index 1840b465c..4b923e906 100644 --- a/src-tauri/src/lib.rs +++ b/src-tauri/src/lib.rs @@ -83,6 +83,7 @@ pub fn run() { core::utils::write_yaml, core::utils::read_yaml, core::utils::decompress, + core::utils::is_library_available, // Download core::utils::download::download_files, core::utils::download::cancel_download_task,