feat: start checks

This commit is contained in:
2025-03-16 17:55:38 +00:00
parent 08d6a2a2fe
commit 8d55e92fc9
26 changed files with 456 additions and 211 deletions

View File

@ -5,12 +5,50 @@ use tokio::fs;
use tauri::{AppHandle, Manager, State};
use crate::model::misc::Game;
use crate::pkg::{Package, PkgKey};
use crate::pkg_store::InstallResult;
use crate::pkg_store::{InstallResult, PackageStore};
use crate::profiles::ongeki::OngekiProfile;
use crate::profiles::{self, AnyProfile, Profile, ProfileMeta, ProfilePaths};
use crate::appdata::AppData;
use crate::model::misc::StartCheckError;
use crate::util;
#[tauri::command]
pub async fn start_check(state: State<'_, Mutex<AppData>>) -> Result<Vec<StartCheckError>, String> {
log::debug!("invoke: start_check");
let appd = state.lock().await;
let prf = appd.profile.as_ref().ok_or_else(|| format!("No profile to check"))?;
let pkgs = appd.pkgs.get_all();
let mut res = Vec::new();
for key in prf.mod_pkgs() {
if let Some(pkg) = pkgs.get(key) {
if let Some(loc) = &pkg.loc {
for dep in &loc.dependencies {
if !prf.mod_pkgs().contains(dep) {
res.push(StartCheckError::MissingDependency(key.clone(), dep.clone()));
}
}
} else {
res.push(StartCheckError::MissingLocalPackage(key.clone()));
}
} else {
res.push(StartCheckError::MissingRemotePackage(key.clone()));
}
}
for key in prf.special_pkgs() {
log::debug!("special: {}", key);
if let Some(pkg) = pkgs.get(&key) {
if pkg.loc.is_some() {
continue;
}
}
res.push(StartCheckError::MissingTool(key));
}
Ok(res)
}
#[tauri::command]
pub async fn startline(app: AppHandle) -> Result<(), String> {
log::debug!("invoke: startline");
@ -110,9 +148,25 @@ pub async fn get_all_packages(state: State<'_, Mutex<AppData>>) -> Result<HashMa
pub async fn fetch_listings(state: State<'_, Mutex<AppData>>) -> Result<(), String> {
log::debug!("invoke: fetch_listings");
{
let appd = state.lock().await;
if !appd.pkgs.is_offline() {
log::warn!("fetch_listings: already done");
return Ok(());
}
if appd.cfg.offline_mode {
log::info!("fetch_listings: skipped");
return Err("offline mode".to_owned());
}
}
let listings = PackageStore::fetch_listings().await
.map_err(|e| e.to_string())?;
let mut appd = state.lock().await;
appd.pkgs.fetch_listings().await
.map_err(|e| e.to_string())
appd.pkgs.process_fetched_listings(listings);
Ok(())
}
#[tauri::command]