support custom manifest
This commit is contained in:
@@ -26,6 +26,8 @@ pub struct EssentialsRepo {
|
||||
pub struct InstallTask {
|
||||
pub id: String,
|
||||
pub version: Option<String>,
|
||||
pub use_manifest: bool,
|
||||
pub manifest_url: Option<String>,
|
||||
}
|
||||
|
||||
impl Default for AppSettings {
|
||||
@@ -165,8 +167,14 @@ async fn get_updates(app: AppHandle) -> Vec<Software> {
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
async fn install_software(id: String, version: Option<String>, state: State<'_, AppState>) -> Result<(), String> {
|
||||
state.install_tx.send(InstallTask { id, version }).await.map_err(|e| e.to_string())
|
||||
async fn install_software(
|
||||
id: String,
|
||||
version: Option<String>,
|
||||
use_manifest: bool,
|
||||
manifest_url: Option<String>,
|
||||
state: State<'_, AppState>
|
||||
) -> Result<(), String> {
|
||||
state.install_tx.send(InstallTask { id, version, use_manifest, manifest_url }).await.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@@ -196,6 +204,8 @@ pub fn run() {
|
||||
while let Some(task) = rx.recv().await {
|
||||
let id = task.id;
|
||||
let version = task.version;
|
||||
let use_manifest = task.use_manifest;
|
||||
let manifest_url = task.manifest_url;
|
||||
|
||||
let log_id = format!("install-{}", id);
|
||||
let _ = handle.emit("install-status", InstallProgress {
|
||||
@@ -204,31 +214,44 @@ pub fn run() {
|
||||
progress: 0.0,
|
||||
});
|
||||
|
||||
let display_cmd = match &version {
|
||||
Some(v) => format!("Winget Install: {} (v{})", id, v),
|
||||
None => format!("Winget Install: {}", id),
|
||||
};
|
||||
emit_log(&handle, &log_id, &display_cmd, "Starting...", "info");
|
||||
let mut args = vec!["install".to_string()];
|
||||
let display_cmd: String;
|
||||
|
||||
let id_for_cmd = id.clone();
|
||||
let h = handle.clone();
|
||||
|
||||
let mut args = vec![
|
||||
"install".to_string(),
|
||||
"--id".to_string(), id_for_cmd.clone(),
|
||||
"-e".to_string(),
|
||||
if use_manifest && manifest_url.is_some() {
|
||||
let url = manifest_url.unwrap();
|
||||
args.push("--manifest".to_string());
|
||||
args.push(url.clone());
|
||||
display_cmd = format!("Winget Install (Manifest): {} from {}", id, url);
|
||||
} else {
|
||||
args.push("--id".to_string());
|
||||
args.push(id.clone());
|
||||
args.push("-e".to_string());
|
||||
|
||||
if let Some(v) = &version {
|
||||
if !v.is_empty() {
|
||||
args.push("--version".to_string());
|
||||
args.push(v.clone());
|
||||
}
|
||||
}
|
||||
|
||||
display_cmd = match &version {
|
||||
Some(v) if !v.is_empty() => format!("Winget Install: {} (v{})", id, v),
|
||||
_ => format!("Winget Install: {}", id),
|
||||
};
|
||||
}
|
||||
|
||||
// 共同的静默与协议参数
|
||||
args.extend([
|
||||
"--silent".to_string(),
|
||||
"--accept-package-agreements".to_string(),
|
||||
"--accept-source-agreements".to_string(),
|
||||
"--disable-interactivity".to_string(),
|
||||
];
|
||||
]);
|
||||
|
||||
if let Some(v) = version {
|
||||
if !v.is_empty() {
|
||||
args.push("--version".to_string());
|
||||
args.push(v);
|
||||
}
|
||||
}
|
||||
emit_log(&handle, &log_id, &display_cmd, "Starting...", "info");
|
||||
|
||||
let id_for_progress = id.clone();
|
||||
let h = handle.clone();
|
||||
|
||||
let child = Command::new("winget")
|
||||
.args(&args)
|
||||
@@ -253,7 +276,7 @@ pub fn run() {
|
||||
if let Some(caps) = perc_re.captures(clean_line) {
|
||||
if let Ok(p_val) = caps[1].parse::<f32>() {
|
||||
let _ = h.emit("install-status", InstallProgress {
|
||||
id: id_for_cmd.clone(),
|
||||
id: id_for_progress.clone(),
|
||||
status: "installing".to_string(),
|
||||
progress: p_val / 100.0,
|
||||
});
|
||||
@@ -265,7 +288,7 @@ pub fn run() {
|
||||
let total = caps[2].parse::<f32>().unwrap_or(1.0);
|
||||
if total > 0.0 {
|
||||
let _ = h.emit("install-status", InstallProgress {
|
||||
id: id_for_cmd.clone(),
|
||||
id: id_for_progress.clone(),
|
||||
status: "installing".to_string(),
|
||||
progress: (current / total).min(1.0),
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user