support disable config

This commit is contained in:
Julian Freeman
2026-04-04 19:06:27 -04:00
parent 8067cc870f
commit 886f513b5d
5 changed files with 107 additions and 48 deletions

View File

@@ -31,8 +31,12 @@ pub struct InstallTask {
#[serde(default)]
pub use_manifest: bool,
pub manifest_url: Option<String>,
#[serde(default = "default_true")]
pub enable_post_install: bool,
}
fn default_true() -> bool { true }
impl Default for AppSettings {
fn default() -> Self {
Self {
@@ -116,7 +120,6 @@ async fn sync_essentials(app: AppHandle) -> Result<bool, String> {
Ok(response) => {
if response.status().is_success() {
let content = response.text().await.map_err(|e| e.to_string())?;
// 验证 JSON 格式(新格式:{ version: string, essentials: Vec<Software> }
let validation: Result<EssentialsRepo, _> = serde_json::from_str(&content);
if validation.is_ok() {
let path = get_essentials_path(&app);
@@ -194,11 +197,9 @@ fn expand_win_path(path: &str) -> PathBuf {
];
for var in env_vars {
// 创建不区分大小写的正则表达式,匹配 %VAR%
let re = Regex::new(&format!(r"(?i)%{}%", var)).unwrap();
if re.is_match(&expanded) {
if let Ok(val) = std::env::var(var) {
// 使用正则表达式替换所有匹配项
expanded = re.replace_all(&expanded, val.as_str()).to_string();
}
}
@@ -211,7 +212,6 @@ async fn execute_post_install(handle: &AppHandle, log_id: &str, steps: Vec<PostI
for (i, step) in steps.into_iter().enumerate() {
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,
@@ -335,7 +335,6 @@ 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");
@@ -370,6 +369,7 @@ pub fn run() {
let task_version = task.version.clone();
let use_manifest = task.use_manifest;
let manifest_url = task.manifest_url.clone();
let enable_post_install_flag = task.enable_post_install;
let log_id = format!("install-{}", task_id);
@@ -494,7 +494,7 @@ pub fn run() {
let exit_status = child_proc.wait().map(|s| s.success()).unwrap_or(false);
let status_result = if exit_status { "success" } else { "error" };
if status_result == "success" {
if status_result == "success" && enable_post_install_flag {
let essentials = get_essentials(handle.clone());
let software_info = essentials.and_then(|repo| {
repo.essentials.into_iter().find(|s| s.id == task_id)