add splashscreen
This commit is contained in:
@@ -17,7 +17,7 @@ pub struct LogPayload {
|
||||
pub timestamp: String,
|
||||
pub command: String,
|
||||
pub output: String,
|
||||
pub status: String, // "info", "success", "error"
|
||||
pub status: String,
|
||||
}
|
||||
|
||||
pub fn emit_log(handle: &AppHandle, command: &str, output: &str, status: &str) {
|
||||
@@ -30,6 +30,14 @@ pub fn emit_log(handle: &AppHandle, command: &str, output: &str, status: &str) {
|
||||
});
|
||||
}
|
||||
|
||||
#[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]
|
||||
fn get_essentials(app: AppHandle) -> Vec<Software> {
|
||||
let app_data_dir = app.path().app_data_dir().unwrap_or_default();
|
||||
@@ -86,7 +94,6 @@ async fn install_software(id: String, state: State<'_, AppState>) -> Result<(),
|
||||
|
||||
#[tauri::command]
|
||||
fn get_logs_history() -> Vec<LogPayload> {
|
||||
// 暂时返回空,后续可以考虑存储
|
||||
vec![]
|
||||
}
|
||||
|
||||
@@ -105,15 +112,8 @@ pub fn run() {
|
||||
let (tx, mut rx) = mpsc::channel::<String>(100);
|
||||
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;
|
||||
});
|
||||
// 移除了在 setup 中直接执行异步 init 的逻辑,改为由前端指令触发
|
||||
|
||||
// 安装队列
|
||||
tauri::async_runtime::spawn(async move {
|
||||
while let Some(id) = rx.recv().await {
|
||||
let _ = handle.emit("install-status", InstallProgress {
|
||||
@@ -161,6 +161,7 @@ pub fn run() {
|
||||
Ok(())
|
||||
})
|
||||
.invoke_handler(tauri::generate_handler![
|
||||
initialize_app,
|
||||
get_essentials,
|
||||
get_all_software,
|
||||
get_updates,
|
||||
|
||||
Reference in New Issue
Block a user