Compare commits
7 Commits
f58c5bede2
...
1552f1cad8
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1552f1cad8 | ||
|
|
e7ed0fa833 | ||
|
|
63b469be97 | ||
|
|
60113e9629 | ||
|
|
cdeb52c316 | ||
|
|
db20a31643 | ||
|
|
72680d6925 |
BIN
app-icon.png
Normal file
|
After Width: | Height: | Size: 83 KiB |
48
app-icon.svg
Normal file
@@ -0,0 +1,48 @@
|
|||||||
|
<svg width="512" height="512" viewBox="0 0 512 512" fill="none" xmlns="http://www.w3.org/2000/svg">
|
||||||
|
<defs>
|
||||||
|
<linearGradient id="bg-grad" x1="0%" y1="0%" x2="100%" y2="100%">
|
||||||
|
<stop offset="0%" style="stop-color:#00C6FF" />
|
||||||
|
<stop offset="100%" style="stop-color:#007AFF" />
|
||||||
|
</linearGradient>
|
||||||
|
<filter id="shadow" x="0" y="0" width="100%" height="100%">
|
||||||
|
<feDropShadow dx="0" dy="8" stdDeviation="12" flood-opacity="0.12"/>
|
||||||
|
</filter>
|
||||||
|
</defs>
|
||||||
|
|
||||||
|
<!-- 背景 Squircle -->
|
||||||
|
<rect x="0" y="0" width="512" height="512" rx="128" fill="url(#bg-grad)" />
|
||||||
|
|
||||||
|
<g filter="url(#shadow)">
|
||||||
|
<!-- 纸箱主体 -->
|
||||||
|
<!-- 左侧面 -->
|
||||||
|
<path d="M120 210V340L256 410V280L120 210Z" fill="#F2F2F7" />
|
||||||
|
<!-- 右侧面 -->
|
||||||
|
<path d="M392 210V340L256 410V280L392 210Z" fill="#E5E5EA" />
|
||||||
|
<!-- 顶部盖板 -->
|
||||||
|
<path d="M256 140L120 210L256 280L392 210L256 140Z" fill="#FFFFFF" />
|
||||||
|
|
||||||
|
<!-- 纸箱接缝 -->
|
||||||
|
<line x1="256" y1="140" x2="256" y2="280" stroke="#D1D1D6" stroke-width="1.5" />
|
||||||
|
<line x1="188" y1="175" x2="324" y2="245" stroke="#D1D1D6" stroke-width="1" stroke-opacity="0.5" />
|
||||||
|
|
||||||
|
<!-- 品牌封箱胶带 -->
|
||||||
|
<path d="M220 158L120 210L256 280L356 228L220 158Z" fill="#007AFF" fill-opacity="0.15" />
|
||||||
|
<path d="M120 210V240L150 255V225L120 210Z" fill="#007AFF" fill-opacity="0.2" />
|
||||||
|
<path d="M392 210V240L362 225V195L392 210Z" fill="#007AFF" fill-opacity="0.2" />
|
||||||
|
|
||||||
|
<!-- 侧面物流标签 (校正透视,精准对齐) -->
|
||||||
|
<g transform="translate(290, 285)">
|
||||||
|
<!-- 标签白色底:使用校正后的斜率 -0.52 -->
|
||||||
|
<path d="M0 0 L40 -21 V34 L0 55 Z" fill="white" fill-opacity="0.95" />
|
||||||
|
<!-- 标签内部装饰线 -->
|
||||||
|
<path d="M8 5 L32 -8" stroke="#007AFF" stroke-width="3" stroke-opacity="0.3" />
|
||||||
|
<path d="M8 15 L30 3" stroke="#007AFF" stroke-width="2" stroke-opacity="0.2" />
|
||||||
|
<path d="M8 25 L25 16" stroke="#007AFF" stroke-width="2" stroke-opacity="0.2" />
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<!-- 底部细节 -->
|
||||||
|
<line x1="140" y1="330" x2="140" y2="350" stroke="#D1D1D6" stroke-width="2" stroke-linecap="round" />
|
||||||
|
</g>
|
||||||
|
|
||||||
|
<circle cx="160" cy="160" r="120" fill="white" fill-opacity="0.1" />
|
||||||
|
</svg>
|
||||||
|
After Width: | Height: | Size: 2.2 KiB |
3
src-tauri/Cargo.lock
generated
@@ -451,8 +451,10 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
|
|||||||
checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0"
|
checksum = "c673075a2e0e5f4a1dde27ce9dee1ea4558c7ffe648f576438a20ca1d2acc4b0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iana-time-zone",
|
"iana-time-zone",
|
||||||
|
"js-sys",
|
||||||
"num-traits",
|
"num-traits",
|
||||||
"serde",
|
"serde",
|
||||||
|
"wasm-bindgen",
|
||||||
"windows-link 0.2.1",
|
"windows-link 0.2.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -4620,6 +4622,7 @@ dependencies = [
|
|||||||
name = "win-softmgr"
|
name = "win-softmgr"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
|
"chrono",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
"serde_json",
|
||||||
"tauri",
|
"tauri",
|
||||||
|
|||||||
@@ -23,4 +23,5 @@ tauri-plugin-opener = "2"
|
|||||||
serde = { version = "1", features = ["derive"] }
|
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"
|
||||||
|
|
||||||
|
|||||||
|
Before Width: | Height: | Size: 3.4 KiB After Width: | Height: | Size: 7.7 KiB |
|
Before Width: | Height: | Size: 6.8 KiB After Width: | Height: | Size: 16 KiB |
|
Before Width: | Height: | Size: 974 B After Width: | Height: | Size: 1.5 KiB |
BIN
src-tauri/icons/64x64.png
Normal file
|
After Width: | Height: | Size: 3.5 KiB |
|
Before Width: | Height: | Size: 2.8 KiB After Width: | Height: | Size: 6.2 KiB |
|
Before Width: | Height: | Size: 3.8 KiB After Width: | Height: | Size: 8.5 KiB |
|
Before Width: | Height: | Size: 3.9 KiB After Width: | Height: | Size: 9.1 KiB |
|
Before Width: | Height: | Size: 7.6 KiB After Width: | Height: | Size: 18 KiB |
|
Before Width: | Height: | Size: 903 B After Width: | Height: | Size: 1.4 KiB |
|
Before Width: | Height: | Size: 8.4 KiB After Width: | Height: | Size: 20 KiB |
|
Before Width: | Height: | Size: 1.3 KiB After Width: | Height: | Size: 2.2 KiB |
|
Before Width: | Height: | Size: 2.0 KiB After Width: | Height: | Size: 3.8 KiB |
|
Before Width: | Height: | Size: 2.4 KiB After Width: | Height: | Size: 5.1 KiB |
|
Before Width: | Height: | Size: 1.5 KiB After Width: | Height: | Size: 2.5 KiB |
@@ -0,0 +1,5 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<adaptive-icon xmlns:android="http://schemas.android.com/apk/res/android">
|
||||||
|
<foreground android:drawable="@mipmap/ic_launcher_foreground"/>
|
||||||
|
<background android:drawable="@color/ic_launcher_background"/>
|
||||||
|
</adaptive-icon>
|
||||||
BIN
src-tauri/icons/android/mipmap-hdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 2.4 KiB |
BIN
src-tauri/icons/android/mipmap-hdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
src-tauri/icons/android/mipmap-hdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 2.2 KiB |
BIN
src-tauri/icons/android/mipmap-mdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 2.3 KiB |
BIN
src-tauri/icons/android/mipmap-mdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 6.3 KiB |
BIN
src-tauri/icons/android/mipmap-mdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 2.1 KiB |
BIN
src-tauri/icons/android/mipmap-xhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 5.5 KiB |
BIN
src-tauri/icons/android/mipmap-xhdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 14 KiB |
BIN
src-tauri/icons/android/mipmap-xhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 4.7 KiB |
BIN
src-tauri/icons/android/mipmap-xxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 8.8 KiB |
BIN
src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_foreground.png
Normal file
|
After Width: | Height: | Size: 22 KiB |
BIN
src-tauri/icons/android/mipmap-xxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher.png
Normal file
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 30 KiB |
BIN
src-tauri/icons/android/mipmap-xxxhdpi/ic_launcher_round.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
@@ -0,0 +1,4 @@
|
|||||||
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
|
<resources>
|
||||||
|
<color name="ic_launcher_background">#fff</color>
|
||||||
|
</resources>
|
||||||
|
Before Width: | Height: | Size: 85 KiB After Width: | Height: | Size: 29 KiB |
|
Before Width: | Height: | Size: 14 KiB After Width: | Height: | Size: 37 KiB |
BIN
src-tauri/icons/ios/AppIcon-20x20@1x.png
Normal file
|
After Width: | Height: | Size: 873 B |
BIN
src-tauri/icons/ios/AppIcon-20x20@2x-1.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src-tauri/icons/ios/AppIcon-20x20@2x.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src-tauri/icons/ios/AppIcon-20x20@3x.png
Normal file
|
After Width: | Height: | Size: 3.2 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@1x.png
Normal file
|
After Width: | Height: | Size: 1.4 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@2x-1.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@2x.png
Normal file
|
After Width: | Height: | Size: 3.1 KiB |
BIN
src-tauri/icons/ios/AppIcon-29x29@3x.png
Normal file
|
After Width: | Height: | Size: 4.9 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@1x.png
Normal file
|
After Width: | Height: | Size: 1.9 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@2x-1.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@2x.png
Normal file
|
After Width: | Height: | Size: 4.4 KiB |
BIN
src-tauri/icons/ios/AppIcon-40x40@3x.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
src-tauri/icons/ios/AppIcon-512@2x.png
Normal file
|
After Width: | Height: | Size: 55 KiB |
BIN
src-tauri/icons/ios/AppIcon-60x60@2x.png
Normal file
|
After Width: | Height: | Size: 7.0 KiB |
BIN
src-tauri/icons/ios/AppIcon-60x60@3x.png
Normal file
|
After Width: | Height: | Size: 11 KiB |
BIN
src-tauri/icons/ios/AppIcon-76x76@1x.png
Normal file
|
After Width: | Height: | Size: 4.3 KiB |
BIN
src-tauri/icons/ios/AppIcon-76x76@2x.png
Normal file
|
After Width: | Height: | Size: 9.3 KiB |
BIN
src-tauri/icons/ios/AppIcon-83.5x83.5@2x.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
@@ -12,6 +12,32 @@ struct AppState {
|
|||||||
install_tx: mpsc::Sender<String>,
|
install_tx: mpsc::Sender<String>,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Serialize)]
|
||||||
|
pub struct LogPayload {
|
||||||
|
pub timestamp: String,
|
||||||
|
pub command: String,
|
||||||
|
pub output: String,
|
||||||
|
pub status: String,
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn emit_log(handle: &AppHandle, command: &str, output: &str, status: &str) {
|
||||||
|
let now = chrono::Local::now().format("%H:%M:%S").to_string();
|
||||||
|
let _ = handle.emit("log-event", LogPayload {
|
||||||
|
timestamp: now,
|
||||||
|
command: command.to_string(),
|
||||||
|
output: output.to_string(),
|
||||||
|
status: status.to_string(),
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
async fn initialize_app(app: AppHandle) -> Result<bool, String> {
|
||||||
|
// 执行耗时的环境配置
|
||||||
|
tokio::task::spawn_blocking(move || {
|
||||||
|
ensure_winget_dependencies(&app).map(|_| true)
|
||||||
|
}).await.unwrap_or(Err("Initialization Task Panicked".to_string()))
|
||||||
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
fn get_essentials(app: AppHandle) -> Vec<Software> {
|
fn get_essentials(app: AppHandle) -> Vec<Software> {
|
||||||
let app_data_dir = app.path().app_data_dir().unwrap_or_default();
|
let app_data_dir = app.path().app_data_dir().unwrap_or_default();
|
||||||
@@ -28,12 +54,12 @@ fn get_essentials(app: AppHandle) -> Vec<Software> {
|
|||||||
description: Some("Microsoft PowerToys 是一组实用程序,供高级用户调整和简化其 Windows 10 和 11 体验。".to_string()),
|
description: Some("Microsoft PowerToys 是一组实用程序,供高级用户调整和简化其 Windows 10 和 11 体验。".to_string()),
|
||||||
version: None,
|
version: None,
|
||||||
available_version: None,
|
available_version: None,
|
||||||
icon_url: Some("https://raw.githubusercontent.com/microsoft/PowerToys/main/doc/images/icons/PowerToys icon/PNG/PowerToysAppList.targetsize-48.png".to_string()),
|
icon_url: Some("https://raw.githubusercontent.com/microsoft/PowerToys/master/doc/images/logo.png".to_string()),
|
||||||
status: "idle".to_string(),
|
status: "idle".to_string(),
|
||||||
progress: 0.0,
|
progress: 0.0,
|
||||||
},
|
},
|
||||||
Software {
|
Software {
|
||||||
id: "Google.Chrome.EXE".to_string(),
|
id: "Google.Chrome".to_string(),
|
||||||
name: "Google Chrome".to_string(),
|
name: "Google Chrome".to_string(),
|
||||||
description: Some("Google Chrome 是一款快速、安全且免费的浏览器。".to_string()),
|
description: Some("Google Chrome 是一款快速、安全且免费的浏览器。".to_string()),
|
||||||
version: None,
|
version: None,
|
||||||
@@ -52,13 +78,13 @@ fn get_essentials(app: AppHandle) -> Vec<Software> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn get_all_software() -> Vec<Software> {
|
async fn get_all_software(app: AppHandle) -> Vec<Software> {
|
||||||
tokio::task::spawn_blocking(move || list_all_software()).await.unwrap_or_default()
|
tokio::task::spawn_blocking(move || list_all_software(&app)).await.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
async fn get_updates() -> Vec<Software> {
|
async fn get_updates(app: AppHandle) -> Vec<Software> {
|
||||||
tokio::task::spawn_blocking(move || list_updates()).await.unwrap_or_default()
|
tokio::task::spawn_blocking(move || list_updates(&app)).await.unwrap_or_default()
|
||||||
}
|
}
|
||||||
|
|
||||||
#[tauri::command]
|
#[tauri::command]
|
||||||
@@ -66,6 +92,11 @@ async fn install_software(id: String, state: State<'_, AppState>) -> Result<(),
|
|||||||
state.install_tx.send(id).await.map_err(|e| e.to_string())
|
state.install_tx.send(id).await.map_err(|e| e.to_string())
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[tauri::command]
|
||||||
|
fn get_logs_history() -> Vec<LogPayload> {
|
||||||
|
vec![]
|
||||||
|
}
|
||||||
|
|
||||||
#[derive(Clone, Serialize)]
|
#[derive(Clone, Serialize)]
|
||||||
struct InstallProgress {
|
struct InstallProgress {
|
||||||
id: String,
|
id: String,
|
||||||
@@ -78,21 +109,11 @@ pub fn run() {
|
|||||||
.plugin(tauri_plugin_opener::init())
|
.plugin(tauri_plugin_opener::init())
|
||||||
.setup(move |app| {
|
.setup(move |app| {
|
||||||
let handle = app.handle().clone();
|
let handle = app.handle().clone();
|
||||||
|
|
||||||
// 确保依赖项已安装 (这是一个耗时的过程,建议在异步任务中运行)
|
|
||||||
tauri::async_runtime::spawn(async move {
|
|
||||||
let _ = tokio::task::spawn_blocking(|| {
|
|
||||||
let _ = ensure_winget_dependencies();
|
|
||||||
}).await;
|
|
||||||
});
|
|
||||||
|
|
||||||
// 在 setup 闭包中初始化,此时运行时已就绪
|
|
||||||
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 的逻辑,改为由前端指令触发
|
||||||
|
|
||||||
tauri::async_runtime::spawn(async move {
|
tauri::async_runtime::spawn(async move {
|
||||||
while let Some(id) = rx.recv().await {
|
while let Some(id) = rx.recv().await {
|
||||||
let _ = handle.emit("install-status", InstallProgress {
|
let _ = handle.emit("install-status", InstallProgress {
|
||||||
@@ -101,7 +122,10 @@ pub fn run() {
|
|||||||
progress: 0.5,
|
progress: 0.5,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
emit_log(&handle, &format!("winget install --id {}", id), "Starting installation...", "info");
|
||||||
|
|
||||||
let id_for_cmd = id.clone();
|
let id_for_cmd = id.clone();
|
||||||
|
let h = handle.clone();
|
||||||
let status_result = tokio::task::spawn_blocking(move || {
|
let status_result = tokio::task::spawn_blocking(move || {
|
||||||
let output = Command::new("winget")
|
let output = Command::new("winget")
|
||||||
.args([
|
.args([
|
||||||
@@ -113,8 +137,16 @@ pub fn run() {
|
|||||||
.output();
|
.output();
|
||||||
|
|
||||||
match output {
|
match output {
|
||||||
Ok(out) if out.status.success() => "success",
|
Ok(out) => {
|
||||||
_ => "error",
|
let msg = String::from_utf8_lossy(&out.stdout).to_string();
|
||||||
|
let err = String::from_utf8_lossy(&out.stderr).to_string();
|
||||||
|
emit_log(&h, &format!("Install result for {}", id_for_cmd), &format!("OUT: {}\nERR: {}", msg, err), if out.status.success() { "success" } else { "error" });
|
||||||
|
if out.status.success() { "success" } else { "error" }
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
emit_log(&h, &format!("Install error for {}", id_for_cmd), &e.to_string(), "error");
|
||||||
|
"error"
|
||||||
|
},
|
||||||
}
|
}
|
||||||
}).await.unwrap_or("error");
|
}).await.unwrap_or("error");
|
||||||
|
|
||||||
@@ -129,10 +161,12 @@ pub fn run() {
|
|||||||
Ok(())
|
Ok(())
|
||||||
})
|
})
|
||||||
.invoke_handler(tauri::generate_handler![
|
.invoke_handler(tauri::generate_handler![
|
||||||
|
initialize_app,
|
||||||
get_essentials,
|
get_essentials,
|
||||||
get_all_software,
|
get_all_software,
|
||||||
get_updates,
|
get_updates,
|
||||||
install_software
|
install_software,
|
||||||
|
get_logs_history
|
||||||
])
|
])
|
||||||
.run(tauri::generate_context!())
|
.run(tauri::generate_context!())
|
||||||
.expect("error while running tauri application");
|
.expect("error while running tauri application");
|
||||||
|
|||||||
@@ -1,6 +1,8 @@
|
|||||||
use serde::{Deserialize, Serialize};
|
use serde::{Deserialize, Serialize};
|
||||||
use std::process::Command;
|
use std::process::Command;
|
||||||
use std::os::windows::process::CommandExt;
|
use std::os::windows::process::CommandExt;
|
||||||
|
use tauri::AppHandle;
|
||||||
|
use crate::emit_log;
|
||||||
|
|
||||||
#[derive(Debug, Serialize, Deserialize, Clone)]
|
#[derive(Debug, Serialize, Deserialize, Clone)]
|
||||||
pub struct Software {
|
pub struct Software {
|
||||||
@@ -23,31 +25,79 @@ struct WingetPackage {
|
|||||||
pub available_versions: Option<Vec<String>>,
|
pub available_versions: Option<Vec<String>>,
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn ensure_winget_dependencies() -> Result<(), String> {
|
pub fn ensure_winget_dependencies(handle: &AppHandle) -> Result<(), String> {
|
||||||
// 确保执行权限和模块存在
|
emit_log(handle, "Check Environment", "Performing fast environment check...", "info");
|
||||||
|
|
||||||
|
// 优化后的脚本:先尝试极速检测,存在则直接退出
|
||||||
let setup_script = r#"
|
let setup_script = r#"
|
||||||
$ErrorActionPreference = 'SilentlyContinue'
|
$ErrorActionPreference = 'SilentlyContinue'
|
||||||
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser -Force
|
|
||||||
if (-not (Get-Module -ListAvailable Microsoft.WinGet.Client)) {
|
# 极速路径:如果模块已安装,直接输出 Success 并退出
|
||||||
Install-Module -Name Microsoft.WinGet.Client -Force -AllowClobber -Scope CurrentUser
|
if (Get-Module -ListAvailable Microsoft.WinGet.Client) {
|
||||||
|
Write-Output "ALREADY_READY"
|
||||||
|
exit 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
# 慢速路径:仅在模块缺失时执行完整初始化
|
||||||
|
Write-Output "CONFIGURING_ENV"
|
||||||
|
[Net.ServicePointManager]::SecurityProtocol = [Net.ServicePointManager]::SecurityProtocol -bor [Net.SecurityProtocolType]::Tls12
|
||||||
|
Import-Module PackageManagement -ErrorAction SilentlyContinue
|
||||||
|
|
||||||
|
if ($null -eq (Get-PackageProvider -Name NuGet -ErrorAction SilentlyContinue)) {
|
||||||
|
Install-PackageProvider -Name NuGet -MinimumVersion 2.8.5.201 -Force -Confirm:$false
|
||||||
|
}
|
||||||
|
|
||||||
|
Set-PSRepository -Name 'PSGallery' -InstallationPolicy Trusted
|
||||||
|
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
|
||||||
|
}
|
||||||
|
|
||||||
|
# 注意:此处不再执行 winget source update,因为它太慢了,移至后台或按需执行
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
let _ = Command::new("powershell")
|
let output = Command::new("powershell")
|
||||||
.args(["-NoProfile", "-Command", setup_script])
|
.args(["-NoProfile", "-Command", setup_script])
|
||||||
.creation_flags(0x08000000)
|
.creation_flags(0x08000000)
|
||||||
.status();
|
.output();
|
||||||
|
|
||||||
Ok(())
|
match output {
|
||||||
|
Ok(out) => {
|
||||||
|
let stdout = String::from_utf8_lossy(&out.stdout).to_string();
|
||||||
|
if stdout.contains("ALREADY_READY") {
|
||||||
|
emit_log(handle, "Environment Setup", "Fast check passed: System is ready.", "success");
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
// 验证安装结果
|
||||||
|
let check = Command::new("powershell")
|
||||||
|
.args(["-NoProfile", "-Command", "Get-Module -ListAvailable Microsoft.WinGet.Client"])
|
||||||
|
.creation_flags(0x08000000)
|
||||||
|
.output();
|
||||||
|
|
||||||
|
if check.map(|o| !o.stdout.is_empty()).unwrap_or(false) {
|
||||||
|
emit_log(handle, "Environment Setup", "Full configuration successful.", "success");
|
||||||
|
Ok(())
|
||||||
|
} else {
|
||||||
|
let err = String::from_utf8_lossy(&out.stderr).to_string();
|
||||||
|
emit_log(handle, "Environment Setup Error", &format!("STDOUT: {}\nSTDERR: {}", stdout, err), "error");
|
||||||
|
Err("Setup failed".to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
emit_log(handle, "Environment Setup Fatal", &e.to_string(), "error");
|
||||||
|
Err(e.to_string())
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_all_software() -> Vec<Software> {
|
pub fn list_all_software(handle: &AppHandle) -> Vec<Software> {
|
||||||
// 使用更健壮的脚本获取 JSON
|
|
||||||
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
|
||||||
$pkgs = Get-WinGetPackage
|
$pkgs = Get-WinGetPackage -ErrorAction SilentlyContinue
|
||||||
if ($pkgs) {
|
if ($pkgs) {
|
||||||
$pkgs | ForEach-Object {
|
$pkgs | ForEach-Object {
|
||||||
[PSCustomObject]@{
|
[PSCustomObject]@{
|
||||||
@@ -62,15 +112,19 @@ pub fn list_all_software() -> Vec<Software> {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
execute_powershell(script)
|
execute_powershell(handle, "Get All Software", script)
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn list_updates() -> Vec<Software> {
|
pub fn list_updates(handle: &AppHandle) -> Vec<Software> {
|
||||||
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
|
||||||
$pkgs = Get-WinGetPackage | Where-Object { $_.IsUpdateAvailable }
|
|
||||||
|
# 在检查更新前,尝试静默更新源(可选,为了准确性)
|
||||||
|
# winget source update --accept-source-agreements | Out-Null
|
||||||
|
|
||||||
|
$pkgs = Get-WinGetPackage -ErrorAction SilentlyContinue | Where-Object { $_.IsUpdateAvailable }
|
||||||
if ($pkgs) {
|
if ($pkgs) {
|
||||||
$pkgs | ForEach-Object {
|
$pkgs | ForEach-Object {
|
||||||
[PSCustomObject]@{
|
[PSCustomObject]@{
|
||||||
@@ -85,10 +139,12 @@ pub fn list_updates() -> Vec<Software> {
|
|||||||
}
|
}
|
||||||
"#;
|
"#;
|
||||||
|
|
||||||
execute_powershell(script)
|
execute_powershell(handle, "Get Updates", script)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn execute_powershell(script: &str) -> Vec<Software> {
|
fn execute_powershell(handle: &AppHandle, cmd_name: &str, script: &str) -> Vec<Software> {
|
||||||
|
emit_log(handle, cmd_name, "Executing PowerShell script...", "info");
|
||||||
|
|
||||||
let output = Command::new("powershell")
|
let output = Command::new("powershell")
|
||||||
.args(["-NoProfile", "-Command", script])
|
.args(["-NoProfile", "-Command", script])
|
||||||
.creation_flags(0x08000000)
|
.creation_flags(0x08000000)
|
||||||
@@ -97,29 +153,36 @@ fn execute_powershell(script: &str) -> Vec<Software> {
|
|||||||
match output {
|
match output {
|
||||||
Ok(out) => {
|
Ok(out) => {
|
||||||
let stdout = String::from_utf8_lossy(&out.stdout);
|
let stdout = String::from_utf8_lossy(&out.stdout);
|
||||||
// 移除可能存在的 UTF-8 BOM
|
let stderr = String::from_utf8_lossy(&out.stderr);
|
||||||
let clean_json = stdout.trim_start_matches('\u{feff}').trim();
|
let clean_json = stdout.trim_start_matches('\u{feff}').trim();
|
||||||
parse_json_output(clean_json.to_string())
|
|
||||||
|
if !out.status.success() && !stderr.is_empty() {
|
||||||
|
emit_log(handle, &format!("{} stderr", cmd_name), &stderr, "error");
|
||||||
|
}
|
||||||
|
|
||||||
|
if clean_json.is_empty() || clean_json == "[]" {
|
||||||
|
emit_log(handle, cmd_name, "No data returned.", "info");
|
||||||
|
return vec![];
|
||||||
|
}
|
||||||
|
|
||||||
|
let result = parse_json_output(clean_json.to_string());
|
||||||
|
emit_log(handle, cmd_name, &format!("Success: found {} items", result.len()), "success");
|
||||||
|
result
|
||||||
|
},
|
||||||
|
Err(e) => {
|
||||||
|
emit_log(handle, cmd_name, &format!("Execution error: {}", e), "error");
|
||||||
|
vec![]
|
||||||
},
|
},
|
||||||
Err(_) => vec![],
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn parse_json_output(json_str: String) -> Vec<Software> {
|
fn parse_json_output(json_str: String) -> Vec<Software> {
|
||||||
if json_str.is_empty() || json_str == "[]" {
|
|
||||||
return vec![];
|
|
||||||
}
|
|
||||||
|
|
||||||
// 尝试解析数组
|
|
||||||
if let Ok(packages) = serde_json::from_str::<Vec<WingetPackage>>(&json_str) {
|
if let Ok(packages) = serde_json::from_str::<Vec<WingetPackage>>(&json_str) {
|
||||||
return packages.into_iter().map(map_package).collect();
|
return packages.into_iter().map(map_package).collect();
|
||||||
}
|
}
|
||||||
|
|
||||||
// 尝试解析单个对象
|
|
||||||
if let Ok(package) = serde_json::from_str::<WingetPackage>(&json_str) {
|
if let Ok(package) = serde_json::from_str::<WingetPackage>(&json_str) {
|
||||||
return vec![map_package(package)];
|
return vec![map_package(package)];
|
||||||
}
|
}
|
||||||
|
|
||||||
vec![]
|
vec![]
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
56
src/App.vue
@@ -1,18 +1,36 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="app-container">
|
<div class="app-container">
|
||||||
<Sidebar />
|
<!-- 启动屏专属过渡 -->
|
||||||
<div class="main-content">
|
<transition name="layout-fade">
|
||||||
<router-view v-slot="{ Component }">
|
<SplashScreen v-if="!store.isInitialized" :status-text="store.initStatus" />
|
||||||
<transition name="fade" mode="out-in">
|
</transition>
|
||||||
<component :is="Component" />
|
|
||||||
</transition>
|
<template v-if="store.isInitialized">
|
||||||
</router-view>
|
<Sidebar />
|
||||||
</div>
|
<div class="main-content">
|
||||||
|
<router-view v-slot="{ Component }">
|
||||||
|
<!-- 页面切换专属过渡:极简、快速 -->
|
||||||
|
<transition name="page-fade" mode="out-in">
|
||||||
|
<component :is="Component" />
|
||||||
|
</transition>
|
||||||
|
</router-view>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
<script setup lang="ts">
|
<script setup lang="ts">
|
||||||
import Sidebar from './components/Sidebar.vue'
|
import Sidebar from './components/Sidebar.vue'
|
||||||
|
import SplashScreen from './components/SplashScreen.vue'
|
||||||
|
import { useSoftwareStore } from './store/software'
|
||||||
|
import { onMounted } from 'vue'
|
||||||
|
|
||||||
|
const store = useSoftwareStore()
|
||||||
|
|
||||||
|
onMounted(async () => {
|
||||||
|
store.initListener()
|
||||||
|
await store.initializeApp()
|
||||||
|
})
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<style>
|
<style>
|
||||||
@@ -58,19 +76,25 @@ body {
|
|||||||
position: relative;
|
position: relative;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* 页面切换动画 */
|
/* 1. 布局级别过渡 (Splash -> App): 优雅、大气 */
|
||||||
.fade-enter-active,
|
.layout-fade-enter-active,
|
||||||
.fade-leave-active {
|
.layout-fade-leave-active {
|
||||||
transition: opacity 0.2s ease, transform 0.2s ease;
|
transition: opacity 0.6s cubic-bezier(0.4, 0, 0.2, 1), transform 0.6s cubic-bezier(0.4, 0, 0.2, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
.fade-enter-from {
|
.layout-fade-leave-to {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateY(10px);
|
transform: scale(1.05);
|
||||||
}
|
}
|
||||||
|
|
||||||
.fade-leave-to {
|
/* 2. 页面级别过渡 (Essentials <-> Updates): 快速、响应灵敏 */
|
||||||
|
.page-fade-enter-active,
|
||||||
|
.page-fade-leave-active {
|
||||||
|
transition: opacity 0.15s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.page-fade-enter-from,
|
||||||
|
.page-fade-leave-to {
|
||||||
opacity: 0;
|
opacity: 0;
|
||||||
transform: translateY(-10px);
|
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
@@ -5,17 +5,48 @@
|
|||||||
</div>
|
</div>
|
||||||
<nav class="sidebar-nav">
|
<nav class="sidebar-nav">
|
||||||
<router-link to="/essentials" class="nav-item">
|
<router-link to="/essentials" class="nav-item">
|
||||||
<span class="nav-icon">✨</span>
|
<span class="nav-icon">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M12 3l1.912 5.885h6.19l-5.007 3.638 1.912 5.885L12 14.77l-5.007 3.638 1.912-5.885-5.007-3.638h6.19z"></path>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
装机必备
|
装机必备
|
||||||
</router-link>
|
</router-link>
|
||||||
<router-link to="/updates" class="nav-item">
|
<router-link to="/updates" class="nav-item">
|
||||||
<span class="nav-icon">🔄</span>
|
<span class="nav-icon">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M21 2v6h-6"></path>
|
||||||
|
<path d="M3 12a9 9 0 0 1 15-6.7L21 8"></path>
|
||||||
|
<path d="M3 22v-6h6"></path>
|
||||||
|
<path d="M21 12a9 9 0 0 1-15 6.7L3 16"></path>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
软件更新
|
软件更新
|
||||||
</router-link>
|
</router-link>
|
||||||
<router-link to="/all" class="nav-item">
|
<router-link to="/all" class="nav-item">
|
||||||
<span class="nav-icon">📦</span>
|
<span class="nav-icon">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M21 8a2 2 0 0 0-1-1.73l-7-4a2 2 0 0 0-2 0l-7 4A2 2 0 0 0 3 8v8a2 2 0 0 0 1 1.73l7 4a2 2 0 0 0 2 0l7-4A2 2 0 0 0 21 16Z"></path>
|
||||||
|
<path d="m3.3 7 8.7 5 8.7-5"></path>
|
||||||
|
<path d="M12 22V12"></path>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
全部软件
|
全部软件
|
||||||
</router-link>
|
</router-link>
|
||||||
|
|
||||||
|
<!-- 底部日志选项 -->
|
||||||
|
<router-link to="/logs" class="nav-item nav-logs">
|
||||||
|
<span class="nav-icon">
|
||||||
|
<svg width="18" height="18" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2" stroke-linecap="round" stroke-linejoin="round">
|
||||||
|
<path d="M14 2H6a2 2 0 0 0-2 2v16a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2V8z"></path>
|
||||||
|
<polyline points="14 2 14 8 20 8"></polyline>
|
||||||
|
<line x1="16" y1="13" x2="8" y2="13"></line>
|
||||||
|
<line x1="16" y1="17" x2="8" y2="17"></line>
|
||||||
|
<polyline points="10 9 9 9 8 9"></polyline>
|
||||||
|
</svg>
|
||||||
|
</span>
|
||||||
|
运行日志
|
||||||
|
</router-link>
|
||||||
</nav>
|
</nav>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
@@ -35,12 +66,14 @@
|
|||||||
font-weight: 700;
|
font-weight: 700;
|
||||||
margin-bottom: 40px;
|
margin-bottom: 40px;
|
||||||
padding-left: 20px;
|
padding-left: 20px;
|
||||||
|
color: var(--text-main);
|
||||||
}
|
}
|
||||||
|
|
||||||
.sidebar-nav {
|
.sidebar-nav {
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
gap: 8px;
|
gap: 8px;
|
||||||
|
flex: 1; /* 撑满空间 */
|
||||||
}
|
}
|
||||||
|
|
||||||
.nav-item {
|
.nav-item {
|
||||||
@@ -68,6 +101,13 @@
|
|||||||
|
|
||||||
.nav-icon {
|
.nav-icon {
|
||||||
margin-right: 12px;
|
margin-right: 12px;
|
||||||
font-size: 18px;
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
}
|
||||||
|
|
||||||
|
.nav-logs {
|
||||||
|
margin-top: auto; /* 将日志推到底部 */
|
||||||
|
margin-bottom: 20px;
|
||||||
}
|
}
|
||||||
</style>
|
</style>
|
||||||
|
|||||||
107
src/components/SplashScreen.vue
Normal file
@@ -0,0 +1,107 @@
|
|||||||
|
<template>
|
||||||
|
<div class="splash-screen">
|
||||||
|
<div class="content">
|
||||||
|
<div class="app-logo">
|
||||||
|
<!-- 这里使用我们设计的图标 SVG 内容的简化版 -->
|
||||||
|
<svg width="120" height="120" viewBox="0 0 512 512" fill="none">
|
||||||
|
<rect x="0" y="0" width="512" height="512" rx="128" fill="#007AFF" />
|
||||||
|
<path d="M256 140L120 210L256 280L392 210L256 140Z" fill="white" />
|
||||||
|
<path d="M120 210V340L256 410V280L120 210Z" fill="white" fill-opacity="0.85" />
|
||||||
|
<path d="M392 210V340L256 410V280L392 210Z" fill="white" fill-opacity="0.7" />
|
||||||
|
</svg>
|
||||||
|
</div>
|
||||||
|
<h1 class="app-name">Windows 软件管理</h1>
|
||||||
|
|
||||||
|
<div class="status-container">
|
||||||
|
<div class="spinner"></div>
|
||||||
|
<p class="status-text">{{ statusText }}</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div class="footer">
|
||||||
|
<p>Created with Gemini</p>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
defineProps<{
|
||||||
|
statusText: string
|
||||||
|
}>();
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.splash-screen {
|
||||||
|
position: fixed;
|
||||||
|
top: 0;
|
||||||
|
left: 0;
|
||||||
|
width: 100vw;
|
||||||
|
height: 100vh;
|
||||||
|
background-color: #FBFBFD;
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
z-index: 9999;
|
||||||
|
}
|
||||||
|
|
||||||
|
.content {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
animation: fadeIn 0.8s ease-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-logo {
|
||||||
|
filter: drop-shadow(0 20px 40px rgba(0, 122, 255, 0.2));
|
||||||
|
margin-bottom: 24px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.app-name {
|
||||||
|
font-size: 28px;
|
||||||
|
font-weight: 800;
|
||||||
|
letter-spacing: -0.5px;
|
||||||
|
color: #1D1D1F;
|
||||||
|
margin-bottom: 48px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-container {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
gap: 16px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.spinner {
|
||||||
|
width: 24px;
|
||||||
|
height: 24px;
|
||||||
|
border: 3px solid rgba(0, 122, 255, 0.1);
|
||||||
|
border-top-color: #007AFF;
|
||||||
|
border-radius: 50%;
|
||||||
|
animation: spin 1s linear infinite;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-text {
|
||||||
|
font-size: 14px;
|
||||||
|
font-weight: 500;
|
||||||
|
color: #86868B;
|
||||||
|
}
|
||||||
|
|
||||||
|
.footer {
|
||||||
|
position: absolute;
|
||||||
|
bottom: 40px;
|
||||||
|
font-size: 12px;
|
||||||
|
color: #C5C5C7;
|
||||||
|
letter-spacing: 0.5px;
|
||||||
|
text-transform: uppercase;
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes spin {
|
||||||
|
to { transform: rotate(360deg); }
|
||||||
|
}
|
||||||
|
|
||||||
|
@keyframes fadeIn {
|
||||||
|
from { opacity: 0; transform: translateY(10px); }
|
||||||
|
to { opacity: 1; transform: translateY(0); }
|
||||||
|
}
|
||||||
|
</style>
|
||||||
@@ -18,6 +18,10 @@ const router = createRouter({
|
|||||||
{
|
{
|
||||||
path: '/all',
|
path: '/all',
|
||||||
component: () => import('../views/AllSoftware.vue')
|
component: () => import('../views/AllSoftware.vue')
|
||||||
|
},
|
||||||
|
{
|
||||||
|
path: '/logs',
|
||||||
|
component: () => import('../views/Logs.vue')
|
||||||
}
|
}
|
||||||
]
|
]
|
||||||
})
|
})
|
||||||
|
|||||||
@@ -4,6 +4,13 @@ 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 {
|
||||||
|
timestamp: string;
|
||||||
|
command: string;
|
||||||
|
output: string;
|
||||||
|
status: 'info' | 'success' | 'error';
|
||||||
|
}
|
||||||
|
|
||||||
export const useSoftwareStore = defineStore('software', {
|
export const useSoftwareStore = defineStore('software', {
|
||||||
state: () => ({
|
state: () => ({
|
||||||
essentials: [] as any[],
|
essentials: [] as any[],
|
||||||
@@ -11,7 +18,10 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
allSoftware: [] as any[],
|
allSoftware: [] as any[],
|
||||||
selectedEssentialIds: [] as string[],
|
selectedEssentialIds: [] as string[],
|
||||||
selectedUpdateIds: [] as string[],
|
selectedUpdateIds: [] as string[],
|
||||||
|
logs: [] as LogEntry[],
|
||||||
loading: false,
|
loading: false,
|
||||||
|
isInitialized: false,
|
||||||
|
initStatus: '正在检查系统环境...',
|
||||||
lastFetched: 0
|
lastFetched: 0
|
||||||
}),
|
}),
|
||||||
getters: {
|
getters: {
|
||||||
@@ -39,15 +49,25 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
sortedAllSoftware: (state) => [...state.allSoftware].sort(sortByName)
|
sortedAllSoftware: (state) => [...state.allSoftware].sort(sortByName)
|
||||||
},
|
},
|
||||||
actions: {
|
actions: {
|
||||||
// 通用的勾选切换逻辑
|
async initializeApp() {
|
||||||
|
if (this.isInitialized) return;
|
||||||
|
|
||||||
|
this.initStatus = '正在同步 Winget 模块...';
|
||||||
|
try {
|
||||||
|
await invoke('initialize_app');
|
||||||
|
this.isInitialized = true;
|
||||||
|
} catch (err) {
|
||||||
|
this.initStatus = '环境配置失败,请检查运行日志';
|
||||||
|
console.error('Init failed:', err);
|
||||||
|
// 即使失败也允许进入,让用户看日志
|
||||||
|
setTimeout(() => { this.isInitialized = true; }, 2000);
|
||||||
|
}
|
||||||
|
},
|
||||||
toggleSelection(id: string, type: 'essential' | 'update') {
|
toggleSelection(id: string, type: 'essential' | 'update') {
|
||||||
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) {
|
if (index === -1) list.push(id);
|
||||||
list.push(id);
|
else list.splice(index, 1);
|
||||||
} else {
|
|
||||||
list.splice(index, 1);
|
|
||||||
}
|
|
||||||
},
|
},
|
||||||
selectAll(type: 'essential' | 'update') {
|
selectAll(type: 'essential' | 'update') {
|
||||||
if (type === 'essential') {
|
if (type === 'essential') {
|
||||||
@@ -79,7 +99,6 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
try {
|
try {
|
||||||
const res = await invoke('get_updates')
|
const res = await invoke('get_updates')
|
||||||
this.updates = res as any[]
|
this.updates = res as any[]
|
||||||
// 刷新数据后,如果没选过,默认全选
|
|
||||||
if (this.selectedUpdateIds.length === 0) this.selectAll('update');
|
if (this.selectedUpdateIds.length === 0) this.selectAll('update');
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false
|
this.loading = false
|
||||||
@@ -115,7 +134,6 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
this.allSoftware = all as any[];
|
this.allSoftware = all as any[];
|
||||||
this.updates = updates as any[];
|
this.updates = updates as any[];
|
||||||
this.lastFetched = Date.now();
|
this.lastFetched = Date.now();
|
||||||
// 如果没选过,默认全选
|
|
||||||
if (this.selectedEssentialIds.length === 0) this.selectAll('essential');
|
if (this.selectedEssentialIds.length === 0) this.selectAll('essential');
|
||||||
} finally {
|
} finally {
|
||||||
this.loading = false;
|
this.loading = false;
|
||||||
@@ -144,11 +162,15 @@ export const useSoftwareStore = defineStore('software', {
|
|||||||
}
|
}
|
||||||
if (status === 'success') {
|
if (status === 'success') {
|
||||||
this.lastFetched = 0;
|
this.lastFetched = 0;
|
||||||
// 安装成功后从选择列表中移除
|
|
||||||
this.selectedEssentialIds = this.selectedEssentialIds.filter(i => i !== id);
|
this.selectedEssentialIds = this.selectedEssentialIds.filter(i => i !== id);
|
||||||
this.selectedUpdateIds = this.selectedUpdateIds.filter(i => i !== id);
|
this.selectedUpdateIds = this.selectedUpdateIds.filter(i => i !== id);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
listen('log-event', (event: any) => {
|
||||||
|
this.logs.unshift(event.payload as LogEntry);
|
||||||
|
if (this.logs.length > 200) this.logs.pop();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|||||||
183
src/views/Logs.vue
Normal file
@@ -0,0 +1,183 @@
|
|||||||
|
<template>
|
||||||
|
<main class="content">
|
||||||
|
<header class="content-header">
|
||||||
|
<div class="header-left">
|
||||||
|
<h1>运行日志</h1>
|
||||||
|
<!-- <p class="count">记录应用最近执行的命令和结果</p> -->
|
||||||
|
</div>
|
||||||
|
<div class="header-actions">
|
||||||
|
<button @click="store.logs = []" class="secondary-btn action-btn">
|
||||||
|
清空日志
|
||||||
|
</button>
|
||||||
|
</div>
|
||||||
|
</header>
|
||||||
|
|
||||||
|
<div v-if="store.logs.length === 0" class="empty-state">
|
||||||
|
<span class="empty-icon">📝</span>
|
||||||
|
<p>暂无操作记录</p>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div v-else class="log-list">
|
||||||
|
<div v-for="(log, index) in store.logs" :key="index" class="log-item" :class="log.status">
|
||||||
|
<div class="log-header">
|
||||||
|
<span class="timestamp">[{{ log.timestamp }}]</span>
|
||||||
|
<span class="command">{{ log.command }}</span>
|
||||||
|
<span class="status-badge">{{ log.status.toUpperCase() }}</span>
|
||||||
|
</div>
|
||||||
|
<pre class="log-output">{{ log.output }}</pre>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</main>
|
||||||
|
</template>
|
||||||
|
|
||||||
|
<script setup lang="ts">
|
||||||
|
import { useSoftwareStore } from '../store/software';
|
||||||
|
import { onMounted } from 'vue';
|
||||||
|
|
||||||
|
const store = useSoftwareStore();
|
||||||
|
|
||||||
|
onMounted(() => {
|
||||||
|
store.initListener();
|
||||||
|
});
|
||||||
|
</script>
|
||||||
|
|
||||||
|
<style scoped>
|
||||||
|
.content {
|
||||||
|
flex: 1;
|
||||||
|
padding: 40px 60px;
|
||||||
|
overflow-y: auto;
|
||||||
|
background-color: var(--bg-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.content-header {
|
||||||
|
display: flex;
|
||||||
|
justify-content: space-between;
|
||||||
|
align-items: flex-end;
|
||||||
|
margin-bottom: 30px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.header-left h1 {
|
||||||
|
font-size: 32px;
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text-main);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* .header-left .count {
|
||||||
|
font-size: 14px;
|
||||||
|
color: var(--text-sec);
|
||||||
|
margin-top: 4px;
|
||||||
|
} */
|
||||||
|
|
||||||
|
.header-actions {
|
||||||
|
display: flex;
|
||||||
|
gap: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn {
|
||||||
|
padding: 8px 16px;
|
||||||
|
border-radius: 10px;
|
||||||
|
font-weight: 600;
|
||||||
|
font-size: 13px;
|
||||||
|
cursor: pointer;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
border: 1px solid var(--border-color);
|
||||||
|
background-color: white;
|
||||||
|
color: var(--text-main);
|
||||||
|
}
|
||||||
|
|
||||||
|
.action-btn:hover {
|
||||||
|
background-color: #FFF5F5;
|
||||||
|
border-color: #FF3B30;
|
||||||
|
color: #FF3B30;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-list {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
gap: 16px;
|
||||||
|
padding-bottom: 40px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-item {
|
||||||
|
background: white;
|
||||||
|
border-radius: 16px;
|
||||||
|
padding: 16px;
|
||||||
|
box-shadow: var(--card-shadow);
|
||||||
|
border: 1px solid transparent;
|
||||||
|
transition: all 0.2s ease;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-item.error {
|
||||||
|
border-left: 4px solid #FF3B30;
|
||||||
|
background-color: #FFF9F9;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-item.success {
|
||||||
|
border-left: 4px solid #34C759;
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-item.info {
|
||||||
|
border-left: 4px solid var(--primary-color);
|
||||||
|
}
|
||||||
|
|
||||||
|
.log-header {
|
||||||
|
display: flex;
|
||||||
|
align-items: center;
|
||||||
|
gap: 12px;
|
||||||
|
margin-bottom: 12px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.timestamp {
|
||||||
|
font-family: monospace;
|
||||||
|
color: var(--text-sec);
|
||||||
|
font-size: 13px;
|
||||||
|
}
|
||||||
|
|
||||||
|
.command {
|
||||||
|
font-weight: 700;
|
||||||
|
color: var(--text-main);
|
||||||
|
font-size: 14px;
|
||||||
|
flex: 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
.status-badge {
|
||||||
|
font-size: 10px;
|
||||||
|
font-weight: 800;
|
||||||
|
padding: 2px 8px;
|
||||||
|
border-radius: 6px;
|
||||||
|
background: var(--bg-light);
|
||||||
|
}
|
||||||
|
|
||||||
|
.error .status-badge { color: #FF3B30; background: #FFE5E5; }
|
||||||
|
.success .status-badge { color: #34C759; background: #E5F9E5; }
|
||||||
|
.info .status-badge { color: var(--primary-color); background: #E5F0FF; }
|
||||||
|
|
||||||
|
.log-output {
|
||||||
|
margin: 0;
|
||||||
|
padding: 12px;
|
||||||
|
background: #1D1D1F;
|
||||||
|
color: #F5F5F7;
|
||||||
|
border-radius: 8px;
|
||||||
|
font-family: 'Cascadia Code', 'Fira Code', monospace;
|
||||||
|
font-size: 12px;
|
||||||
|
line-height: 1.5;
|
||||||
|
overflow-x: auto;
|
||||||
|
white-space: pre-wrap;
|
||||||
|
max-height: 200px;
|
||||||
|
overflow-y: auto;
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-state {
|
||||||
|
display: flex;
|
||||||
|
flex-direction: column;
|
||||||
|
align-items: center;
|
||||||
|
justify-content: center;
|
||||||
|
height: 300px;
|
||||||
|
color: var(--text-sec);
|
||||||
|
}
|
||||||
|
|
||||||
|
.empty-icon {
|
||||||
|
font-size: 48px;
|
||||||
|
margin-bottom: 16px;
|
||||||
|
}
|
||||||
|
</style>
|
||||||