add splashscreen
This commit is contained in:
@@ -26,10 +26,9 @@ struct WingetPackage {
|
||||
}
|
||||
|
||||
pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
||||
emit_log(handle, "Check Environment", "Initializing system components...", "info");
|
||||
emit_log(handle, "Check Environment", "Initializing system components and updating sources...", "info");
|
||||
|
||||
let setup_script = r#"
|
||||
# 设置容错
|
||||
$ErrorActionPreference = 'SilentlyContinue'
|
||||
|
||||
Write-Output "Step 1: Enabling TLS 1.2"
|
||||
@@ -42,23 +41,24 @@ pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
||||
Write-Output "Step 3: Checking NuGet provider"
|
||||
$provider = Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue
|
||||
if ($null -eq $provider) {
|
||||
Write-Output "Installing NuGet provider..."
|
||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false -ErrorAction SilentlyContinue
|
||||
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false
|
||||
}
|
||||
|
||||
Write-Output "Step 4: Configuring Repository Trust"
|
||||
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted -ErrorAction SilentlyContinue
|
||||
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
|
||||
|
||||
Write-Output "Step 5: Setting Execution Policy"
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force -ErrorAction SilentlyContinue
|
||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
|
||||
|
||||
Write-Output "Step 6: Checking Microsoft.WinGet.Client"
|
||||
if (-not (Get-Module -ListAvailable Microsoft.WinGet.Client)) {
|
||||
Write-Output "Installing Winget Client module (this may take 1-2 minutes)..."
|
||||
Write-Output "Installing Winget Client module..."
|
||||
Install-Module -Name Microsoft.WinGet.Client -Force -AllowClobber -Scope CurrentUser -Confirm:$false
|
||||
} else {
|
||||
Write-Output "Winget Client module is already present."
|
||||
}
|
||||
|
||||
Write-Output "Step 7: Updating Winget Sources (apt-get update style)"
|
||||
# 这一步非常关键,确保 winget 的本地数据库是最新的
|
||||
winget source update --accept-source-agreements
|
||||
"#;
|
||||
|
||||
let output = Command::new("powershell")
|
||||
@@ -70,7 +70,7 @@ pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
||||
Ok(out) => {
|
||||
let msg = String::from_utf8_lossy(&out.stdout).to_string();
|
||||
let err = String::from_utf8_lossy(&out.stderr).to_string();
|
||||
// 只要最终模块存在,就认为成功,忽略过程中的次要警告
|
||||
|
||||
let check_final = Command::new("powershell")
|
||||
.args(["-NoProfile", "-Command", "Get-Module -ListAvailable Microsoft.WinGet.Client"])
|
||||
.creation_flags(0x08000000)
|
||||
@@ -79,7 +79,7 @@ pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
||||
let is_success = check_final.map(|o| !o.stdout.is_empty()).unwrap_or(false);
|
||||
|
||||
if is_success {
|
||||
emit_log(handle, "Environment Setup", "Winget module is ready.", "success");
|
||||
emit_log(handle, "Environment Setup", "Winget module and sources are ready.", "success");
|
||||
Ok(())
|
||||
} else {
|
||||
emit_log(handle, "Environment Setup Error", &format!("OUT: {}\nERR: {}", msg, err), "error");
|
||||
|
||||
Reference in New Issue
Block a user