refactor 2
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
use tauri::AppHandle;
|
||||
|
||||
use crate::domain::models::{DashboardSnapshot, EssentialsStatusItem, UpdateCandidate};
|
||||
use crate::providers::winget_client;
|
||||
use crate::services::{essentials_service, reconcile_service};
|
||||
use crate::winget::Software;
|
||||
|
||||
pub async fn initialize_app(app: AppHandle) -> Result<bool, String> {
|
||||
@@ -33,3 +35,28 @@ pub async fn get_software_icon(app: AppHandle, id: String, name: String) -> Opti
|
||||
.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
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user