[fix] powershell black screens and try to solve update re-start not working

This commit is contained in:
2025-11-08 19:14:18 +08:00
parent c50fedd305
commit 11afc6dc9e
12 changed files with 357 additions and 281 deletions

View File

@@ -21,6 +21,13 @@ strip = true # Remove debug symbols
opt-level = 0 # 关闭优化
debug = true # 保留调试信息
[profile.fast-release]
inherits = "release"
lto = false # 关闭链接时优化,加快构建速度
codegen-units = 16 # 增加并行编译单元,加快构建速度
strip = false # 不剥离调试符号,加快构建速度
opt-level = 2 # 使用适中的优化级别(比 release 的 "s" 更快)
[build-dependencies]
tauri-build = { version = "2.5.1", features = [] }

View File

@@ -377,14 +377,23 @@ pub fn install_app_update(installer_path: String) -> Result<(), String> {
#[cfg(target_os = "windows")]
pub async fn get_computer_info() -> Result<serde_json::Value, String> {
use tokio::process::Command;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x08000000;
// 异步执行 PowerShell 命令获取计算机信息并转换为 JSON
let output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-ComputerInfo | Select-Object OsName, OSDisplayVersion, BiosSMBIOSBIOSVersion, CsManufacturer, CsName | ConvertTo-Json -Compress"
])
let mut cmd = Command::new("powershell");
cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-ComputerInfo | Select-Object OsName, OSDisplayVersion, BiosSMBIOSBIOSVersion, CsManufacturer, CsName | ConvertTo-Json -Compress"
]);
#[cfg(windows)]
cmd.creation_flags(CREATE_NO_WINDOW);
let output = cmd
.output()
.await
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;
@@ -423,14 +432,17 @@ pub async fn get_computer_info() -> Result<serde_json::Value, String> {
// 如果没有从 OSDisplayVersion 获取到版本代码,尝试从注册表获取 ReleaseId
if !json.get("ReleaseId").and_then(|v| v.as_str()).is_some() {
let release_id_output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; try { (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion').ReleaseId } catch { $null }"
])
.output()
.await;
let mut release_cmd = Command::new("powershell");
release_cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; try { (Get-ItemProperty -Path 'HKLM:\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion').ReleaseId } catch { $null }"
]);
#[cfg(windows)]
release_cmd.creation_flags(CREATE_NO_WINDOW);
let release_id_output = release_cmd.output().await;
if let Ok(release_output) = release_id_output {
if release_output.status.success() {
@@ -552,14 +564,23 @@ pub struct MotherboardInfo {
#[cfg(target_os = "windows")]
pub async fn get_memory_info() -> Result<Vec<MemoryInfo>, String> {
use tokio::process::Command;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x08000000;
// 执行 PowerShell 命令获取内存信息
let output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-WmiObject Win32_PhysicalMemory | Select-Object Capacity, Manufacturer, ConfiguredClockSpeed, Speed | ConvertTo-Json -Compress"
])
let mut cmd = Command::new("powershell");
cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-WmiObject Win32_PhysicalMemory | Select-Object Capacity, Manufacturer, ConfiguredClockSpeed, Speed | ConvertTo-Json -Compress"
]);
#[cfg(windows)]
cmd.creation_flags(CREATE_NO_WINDOW);
let output = cmd
.output()
.await
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;
@@ -635,14 +656,23 @@ pub async fn get_memory_info() -> Result<Vec<MemoryInfo>, String> {
#[cfg(target_os = "windows")]
pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
use tokio::process::Command;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x08000000;
// 执行 PowerShell 命令获取显示器信息
let output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorID | ForEach-Object { [PSCustomObject]@{ Manufacturer = [System.Text.Encoding]::ASCII.GetString($_.ManufacturerName) -replace \"`0\"; Model = [System.Text.Encoding]::ASCII.GetString($_.UserFriendlyName) -replace \"`0\" } } | ConvertTo-Json -Compress"
])
let mut cmd = Command::new("powershell");
cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorID | ForEach-Object { [PSCustomObject]@{ Manufacturer = [System.Text.Encoding]::ASCII.GetString($_.ManufacturerName) -replace \"`0\"; Model = [System.Text.Encoding]::ASCII.GetString($_.UserFriendlyName) -replace \"`0\" } } | ConvertTo-Json -Compress"
]);
#[cfg(windows)]
cmd.creation_flags(CREATE_NO_WINDOW);
let output = cmd
.output()
.await
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;
@@ -673,34 +703,43 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
}
// 尝试获取刷新率和分辨率信息
let _display_output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorBasicDisplayParams | Select-Object MaxHorizontalImageSize, MaxVerticalImageSize | ConvertTo-Json -Compress"
])
.output()
.await;
let mut _display_cmd = Command::new("powershell");
_display_cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorBasicDisplayParams | Select-Object MaxHorizontalImageSize, MaxVerticalImageSize | ConvertTo-Json -Compress"
]);
#[cfg(windows)]
_display_cmd.creation_flags(CREATE_NO_WINDOW);
let _display_output = _display_cmd.output().await;
// 获取刷新率信息
let _refresh_output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorListedSupportedSourceModes | Select-Object -First 1 -ExpandProperty ModeTimings | Select-Object -First 1 -ExpandProperty RefreshRate | ConvertTo-Json -Compress"
])
.output()
.await;
let mut _refresh_cmd = Command::new("powershell");
_refresh_cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -Namespace root/wmi -ClassName WmiMonitorListedSupportedSourceModes | Select-Object -First 1 -ExpandProperty ModeTimings | Select-Object -First 1 -ExpandProperty RefreshRate | ConvertTo-Json -Compress"
]);
#[cfg(windows)]
_refresh_cmd.creation_flags(CREATE_NO_WINDOW);
let _refresh_output = _refresh_cmd.output().await;
// 获取当前显示器的分辨率和刷新率
let current_display_output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Add-Type -AssemblyName System.Windows.Forms; $screens = [System.Windows.Forms.Screen]::AllScreens; $screens | ForEach-Object { [PSCustomObject]@{ Width = $_.Bounds.Width; Height = $_.Bounds.Height; Primary = $_.Primary } } | ConvertTo-Json -Compress"
])
.output()
.await;
let mut current_display_cmd = Command::new("powershell");
current_display_cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Add-Type -AssemblyName System.Windows.Forms; $screens = [System.Windows.Forms.Screen]::AllScreens; $screens | ForEach-Object { [PSCustomObject]@{ Width = $_.Bounds.Width; Height = $_.Bounds.Height; Primary = $_.Primary } } | ConvertTo-Json -Compress"
]);
#[cfg(windows)]
current_display_cmd.creation_flags(CREATE_NO_WINDOW);
let current_display_output = current_display_cmd.output().await;
// 合并显示器信息
if let Ok(display_result) = current_display_output {
@@ -783,14 +822,23 @@ pub async fn get_monitor_info() -> Result<Vec<MonitorInfo>, String> {
#[cfg(target_os = "windows")]
pub async fn get_motherboard_info() -> Result<MotherboardInfo, String> {
use tokio::process::Command;
#[cfg(windows)]
use std::os::windows::process::CommandExt;
#[cfg(windows)]
const CREATE_NO_WINDOW: u32 = 0x08000000;
// 执行 PowerShell 命令获取主板信息
let output = Command::new("powershell")
.args(&[
"-NoProfile",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -ClassName Win32_BaseBoard | Select-Object Manufacturer, Product, Version | ConvertTo-Json -Compress"
])
let mut cmd = Command::new("powershell");
cmd.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
"[Console]::OutputEncoding = [System.Text.Encoding]::UTF8; Get-CimInstance -ClassName Win32_BaseBoard | Select-Object Manufacturer, Product, Version | ConvertTo-Json -Compress"
]);
#[cfg(windows)]
cmd.creation_flags(CREATE_NO_WINDOW);
let output = cmd
.output()
.await
.map_err(|e| format!("执行 PowerShell 命令失败: {}", e))?;

View File

@@ -36,10 +36,15 @@ pub fn get_exe_path(name: &str) -> Result<String, std::io::Error> {
// ----
// 进程路径
let command = format!("Get-Process {} | Select-Object path", name);
let args = command.split_whitespace().collect::<Vec<&str>>();
#[cfg(windows)]
let output = Command::new("powershell.exe")
.args(&args)
.args(&[
"-NoProfile",
"-WindowStyle",
"Hidden",
"-Command",
&command,
])
.creation_flags(CREATE_NO_WINDOW)
.output()?;

View File

@@ -415,17 +415,23 @@ pub async fn download_update(
/// 安装更新Windows
#[cfg(target_os = "windows")]
pub fn install_update(installer_path: &str) -> Result<()> {
// 使用 /S 静默安装
let mut cmd = Command::new(installer_path);
cmd.args(&["/S"]); // 静默安装
cmd.creation_flags(CREATE_NO_WINDOW);
cmd.spawn()?;
let mut child = cmd.spawn()?;
// 等待安装程序完成
child.wait()?;
// 安装完成后,由前端调用 relaunch() 来启动新版本
Ok(())
}
/// 安装更新macOS
#[cfg(target_os = "macos")]
pub fn install_update(installer_path: &str) -> Result<()> {
Command::new("open").arg(installer_path).spawn()?;
let mut child = Command::new("open").arg(installer_path).spawn()?;
// 等待安装程序完成
child.wait()?;
Ok(())
}
@@ -433,13 +439,15 @@ pub fn install_update(installer_path: &str) -> Result<()> {
#[cfg(target_os = "linux")]
pub fn install_update(installer_path: &str) -> Result<()> {
if installer_path.ends_with(".deb") {
Command::new("sudo")
let mut child = Command::new("sudo")
.args(&["dpkg", "-i", installer_path])
.spawn()?;
child.wait()?;
} else if installer_path.ends_with(".AppImage") {
Command::new("chmod")
let mut child = Command::new("chmod")
.args(&["+x", installer_path])
.spawn()?;
child.wait()?;
}
Ok(())
}

View File

@@ -51,7 +51,7 @@
},
"productName": "CS工具箱",
"mainBinaryName": "cstb",
"version": "0.0.6-beta.7",
"version": "0.0.6-beta.6",
"identifier": "upup.cool",
"plugins": {
"deep-link": {