support delay

This commit is contained in:
Julian Freeman
2026-04-04 18:24:34 -04:00
parent 86df026091
commit fbdfcc8abe
2 changed files with 29 additions and 8 deletions

View File

@@ -210,8 +210,17 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec<PostI
let steps_len = steps.len(); let steps_len = steps.len();
for (i, step) in steps.into_iter().enumerate() { for (i, step) in steps.into_iter().enumerate() {
let step_prefix = format!("Step {}/{}: ", i + 1, steps_len); let step_prefix = format!("Step {}/{}: ", i + 1, steps_len);
// 预先提取延迟时间
let delay = match &step {
PostInstallStep::RegistryBatch { delay_ms, .. } => *delay_ms,
PostInstallStep::FileCopy { delay_ms, .. } => *delay_ms,
PostInstallStep::FileDelete { delay_ms, .. } => *delay_ms,
PostInstallStep::Command { delay_ms, .. } => *delay_ms,
};
match step { match step {
PostInstallStep::RegistryBatch { root, base_path, values } => { PostInstallStep::RegistryBatch { root, base_path, values, .. } => {
emit_log(handle, log_id, "Registry Update", &format!("{}Applying batch registry settings to {}...", step_prefix, base_path), "info"); emit_log(handle, log_id, "Registry Update", &format!("{}Applying batch registry settings to {}...", step_prefix, base_path), "info");
let hive = match root.as_str() { let hive = match root.as_str() {
"HKCU" => RegKey::predef(HKEY_CURRENT_USER), "HKCU" => RegKey::predef(HKEY_CURRENT_USER),
@@ -253,7 +262,7 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec<PostI
} }
} }
}, },
PostInstallStep::FileCopy { src, dest } => { PostInstallStep::FileCopy { src, dest, .. } => {
let dest_path = expand_win_path(&dest); let dest_path = expand_win_path(&dest);
let src_is_url = src.starts_with("http://") || src.starts_with("https://"); let src_is_url = src.starts_with("http://") || src.starts_with("https://");
@@ -289,7 +298,7 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec<PostI
} }
} }
}, },
PostInstallStep::FileDelete { path } => { PostInstallStep::FileDelete { path, .. } => {
let full_path = expand_win_path(&path); let full_path = expand_win_path(&path);
emit_log(handle, log_id, "File Delete", &format!("{}Deleting {:?}...", step_prefix, full_path), "info"); emit_log(handle, log_id, "File Delete", &format!("{}Deleting {:?}...", step_prefix, full_path), "info");
if full_path.exists() { if full_path.exists() {
@@ -302,7 +311,7 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec<PostI
emit_log(handle, log_id, "File Info", "File does not exist, skipping.", "info"); emit_log(handle, log_id, "File Info", "File does not exist, skipping.", "info");
} }
}, },
PostInstallStep::Command { run } => { PostInstallStep::Command { run, .. } => {
emit_log(handle, log_id, "Command Execution", &format!("{}Executing: {}", step_prefix, run), "info"); emit_log(handle, log_id, "Command Execution", &format!("{}Executing: {}", step_prefix, run), "info");
let output = Command::new("cmd") let output = Command::new("cmd")
.args(["/C", &run]) .args(["/C", &run])
@@ -324,6 +333,14 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec<PostI
} }
} }
} }
// 如果设置了延迟,执行异步等待
if let Some(ms) = delay {
if ms > 0 {
emit_log(handle, log_id, "Post-Install", &format!("Waiting for {}ms...", ms), "info");
tokio::time::sleep(std::time::Duration::from_millis(ms)).await;
}
}
} }
Ok(()) Ok(())
} }

View File

@@ -16,22 +16,26 @@ pub struct RegistryValue {
pub enum PostInstallStep { pub enum PostInstallStep {
#[serde(rename = "registry_batch")] #[serde(rename = "registry_batch")]
RegistryBatch { RegistryBatch {
root: String, // "HKCU", "HKLM" root: String,
base_path: String, base_path: String,
values: HashMap<String, RegistryValue>, values: HashMap<String, RegistryValue>,
delay_ms: Option<u64>,
}, },
#[serde(rename = "file_copy")] #[serde(rename = "file_copy")]
FileCopy { FileCopy {
src: String, // 支持 URL 或本地路径(含环境变量) src: String,
dest: String, // 目标路径(含环境变量) dest: String,
delay_ms: Option<u64>,
}, },
#[serde(rename = "file_delete")] #[serde(rename = "file_delete")]
FileDelete { FileDelete {
path: String, // 要删除的文件路径(含环境变量) path: String,
delay_ms: Option<u64>,
}, },
#[serde(rename = "command")] #[serde(rename = "command")]
Command { Command {
run: String, run: String,
delay_ms: Option<u64>,
}, },
} }