Compare commits
2 Commits
569b13d820
...
f83ccbe2da
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f83ccbe2da | ||
|
|
9803ec67ca |
1
src-tauri/Cargo.lock
generated
1
src-tauri/Cargo.lock
generated
@@ -4623,6 +4623,7 @@ name = "win-softmgr"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"regex",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri",
|
"tauri",
|
||||||
|
|||||||
@@ -24,4 +24,5 @@ serde = { version = "1", features = ["derive"] }
|
|||||||
serde_json = "1"
|
serde_json = "1"
|
||||||
tokio = { version = "1.50.0", features = ["full"] }
|
tokio = { version = "1.50.0", features = ["full"] }
|
||||||
chrono = "0.4.44"
|
chrono = "0.4.44"
|
||||||
|
regex = "1.12.3"
|
||||||
|
|
||||||
|
|||||||
@@ -1,12 +1,14 @@
|
|||||||
pub mod winget;
|
pub mod winget;
|
||||||
|
|
||||||
use std::fs;
|
use std::fs;
|
||||||
use std::process::Command;
|
use std::process::{Command, Stdio};
|
||||||
use std::os::windows::process::CommandExt;
|
use std::os::windows::process::CommandExt;
|
||||||
|
use std::io::{BufRead, BufReader};
|
||||||
use tokio::sync::mpsc;
|
use tokio::sync::mpsc;
|
||||||
use tauri::{AppHandle, Manager, State, Emitter};
|
use tauri::{AppHandle, Manager, State, Emitter};
|
||||||
use serde::Serialize;
|
use serde::Serialize;
|
||||||
use winget::{Software, list_all_software, list_updates, ensure_winget_dependencies};
|
use winget::{Software, list_all_software, list_updates, ensure_winget_dependencies};
|
||||||
|
use regex::Regex;
|
||||||
|
|
||||||
struct AppState {
|
struct AppState {
|
||||||
install_tx: mpsc::Sender<String>,
|
install_tx: mpsc::Sender<String>,
|
||||||
@@ -14,15 +16,17 @@ struct AppState {
|
|||||||
|
|
||||||
#[derive(Clone, Serialize)]
|
#[derive(Clone, Serialize)]
|
||||||
pub struct LogPayload {
|
pub struct LogPayload {
|
||||||
|
pub id: String,
|
||||||
pub timestamp: String,
|
pub timestamp: String,
|
||||||
pub command: String,
|
pub command: String,
|
||||||
pub output: String,
|
pub output: String,
|
||||||
pub status: String,
|
pub status: String,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn emit_log(handle: &AppHandle, command: &str, output: &str, status: &str) {
|
pub fn emit_log(handle: &AppHandle, id: &str, command: &str, output: &str, status: &str) {
|
||||||
let now = chrono::Local::now().format("%H:%M:%S").to_string();
|
let now = chrono::Local::now().format("%H:%M:%S").to_string();
|
||||||
let _ = handle.emit("log-event", LogPayload {
|
let _ = handle.emit("log-event", LogPayload {
|
||||||
|
id: id.to_string(),
|
||||||
timestamp: now,
|
timestamp: now,
|
||||||
command: command.to_string(),
|
command: command.to_string(),
|
||||||
output: output.to_string(),
|
output: output.to_string(),
|
||||||
@@ -32,7 +36,6 @@ pub fn emit_log(handle: &AppHandle, command: &str, output: &str, status: &str) {
|
|||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn initialize_app(app: AppHandle) -> Result<bool, String> {
|
async fn initialize_app(app: AppHandle) -> Result<bool, String> {
|
||||||
// 执行耗时的环境配置
|
|
||||||
tokio::task::spawn_blocking(move || {
|
tokio::task::spawn_blocking(move || {
|
||||||
ensure_winget_dependencies(&app).map(|_| true)
|
ensure_winget_dependencies(&app).map(|_| true)
|
||||||
}).await.unwrap_or(Err("Initialization Task Panicked".to_string()))
|
}).await.unwrap_or(Err("Initialization Task Panicked".to_string()))
|
||||||
@@ -112,49 +115,102 @@ 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 });
|
||||||
|
|
||||||
// 移除了在 setup 中直接执行异步 init 的逻辑,改为由前端指令触发
|
let init_handle = handle.clone();
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
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 {
|
||||||
|
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();
|
||||||
|
|
||||||
while let Some(id) = rx.recv().await {
|
while let Some(id) = rx.recv().await {
|
||||||
|
let log_id = format!("install-{}", id);
|
||||||
let _ = handle.emit("install-status", InstallProgress {
|
let _ = handle.emit("install-status", InstallProgress {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
status: "installing".to_string(),
|
status: "installing".to_string(),
|
||||||
progress: 0.5,
|
progress: 0.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
emit_log(&handle, &format!("winget install --id {}", id), "Starting installation...", "info");
|
emit_log(&handle, &log_id, &format!("Winget Install: {}", id), "Starting...", "info");
|
||||||
|
|
||||||
let id_for_cmd = id.clone();
|
let id_for_cmd = id.clone();
|
||||||
let h = handle.clone();
|
let h = handle.clone();
|
||||||
let status_result = tokio::task::spawn_blocking(move || {
|
|
||||||
let output = Command::new("winget")
|
let child = Command::new("winget")
|
||||||
.args([
|
.args([
|
||||||
"install", "--id", &id_for_cmd, "-e", "--silent",
|
"install", "--id", &id_for_cmd, "-e", "--silent",
|
||||||
"--accept-package-agreements", "--accept-source-agreements",
|
"--accept-package-agreements", "--accept-source-agreements",
|
||||||
"--disable-interactivity"
|
"--disable-interactivity"
|
||||||
])
|
])
|
||||||
|
.stdout(Stdio::piped())
|
||||||
|
.stderr(Stdio::piped())
|
||||||
.creation_flags(0x08000000)
|
.creation_flags(0x08000000)
|
||||||
.output();
|
.spawn();
|
||||||
|
|
||||||
match output {
|
let status_result = match child {
|
||||||
Ok(out) => {
|
Ok(mut child_proc) => {
|
||||||
let msg = String::from_utf8_lossy(&out.stdout).to_string();
|
if let Some(stdout) = child_proc.stdout.take() {
|
||||||
let err = String::from_utf8_lossy(&out.stderr).to_string();
|
let reader = BufReader::new(stdout);
|
||||||
emit_log(&h, &format!("Install result for {}", id_for_cmd), &format!("OUT: {}\nERR: {}", msg, err), if out.status.success() { "success" } else { "error" });
|
for line_res in reader.split(b'\r') {
|
||||||
if out.status.success() { "success" } else { "error" }
|
if let Ok(line_bytes) = line_res {
|
||||||
|
let line_str = String::from_utf8_lossy(&line_bytes).to_string();
|
||||||
|
let clean_line = line_str.trim();
|
||||||
|
|
||||||
|
if clean_line.is_empty() { continue; }
|
||||||
|
|
||||||
|
let mut is_progress = false;
|
||||||
|
|
||||||
|
if let Some(caps) = perc_re.captures(clean_line) {
|
||||||
|
if let Ok(p_val) = caps[1].parse::<f32>() {
|
||||||
|
let _ = h.emit("install-status", InstallProgress {
|
||||||
|
id: id_for_cmd.clone(),
|
||||||
|
status: "installing".to_string(),
|
||||||
|
progress: p_val / 100.0,
|
||||||
|
});
|
||||||
|
is_progress = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else if let Some(caps) = size_re.captures(clean_line) {
|
||||||
|
let current = caps[1].parse::<f32>().unwrap_or(0.0);
|
||||||
|
let total = caps[2].parse::<f32>().unwrap_or(1.0);
|
||||||
|
if total > 0.0 {
|
||||||
|
let _ = h.emit("install-status", InstallProgress {
|
||||||
|
id: id_for_cmd.clone(),
|
||||||
|
status: "installing".to_string(),
|
||||||
|
progress: (current / total).min(1.0),
|
||||||
|
});
|
||||||
|
is_progress = true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if !is_progress {
|
||||||
|
// 追加内容到同一个日志卡片
|
||||||
|
emit_log(&h, &log_id, "", clean_line, "info");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
let exit_status = child_proc.wait().map(|s| s.success()).unwrap_or(false);
|
||||||
|
if exit_status { "success" } else { "error" }
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
emit_log(&h, &format!("Install error for {}", id_for_cmd), &e.to_string(), "error");
|
emit_log(&h, &log_id, "Fatal Error", &e.to_string(), "error");
|
||||||
"error"
|
"error"
|
||||||
},
|
|
||||||
}
|
}
|
||||||
}).await.unwrap_or("error");
|
};
|
||||||
|
|
||||||
let _ = handle.emit("install-status", InstallProgress {
|
let _ = handle.emit("install-status", InstallProgress {
|
||||||
id: id.clone(),
|
id: id.clone(),
|
||||||
status: status_result.to_string(),
|
status: status_result.to_string(),
|
||||||
progress: 1.0,
|
progress: 1.0,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
emit_log(&handle, &log_id, "Result", &format!("Execution finished: {}", status_result), if status_result == "success" { "success" } else { "error" });
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
@@ -26,35 +26,25 @@ struct WingetPackage {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
||||||
emit_log(handle, "Check Environment", "Performing fast environment check...", "info");
|
let log_id = "env-check";
|
||||||
|
emit_log(handle, log_id, "Environment Check", "Starting system configuration...", "info");
|
||||||
|
|
||||||
// 优化后的脚本:先尝试极速检测,存在则直接退出
|
|
||||||
let setup_script = r#"
|
let setup_script = r#"
|
||||||
$ErrorActionPreference = 'SilentlyContinue'
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
|
Write-Output "Checking module status..."
|
||||||
# 极速路径:如果模块已安装,直接输出 Success 并退出
|
|
||||||
if (Get-Module -ListAvailable Microsoft.WinGet.Client) {
|
if (Get-Module -ListAvailable Microsoft.WinGet.Client) {
|
||||||
Write-Output "ALREADY_READY"
|
Write-Output "ALREADY_READY"
|
||||||
exit 0
|
exit 0
|
||||||
}
|
}
|
||||||
|
Write-Output "Step 1: Enabling TLS 1.2"
|
||||||
# 慢速路径:仅在模块缺失时执行完整初始化
|
|
||||||
Write-Output "CONFIGURING_ENV"
|
|
||||||
[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
|
||||||
|
|
||||||
if (-not (Get-Module -ListAvailable Microsoft.WinGet.Client)) {
|
|
||||||
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,因为它太慢了,移至后台或按需执行
|
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let output = Command::new("powershell")
|
let output = Command::new("powershell")
|
||||||
@@ -65,34 +55,35 @@ 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");
|
||||||
|
|
||||||
if stdout.contains("ALREADY_READY") {
|
if stdout.contains("ALREADY_READY") {
|
||||||
emit_log(handle, "Environment Setup", "Fast check passed: System is ready.", "success");
|
emit_log(handle, log_id, "Result", "Ready (Fast check).", "success");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
// 验证安装结果
|
|
||||||
let check = Command::new("powershell")
|
let check = 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.map(|o| !o.stdout.is_empty()).unwrap_or(false) {
|
||||||
emit_log(handle, "Environment Setup", "Full configuration successful.", "success");
|
emit_log(handle, log_id, "Result", "Module installed successfully.", "success");
|
||||||
Ok(())
|
Ok(())
|
||||||
} else {
|
} else {
|
||||||
let err = String::from_utf8_lossy(&out.stderr).to_string();
|
emit_log(handle, log_id, "Result", "Module installation failed.", "error");
|
||||||
emit_log(handle, "Environment Setup Error", &format!("STDOUT: {}\nSTDERR: {}", stdout, err), "error");
|
|
||||||
Err("Setup failed".to_string())
|
Err("Setup failed".to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
emit_log(handle, "Environment Setup Fatal", &e.to_string(), "error");
|
emit_log(handle, log_id, "Fatal Error", &e.to_string(), "error");
|
||||||
Err(e.to_string())
|
Err(e.to_string())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_all_software(handle: &AppHandle) -> Vec<Software> {
|
pub fn list_all_software(handle: &AppHandle) -> Vec<Software> {
|
||||||
|
let log_id = format!("list-all-{}", chrono::Local::now().timestamp_millis());
|
||||||
let script = r#"
|
let script = r#"
|
||||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
$ErrorActionPreference = 'SilentlyContinue'
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
@@ -112,18 +103,15 @@ pub fn list_all_software(handle: &AppHandle) -> Vec<Software> {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
execute_powershell(handle, "Get All Software", script)
|
execute_powershell(handle, &log_id, "Fetch All Software", script)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_updates(handle: &AppHandle) -> Vec<Software> {
|
pub fn list_updates(handle: &AppHandle) -> Vec<Software> {
|
||||||
|
let log_id = format!("list-updates-{}", chrono::Local::now().timestamp_millis());
|
||||||
let script = r#"
|
let script = r#"
|
||||||
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
$OutputEncoding = [Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
$ErrorActionPreference = 'SilentlyContinue'
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
Import-Module Microsoft.WinGet.Client -ErrorAction SilentlyContinue
|
Import-Module Microsoft.WinGet.Client -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
# 在检查更新前,尝试静默更新源(可选,为了准确性)
|
|
||||||
# winget source update --accept-source-agreements | Out-Null
|
|
||||||
|
|
||||||
$pkgs = Get-WinGetPackage -ErrorAction SilentlyContinue | Where-Object { $_.IsUpdateAvailable }
|
$pkgs = Get-WinGetPackage -ErrorAction SilentlyContinue | Where-Object { $_.IsUpdateAvailable }
|
||||||
if ($pkgs) {
|
if ($pkgs) {
|
||||||
$pkgs | ForEach-Object {
|
$pkgs | ForEach-Object {
|
||||||
@@ -139,11 +127,11 @@ pub fn list_updates(handle: &AppHandle) -> Vec<Software> {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
execute_powershell(handle, "Get Updates", script)
|
execute_powershell(handle, &log_id, "Fetch Updates", script)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_powershell(handle: &AppHandle, cmd_name: &str, script: &str) -> Vec<Software> {
|
fn execute_powershell(handle: &AppHandle, log_id: &str, cmd_title: &str, script: &str) -> Vec<Software> {
|
||||||
emit_log(handle, cmd_name, "Executing PowerShell script...", "info");
|
emit_log(handle, log_id, cmd_title, "Executing PowerShell...", "info");
|
||||||
|
|
||||||
let output = Command::new("powershell")
|
let output = Command::new("powershell")
|
||||||
.args(["-NoProfile", "-Command", script])
|
.args(["-NoProfile", "-Command", script])
|
||||||
@@ -157,20 +145,20 @@ fn execute_powershell(handle: &AppHandle, cmd_name: &str, script: &str) -> Vec<S
|
|||||||
let clean_json = stdout.trim_start_matches('\u{feff}').trim();
|
let clean_json = stdout.trim_start_matches('\u{feff}').trim();
|
||||||
|
|
||||||
if !out.status.success() && !stderr.is_empty() {
|
if !out.status.success() && !stderr.is_empty() {
|
||||||
emit_log(handle, &format!("{} stderr", cmd_name), &stderr, "error");
|
emit_log(handle, log_id, "", &format!("STDERR: {}", stderr), "error");
|
||||||
}
|
}
|
||||||
|
|
||||||
if clean_json.is_empty() || clean_json == "[]" {
|
if clean_json.is_empty() || clean_json == "[]" {
|
||||||
emit_log(handle, cmd_name, "No data returned.", "info");
|
emit_log(handle, log_id, "Result", "No software found.", "info");
|
||||||
return vec![];
|
return vec![];
|
||||||
}
|
}
|
||||||
|
|
||||||
let result = parse_json_output(clean_json.to_string());
|
let result = parse_json_output(clean_json.to_string());
|
||||||
emit_log(handle, cmd_name, &format!("Success: found {} items", result.len()), "success");
|
emit_log(handle, log_id, "Result", &format!("Successfully parsed {} items.", result.len()), "success");
|
||||||
result
|
result
|
||||||
},
|
},
|
||||||
Err(e) => {
|
Err(e) => {
|
||||||
emit_log(handle, cmd_name, &format!("Execution error: {}", e), "error");
|
emit_log(handle, log_id, "Execution Error", &e.to_string(), "error");
|
||||||
vec![]
|
vec![]
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|||||||
10
src/App.vue
10
src/App.vue
@@ -1,6 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<!-- 启动屏专属过渡 -->
|
|
||||||
<transition name="layout-fade">
|
<transition name="layout-fade">
|
||||||
<SplashScreen v-if="!store.isInitialized" :status-text="store.initStatus" />
|
<SplashScreen v-if="!store.isInitialized" :status-text="store.initStatus" />
|
||||||
</transition>
|
</transition>
|
||||||
@@ -9,7 +8,6 @@
|
|||||||
<Sidebar />
|
<Sidebar />
|
||||||
<div class="main-content">
|
<div class="main-content">
|
||||||
<router-view v-slot="{ Component }">
|
<router-view v-slot="{ Component }">
|
||||||
<!-- 页面切换专属过渡:极简、快速 -->
|
|
||||||
<transition name="page-fade" mode="out-in">
|
<transition name="page-fade" mode="out-in">
|
||||||
<component :is="Component" />
|
<component :is="Component" />
|
||||||
</transition>
|
</transition>
|
||||||
@@ -72,11 +70,13 @@ body {
|
|||||||
.main-content {
|
.main-content {
|
||||||
flex: 1;
|
flex: 1;
|
||||||
height: 100vh;
|
height: 100vh;
|
||||||
overflow-y: auto;
|
display: flex; /* 让子元素(页面)能撑满高度 */
|
||||||
|
flex-direction: column;
|
||||||
|
overflow: hidden; /* 禁用全局容器滚动 */
|
||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 1. 布局级别过渡 (Splash -> App): 优雅、大气 */
|
/* 1. 布局级别过渡 (Splash -> App) */
|
||||||
.layout-fade-enter-active,
|
.layout-fade-enter-active,
|
||||||
.layout-fade-leave-active {
|
.layout-fade-leave-active {
|
||||||
transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
|
transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
@@ -87,7 +87,7 @@ body {
|
|||||||
transform: scale(1.05);
|
transform: scale(1.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 2. 页面级别过渡 (Essentials <-> Updates): 快速、响应灵敏 */
|
/* 2. 页面级别过渡 */
|
||||||
.page-fade-enter-active,
|
.page-fade-enter-active,
|
||||||
.page-fade-leave-active {
|
.page-fade-leave-active {
|
||||||
transition: opacity 0.15s ease;
|
transition: opacity 0.15s ease;
|
||||||
|
|||||||
@@ -66,10 +66,18 @@
|
|||||||
<span class="wait-text">等待中</span>
|
<span class="wait-text">等待中</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<!-- 安装中状态:旋转 Loading -->
|
<!-- 安装中状态:显示进度环和百分比 -->
|
||||||
<div v-else-if="software.status === 'installing'" class="progress-status">
|
<div v-else-if="software.status === 'installing'" class="progress-status">
|
||||||
<div class="spinning-loader"></div>
|
<div class="progress-ring-container">
|
||||||
<span class="loading-text">正在安装</span>
|
<svg viewBox="0 0 32 32" class="ring-svg">
|
||||||
|
<circle class="bg" cx="16" cy="16" r="14" fill="none" stroke-width="3" />
|
||||||
|
<circle class="fg" cx="16" cy="16" r="14" fill="none" stroke-width="3"
|
||||||
|
:style="{ strokeDasharray: 88, strokeDashoffset: 88 - (88 * (software.progress || 0)) }"
|
||||||
|
/>
|
||||||
|
</svg>
|
||||||
|
<div v-if="!software.progress" class="inner-loader"></div>
|
||||||
|
</div>
|
||||||
|
<span class="loading-text">{{ displayProgress }}</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div v-else-if="software.status === 'success'" class="status-success">
|
<div v-else-if="software.status === 'success'" class="status-success">
|
||||||
@@ -105,6 +113,11 @@ const props = defineProps<{
|
|||||||
|
|
||||||
const emit = defineEmits(['install', 'toggleSelect']);
|
const emit = defineEmits(['install', 'toggleSelect']);
|
||||||
|
|
||||||
|
const displayProgress = computed(() => {
|
||||||
|
if (!props.software.progress) return '准备中';
|
||||||
|
return Math.round(props.software.progress * 100) + '%';
|
||||||
|
});
|
||||||
|
|
||||||
const placeholderColor = computed(() => {
|
const placeholderColor = computed(() => {
|
||||||
const colors = ['#FF9500', '#FF3B30', '#34C759', '#007AFF', '#5856D6', '#AF52DE'];
|
const colors = ['#FF9500', '#FF3B30', '#34C759', '#007AFF', '#5856D6', '#AF52DE'];
|
||||||
let hash = 0;
|
let hash = 0;
|
||||||
@@ -115,9 +128,7 @@ const placeholderColor = computed(() => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
const handleCardClick = () => {
|
const handleCardClick = () => {
|
||||||
// 安装或等待中禁止修改勾选
|
|
||||||
if (props.software.status === 'pending' || props.software.status === 'installing') return;
|
if (props.software.status === 'pending' || props.software.status === 'installing') return;
|
||||||
|
|
||||||
if (props.selectable && props.software.status !== 'installed') {
|
if (props.selectable && props.software.status !== 'installed') {
|
||||||
emit('toggleSelect', props.software.id);
|
emit('toggleSelect', props.software.id);
|
||||||
}
|
}
|
||||||
@@ -150,10 +161,9 @@ const handleCardClick = () => {
|
|||||||
}
|
}
|
||||||
|
|
||||||
.software-card.is-busy {
|
.software-card.is-busy {
|
||||||
opacity: 0.8;
|
opacity: 0.9;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 勾选框样式 */
|
|
||||||
.selection-area {
|
.selection-area {
|
||||||
margin-right: 16px;
|
margin-right: 16px;
|
||||||
flex-shrink: 0;
|
flex-shrink: 0;
|
||||||
@@ -275,7 +285,7 @@ const handleCardClick = () => {
|
|||||||
|
|
||||||
.card-right {
|
.card-right {
|
||||||
margin-left: 20px;
|
margin-left: 20px;
|
||||||
min-width: 120px;
|
min-width: 100px;
|
||||||
display: flex;
|
display: flex;
|
||||||
justify-content: flex-end;
|
justify-content: flex-end;
|
||||||
}
|
}
|
||||||
@@ -328,24 +338,51 @@ const handleCardClick = () => {
|
|||||||
display: flex;
|
display: flex;
|
||||||
align-items: center;
|
align-items: center;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 4px;
|
gap: 6px;
|
||||||
width: 90px;
|
width: 90px;
|
||||||
justify-content: center;
|
justify-content: center;
|
||||||
}
|
}
|
||||||
|
|
||||||
.spinning-loader {
|
.progress-ring-container {
|
||||||
width: 18px;
|
position: relative;
|
||||||
height: 18px;
|
width: 24px;
|
||||||
border: 2px solid rgba(0, 122, 255, 0.1);
|
height: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ring-svg {
|
||||||
|
transform: rotate(-90deg);
|
||||||
|
width: 100%;
|
||||||
|
height: 100%;
|
||||||
|
}
|
||||||
|
|
||||||
|
.ring-svg .bg {
|
||||||
|
stroke: var(--border-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.ring-svg .fg {
|
||||||
|
stroke: var(--primary-color);
|
||||||
|
stroke-linecap: round;
|
||||||
|
transition: stroke-dashoffset 0.3s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.inner-loader {
|
||||||
|
position: absolute;
|
||||||
|
top: 4px;
|
||||||
|
left: 4px;
|
||||||
|
width: 16px;
|
||||||
|
height: 16px;
|
||||||
|
border: 2px solid transparent;
|
||||||
border-top-color: var(--primary-color);
|
border-top-color: var(--primary-color);
|
||||||
border-radius: 50%;
|
border-radius: 50%;
|
||||||
animation: spin 1s linear infinite;
|
animation: spin 0.8s linear infinite;
|
||||||
}
|
}
|
||||||
|
|
||||||
.loading-text {
|
.loading-text {
|
||||||
font-size: 10px;
|
font-size: 10px;
|
||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
color: var(--primary-color);
|
color: var(--primary-color);
|
||||||
|
text-transform: uppercase;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.status-success, .status-error {
|
.status-success, .status-error {
|
||||||
|
|||||||
@@ -5,6 +5,7 @@ import { listen } from '@tauri-apps/api/event'
|
|||||||
const sortByName = (a: any, b: any) => a.name.localeCompare(b.name, 'zh-CN', { sensitivity: 'accent' });
|
const sortByName = (a: any, b: any) => a.name.localeCompare(b.name, 'zh-CN', { sensitivity: 'accent' });
|
||||||
|
|
||||||
export interface LogEntry {
|
export interface LogEntry {
|
||||||
|
id: string; // 日志唯一标识
|
||||||
timestamp: string;
|
timestamp: string;
|
||||||
command: string;
|
command: string;
|
||||||
output: string;
|
output: string;
|
||||||
@@ -41,13 +42,11 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
actionLabel = '已安装';
|
actionLabel = '已安装';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return { ...item, status: displayStatus, actionLabel };
|
return { ...item, status: displayStatus, actionLabel };
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
sortedUpdates: (state) => [...state.updates].sort(sortByName),
|
sortedUpdates: (state) => [...state.updates].sort(sortByName),
|
||||||
sortedAllSoftware: (state) => [...state.allSoftware].sort(sortByName),
|
sortedAllSoftware: (state) => [...state.allSoftware].sort(sortByName),
|
||||||
// 全局繁忙状态:只要有任何软件在等待或安装中,就锁定关键操作
|
|
||||||
isBusy: (state) => {
|
isBusy: (state) => {
|
||||||
const allItems = [...state.essentials, ...state.updates, ...state.allSoftware];
|
const allItems = [...state.essentials, ...state.updates, ...state.allSoftware];
|
||||||
return allItems.some(item => item.status === 'pending' || item.status === 'installing');
|
return allItems.some(item => item.status === 'pending' || item.status === 'installing');
|
||||||
@@ -66,7 +65,7 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
toggleSelection(id: string, type: 'essential' | 'update') {
|
toggleSelection(id: string, type: 'essential' | 'update') {
|
||||||
if (this.isBusy) return; // 繁忙时禁止修改勾选
|
if (this.isBusy) return;
|
||||||
const list = type === 'essential' ? this.selectedEssentialIds : this.selectedUpdateIds;
|
const list = type === 'essential' ? this.selectedEssentialIds : this.selectedUpdateIds;
|
||||||
const index = list.indexOf(id);
|
const index = list.indexOf(id);
|
||||||
if (index === -1) list.push(id);
|
if (index === -1) list.push(id);
|
||||||
@@ -146,12 +145,8 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
async install(id: string) {
|
async install(id: string) {
|
||||||
// 这里的 logic 同时负责单个安装和批量安装的任务入队
|
|
||||||
const software = this.findSoftware(id)
|
const software = this.findSoftware(id)
|
||||||
if (software) {
|
if (software) software.status = 'pending';
|
||||||
// 进入队列前统一标记为等待中
|
|
||||||
software.status = 'pending';
|
|
||||||
}
|
|
||||||
await invoke('install_software', { id })
|
await invoke('install_software', { id })
|
||||||
},
|
},
|
||||||
findSoftware(id: string) {
|
findSoftware(id: string) {
|
||||||
@@ -177,9 +172,24 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
// 日志监听:根据 ID 追加内容
|
||||||
listen('log-event', (event: any) => {
|
listen('log-event', (event: any) => {
|
||||||
this.logs.unshift(event.payload as LogEntry);
|
const payload = event.payload as LogEntry;
|
||||||
if (this.logs.length > 200) this.logs.pop();
|
const existingLog = this.logs.find(l => l.id === payload.id);
|
||||||
|
|
||||||
|
if (existingLog) {
|
||||||
|
// 如果是增量更新
|
||||||
|
if (payload.output) {
|
||||||
|
existingLog.output += '\n' + payload.output;
|
||||||
|
}
|
||||||
|
if (payload.status !== 'info') {
|
||||||
|
existingLog.status = payload.status;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// 如果是新日志
|
||||||
|
this.logs.unshift(payload);
|
||||||
|
if (this.logs.length > 100) this.logs.pop();
|
||||||
|
}
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user