Compare commits
2 Commits
f83ccbe2da
...
8f55da1940
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
8f55da1940 | ||
|
|
714db81938 |
@@ -115,14 +115,6 @@ pub fn run() {
|
|||||||
let (tx, mut rx) = mpsc::channel::<String>(100);
|
let (tx, mut rx) = mpsc::channel::<String>(100);
|
||||||
app.manage(AppState { install_tx: tx });
|
app.manage(AppState { install_tx: tx });
|
||||||
|
|
||||||
let init_handle = handle.clone();
|
|
||||||
tauri::async_runtime::spawn(async move {
|
|
||||||
let _ = tokio::task::spawn_blocking(move || {
|
|
||||||
let _ = ensure_winget_dependencies(&init_handle);
|
|
||||||
}).await;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 安装队列处理器
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
let perc_re = Regex::new(r"(\d+)\s*%").unwrap();
|
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();
|
let size_re = Regex::new(r"([\d\.]+)\s*[a-zA-Z]+\s*/\s*([\d\.]+)\s*[a-zA-Z]+").unwrap();
|
||||||
@@ -187,8 +179,8 @@ pub fn run() {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if !is_progress {
|
// 净化日志:过滤进度行、单字符动画行以及退格符
|
||||||
// 追加内容到同一个日志卡片
|
if !is_progress && clean_line.chars().count() > 1 {
|
||||||
emit_log(&h, &log_id, "", clean_line, "info");
|
emit_log(&h, &log_id, "", clean_line, "info");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -26,25 +26,38 @@ struct WingetPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
||||||
let log_id = "env-check";
|
emit_log(handle, "env-check", "Environment Check", "Checking system components...", "info");
|
||||||
emit_log(handle, log_id, "Environment Check", "Starting system configuration...", "info");
|
|
||||||
|
|
||||||
|
// 优化后的极速检测脚本
|
||||||
let setup_script = r#"
|
let setup_script = r#"
|
||||||
|
# 强制指定输出编码为 UTF8 (无 BOM)
|
||||||
|
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
$ErrorActionPreference = 'SilentlyContinue'
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
Write-Output "Checking module status..."
|
|
||||||
if (Get-Module -ListAvailable Microsoft.WinGet.Client) {
|
# 使用多种方式确认环境是否已就绪
|
||||||
Write-Output "ALREADY_READY"
|
$module = Get-Module -ListAvailable Microsoft.WinGet.Client
|
||||||
|
$command = Get-Command Get-WinGetPackage -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($module -or $command) {
|
||||||
|
Write-Output "CHECK_RESULT:READY"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
Write-Output "Step 1: Enabling TLS 1.2"
|
|
||||||
|
# 仅在确实缺失时才输出配置日志并开始安装
|
||||||
|
Write-Output "CHECK_RESULT:NEED_INSTALL"
|
||||||
|
|
||||||
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
||||||
Import-Module PackageManagement -ErrorAction SilentlyContinue
|
Import-Module PackageManagement -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
if ($null -eq (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
|
if ($null -eq (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
|
||||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false
|
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false
|
||||||
}
|
}
|
||||||
|
|
||||||
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
|
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
|
||||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
|
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
|
||||||
|
|
||||||
Install-Module -Name Microsoft.WinGet.Client -Force -AllowClobber -Scope CurrentUser -Confirm:$false
|
Install-Module -Name Microsoft.WinGet.Client -Force -AllowClobber -Scope CurrentUser -Confirm:$false
|
||||||
|
winget source update --accept-source-agreements
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let output = Command::new("powershell")
|
let output = Command::new("powershell")
|
||||||
@@ -55,28 +68,32 @@ pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
|||||||
match output {
|
match output {
|
||||||
Ok(out) => {
|
Ok(out) => {
|
||||||
let stdout = String::from_utf8_lossy(&out.stdout).to_string();
|
let stdout = String::from_utf8_lossy(&out.stdout).to_string();
|
||||||
emit_log(handle, log_id, "", &stdout, "info");
|
let stderr = String::from_utf8_lossy(&out.stderr).to_string();
|
||||||
|
|
||||||
if stdout.contains("ALREADY_READY") {
|
// 清理输出字符串,移除 BOM 和换行
|
||||||
emit_log(handle, log_id, "Result", "Ready (Fast check).", "success");
|
let clean_stdout = stdout.trim_start_matches('\u{feff}').trim();
|
||||||
|
|
||||||
|
if clean_stdout.contains("CHECK_RESULT:READY") {
|
||||||
|
emit_log(handle, "env-check", "Result", "Environment is already configured. Skipping install.", "success");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let check = Command::new("powershell")
|
// 如果执行了安装路径,检查最终结果
|
||||||
|
let check_final = Command::new("powershell")
|
||||||
.args(["-NoProfile", "-Command", "Get-Module -ListAvailable Microsoft.WinGet.Client"])
|
.args(["-NoProfile", "-Command", "Get-Module -ListAvailable Microsoft.WinGet.Client"])
|
||||||
.creation_flags(0x08000000)
|
.creation_flags(0x08000000)
|
||||||
.output();
|
.output();
|
||||||
|
|
||||||
if check.map(|o| !o.stdout.is_empty()).unwrap_or(false) {
|
if check_final.map(|o| !o.stdout.is_empty()).unwrap_or(false) {
|
||||||
emit_log(handle, log_id, "Result", "Module installed successfully.", "success");
|
emit_log(handle, "env-check", "Result", "Environment configured successfully.", "success");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
emit_log(handle, log_id, "Result", "Module installation failed.", "error");
|
emit_log(handle, "env-check", "Error", &format!("OUT: {}\nERR: {}", clean_stdout, stderr), "error");
|
||||||
Err("Setup failed".to_string())
|
Err("Setup verification failed".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
emit_log(handle, log_id, "Fatal Error", &e.to_string(), "error");
|
emit_log(handle, "env-check", "Fatal Error", &e.to_string(), "error");
|
||||||
Err(e.to_string())
|
Err(e.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -149,7 +166,7 @@ fn execute_powershell(handle: &AppHandle, log_id: &str, cmd_title: &str, script:
|
|||||||
}
|
}
|
||||||
|
|
||||||
if clean_json.is_empty() || clean_json == "[]" {
|
if clean_json.is_empty() || clean_json == "[]" {
|
||||||
emit_log(handle, log_id, "Result", "No software found.", "info");
|
emit_log(handle, log_id, "Result", "No data returned.", "info");
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user