feat: initial chunithm support

This commit is contained in:
2025-03-19 17:39:12 +00:00
parent 1191cdd95c
commit 8ac45df3e1
31 changed files with 1368 additions and 884 deletions

View File

@ -6,8 +6,7 @@ use tauri::{AppHandle, Manager, State};
use crate::model::misc::Game;
use crate::pkg::{Package, PkgKey};
use crate::pkg_store::{InstallResult, PackageStore};
use crate::profiles::ongeki::OngekiProfile;
use crate::profiles::{self, AnyProfile, Profile, ProfileMeta, ProfilePaths};
use crate::profiles::{self, Profile, ProfileData, ProfileMeta, ProfilePaths};
use crate::appdata::{AppData, ToggleAction};
use crate::model::misc::StartCheckError;
use crate::util;
@ -147,10 +146,21 @@ pub async fn get_all_packages(state: State<'_, Mutex<AppData>>) -> Result<HashMa
Ok(appd.pkgs.get_all())
}
#[tauri::command]
pub async fn get_game_packages(state: State<'_, Mutex<AppData>>, game: Game) -> Result<Vec<PkgKey>, ()> {
log::debug!("invoke: get_game_packages {game}");
let appd = state.lock().await;
Ok(appd.pkgs.get_game_list(game))
}
#[tauri::command]
pub async fn fetch_listings(state: State<'_, Mutex<AppData>>) -> Result<(), String> {
log::debug!("invoke: fetch_listings");
// let game;
{
let appd = state.lock().await;
if !appd.pkgs.is_offline() {
@ -161,13 +171,26 @@ pub async fn fetch_listings(state: State<'_, Mutex<AppData>>) -> Result<(), Stri
log::info!("fetch_listings: skipped");
return Err("offline mode".to_owned());
}
// if let Some(profile) = &appd.profile {
// game = profile.meta.game;
// } else {
// return Err("No profile".to_owned());
// }
}
let listings = PackageStore::fetch_listings().await
// Can be this lazy for now as there are only two short lists
let listings1 = PackageStore::fetch_listings(Game::Ongeki).await
.map_err(|e| e.to_string())?;
let listings2 = PackageStore::fetch_listings(Game::Chunithm).await
.map_err(|e| e.to_string())?;
let mut appd = state.lock().await;
appd.pkgs.process_fetched_listings(listings);
appd.pkgs.process_fetched_listings(listings1, Game::Ongeki);
appd.pkgs.process_fetched_listings(listings2, Game::Chunithm);
appd.pkgs.save().await
.map_err(|e| e.to_string())?;
Ok(())
}
@ -189,15 +212,10 @@ pub async fn init_profile(
log::debug!("invoke: init_profile({}, {})", game, name);
let mut appd = state.lock().await;
let new_profile = OngekiProfile::new(name)
let new_profile = Profile::new(ProfileMeta { game, name })
.map_err(|e| format!("Unable to create profile: {}", e))?;
fs::create_dir_all(new_profile.config_dir()).await
.map_err(|e| format!("Unable to create the profile config directory: {}", e))?;
fs::create_dir_all(new_profile.data_dir()).await
.map_err(|e| format!("Unable to create the profile data directory: {}", e))?;
appd.profile = Some(AnyProfile::OngekiProfile(new_profile.clone()));
appd.profile = Some(new_profile);
Ok(())
}
@ -242,7 +260,7 @@ pub async fn rename_profile(
let mut appd = state.lock().await;
if let Some(current) = &mut appd.profile {
if current.meta() == profile {
if current.meta == profile {
current.rename(new_meta.name);
}
}
@ -277,7 +295,7 @@ pub async fn delete_profile(state: State<'_, Mutex<AppData>>, profile: ProfileMe
let mut appd = state.lock().await;
if let Some(current) = &mut appd.profile {
if current.meta() == profile {
if current.meta == profile {
appd.profile = None;
}
}
@ -286,7 +304,7 @@ pub async fn delete_profile(state: State<'_, Mutex<AppData>>, profile: ProfileMe
}
#[tauri::command]
pub async fn get_current_profile(state: State<'_, Mutex<AppData>>) -> Result<Option<AnyProfile>, ()> {
pub async fn get_current_profile(state: State<'_, Mutex<AppData>>) -> Result<Option<Profile>, ()> {
log::debug!("invoke: get_current_profile");
let appd = state.lock().await;
@ -294,12 +312,12 @@ pub async fn get_current_profile(state: State<'_, Mutex<AppData>>) -> Result<Opt
}
#[tauri::command]
pub async fn sync_current_profile(state: State<'_, Mutex<AppData>>, profile: AnyProfile) -> Result<(), String> {
pub async fn sync_current_profile(state: State<'_, Mutex<AppData>>, data: ProfileData) -> Result<(), String> {
log::debug!("invoke: sync_current_profile");
let mut appd = state.lock().await;
if let Some(p) = &mut appd.profile {
p.sync(profile);
p.sync(data);
}
Ok(())