optimize status fetch
This commit is contained in:
@@ -177,6 +177,11 @@ async fn install_software(
|
||||
state.install_tx.send(task).await.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn get_software_info(app: AppHandle, id: String) -> Option<Software> {
|
||||
tokio::task::spawn_blocking(move || winget::get_software_info(&app, &id)).await.unwrap_or(None)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
fn get_logs_history() -> Vec<LogPayload> {
|
||||
vec![]
|
||||
@@ -541,6 +546,7 @@ pub fn run() {
|
||||
get_essentials,
|
||||
get_installed_software,
|
||||
get_updates,
|
||||
get_software_info,
|
||||
install_software,
|
||||
get_logs_history
|
||||
])
|
||||
|
||||
@@ -260,6 +260,27 @@ pub fn list_updates(handle: &AppHandle) -> Vec<Software> {
|
||||
execute_powershell(handle, &log_id, "Fetch Updates", script)
|
||||
}
|
||||
|
||||
pub fn get_software_info(handle: &AppHandle, id: &str) -> Option<Software> {
|
||||
let log_id = format!("get-info-{}", chrono::Local::now().timestamp_millis());
|
||||
let script = format!(r#"
|
||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
Import-Module Microsoft.WinGet.Client -ErrorAction SilentlyContinue
|
||||
$pkg = Get-WinGetPackage -Id "{}" -ErrorAction SilentlyContinue
|
||||
if ($pkg) {{
|
||||
[PSCustomObject]@{{
|
||||
Name = [string]$pkg.Name;
|
||||
Id = [string]$pkg.Id;
|
||||
InstalledVersion = [string]$pkg.InstalledVersion;
|
||||
AvailableVersions = @()
|
||||
}} | ConvertTo-Json -Compress
|
||||
}}
|
||||
"#, id);
|
||||
|
||||
let res = execute_powershell(handle, &log_id, "Fetch Single Software Info", &script);
|
||||
res.into_iter().next()
|
||||
}
|
||||
|
||||
fn execute_powershell(handle: &AppHandle, log_id: &str, cmd_title: &str, script: &str) -> Vec<Software> {
|
||||
emit_log(handle, log_id, cmd_title, "Fetching data from Winget...", "info");
|
||||
|
||||
|
||||
Reference in New Issue
Block a user