86 lines
2.6 KiB
Rust
86 lines
2.6 KiB
Rust
use tauri::AppHandle;
|
|
|
|
use crate::domain::models::{DashboardSnapshot, EssentialsStatusItem, UpdateCandidate};
|
|
use crate::providers::winget_client;
|
|
use crate::services::{essentials_service, reconcile_service};
|
|
use crate::services::task_event_service::emit_task_event;
|
|
|
|
pub async fn initialize_app(app: AppHandle) -> Result<bool, String> {
|
|
emit_task_event(
|
|
&app,
|
|
"env-check",
|
|
"env-check",
|
|
"initialize_app",
|
|
"running",
|
|
"checking_environment",
|
|
0.0,
|
|
None,
|
|
Some("Checking WinGet environment".to_string()),
|
|
None,
|
|
);
|
|
let app_clone = app.clone();
|
|
let result = tokio::task::spawn_blocking(move || winget_client::ensure_environment_ready(&app_clone).map(|_| true))
|
|
.await
|
|
.unwrap_or(Err("Initialization Task Panicked".to_string()));
|
|
|
|
match &result {
|
|
Ok(_) => emit_task_event(
|
|
&app,
|
|
"env-check",
|
|
"env-check",
|
|
"initialize_app",
|
|
"completed",
|
|
"ready",
|
|
1.0,
|
|
None,
|
|
Some("WinGet environment ready".to_string()),
|
|
None,
|
|
),
|
|
Err(err) => emit_task_event(
|
|
&app,
|
|
"env-check",
|
|
"env-check",
|
|
"initialize_app",
|
|
"failed",
|
|
"error",
|
|
1.0,
|
|
None,
|
|
Some(err.clone()),
|
|
None,
|
|
),
|
|
}
|
|
|
|
result
|
|
}
|
|
|
|
pub async fn get_software_icon(app: AppHandle, id: String, name: String) -> Option<String> {
|
|
tokio::task::spawn_blocking(move || winget_client::resolve_icon(&app, &id, &name))
|
|
.await
|
|
.unwrap_or(None)
|
|
}
|
|
|
|
pub async fn get_dashboard_snapshot(app: AppHandle) -> DashboardSnapshot {
|
|
let repo = essentials_service::get_essentials(&app);
|
|
let app_for_installed = app.clone();
|
|
let app_for_updates = app.clone();
|
|
|
|
let installed_handle =
|
|
tokio::task::spawn_blocking(move || winget_client::list_installed_packages(&app_for_installed));
|
|
let updates_handle =
|
|
tokio::task::spawn_blocking(move || winget_client::list_upgrade_candidates(&app_for_updates));
|
|
|
|
let installed_software = installed_handle.await.unwrap_or_default();
|
|
let updates = updates_handle.await.unwrap_or_default();
|
|
|
|
reconcile_service::build_dashboard_snapshot(repo, installed_software, updates)
|
|
}
|
|
|
|
pub async fn get_essentials_status(app: AppHandle) -> (String, Vec<EssentialsStatusItem>) {
|
|
let snapshot = get_dashboard_snapshot(app).await;
|
|
(snapshot.essentials_version, snapshot.essentials)
|
|
}
|
|
|
|
pub async fn get_update_candidates(app: AppHandle) -> Vec<UpdateCandidate> {
|
|
get_dashboard_snapshot(app).await.updates
|
|
}
|