upgrade essentials versions

This commit is contained in:
Julian Freeman
2026-03-30 20:21:44 -04:00
parent 7afdc845fa
commit 4f46d745f0
3 changed files with 64 additions and 18 deletions

View File

@@ -22,6 +22,12 @@ pub struct EssentialsRepo {
pub essentials: Vec<Software>,
}
#[derive(Clone, Serialize, Deserialize)]
pub struct InstallTask {
pub id: String,
pub version: Option<String>,
}
impl Default for AppSettings {
fn default() -> Self {
Self {
@@ -31,7 +37,7 @@ impl Default for AppSettings {
}
struct AppState {
install_tx: mpsc::Sender<String>,
install_tx: mpsc::Sender<InstallTask>,
}
#[derive(Clone, Serialize)]
@@ -159,8 +165,8 @@ async fn get_updates(app: AppHandle) -> Vec<Software> {
}
#[tauri::command]
async fn install_software(id: String, state: State<'_, AppState>) -> Result<(), String> {
state.install_tx.send(id).await.map_err(|e| e.to_string())
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())
}
#[tauri::command]
@@ -180,14 +186,17 @@ pub fn run() {
.plugin(tauri_plugin_opener::init())
.setup(move |app| {
let handle = app.handle().clone();
let (tx, mut rx) = mpsc::channel::<String>(100);
let (tx, mut rx) = mpsc::channel::<InstallTask>(100);
app.manage(AppState { install_tx: tx });
tauri::async_runtime::spawn(async move {
let perc_re = Regex::new(r"(\d+)\s*%").unwrap();
let size_re = Regex::new(r"([\d\.]+)\s*[a-zA-Z]+\s*/\s*([\d\.]+)\s*[a-zA-Z]+").unwrap();
while let Some(id) = rx.recv().await {
while let Some(task) = rx.recv().await {
let id = task.id;
let version = task.version;
let log_id = format!("install-{}", id);
let _ = handle.emit("install-status", InstallProgress {
id: id.clone(),
@@ -195,17 +204,34 @@ pub fn run() {
progress: 0.0,
});
emit_log(&handle, &log_id, &format!("Winget Install: {}", id), "Starting...", "info");
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 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(),
"--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);
}
}
let child = Command::new("winget")
.args([
"install", "--id", &id_for_cmd, "-e", "--silent",
"--accept-package-agreements", "--accept-source-agreements",
"--disable-interactivity"
])
.args(&args)
.stdout(Stdio::piped())
.stderr(Stdio::piped())
.creation_flags(0x08000000)