feat: groundwork for multi-profile support
This commit is contained in:
@ -4,6 +4,7 @@ use std::path::PathBuf;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::fs;
|
||||
|
||||
use crate::model::misc::Game;
|
||||
use crate::pkg::{Package, PkgKey};
|
||||
use crate::pkg_store::InstallResult;
|
||||
use crate::profile::Profile;
|
||||
@ -106,6 +107,23 @@ pub async fn fetch_listings(state: State<'_, Mutex<AppData>>) -> Result<(), Stri
|
||||
.map_err(|e| e.to_string())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_profiles() -> Result<Vec<(Game, String)>, String> {
|
||||
log::debug!("invoke: list_profiles");
|
||||
|
||||
let list = Profile::list().await.map_err(|e| e.to_string())?;
|
||||
Ok(list)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn load_profile(state: State<'_, Mutex<AppData>>, game: Game, name: String) -> Result<(), String> {
|
||||
log::debug!("invoke: load_profile({} {:?})", game, name);
|
||||
|
||||
let mut appd = state.lock().await;
|
||||
appd.switch_profile(&game, &name).map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_current_profile(state: State<'_, Mutex<AppData>>) -> Result<Option<Profile>, ()> {
|
||||
log::debug!("invoke: get_current_profile");
|
||||
@ -115,8 +133,8 @@ pub async fn get_current_profile(state: State<'_, Mutex<AppData>>) -> Result<Opt
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn save_profile(state: State<'_, Mutex<AppData>>) -> Result<(), ()> {
|
||||
log::debug!("invoke: save_profile");
|
||||
pub async fn save_current_profile(state: State<'_, Mutex<AppData>>) -> Result<(), ()> {
|
||||
log::debug!("invoke: save_current_profile");
|
||||
|
||||
let appd = state.lock().await;
|
||||
if let Some(p) = &appd.profile {
|
||||
@ -133,18 +151,17 @@ pub async fn init_profile(
|
||||
state: State<'_, Mutex<AppData>>,
|
||||
exe_path: PathBuf
|
||||
) -> Result<Profile, String> {
|
||||
log::debug!("invoke: init_profile({})", exe_path.to_string_lossy());
|
||||
log::debug!("invoke: init_profile({:?})", exe_path);
|
||||
|
||||
let mut appd = state.lock().await;
|
||||
let new_profile = Profile::new(exe_path);
|
||||
if let Some(new_profile) = Profile::new(exe_path) {
|
||||
new_profile.save().await;
|
||||
appd.profile = Some(new_profile.clone());
|
||||
|
||||
new_profile.save().await;
|
||||
appd.profile = Some(new_profile.clone());
|
||||
|
||||
fs::create_dir(new_profile.dir()).await
|
||||
.map_err(|e| format!("Unable to create profile directory: {}", e))?;
|
||||
|
||||
Ok(new_profile)
|
||||
Ok(new_profile)
|
||||
} else {
|
||||
Err("Unrecognized game".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
// #[tauri::command]
|
||||
@ -184,7 +201,7 @@ pub async fn write_profile_data(
|
||||
content: String
|
||||
) -> Result<(), String> {
|
||||
let appd = state.lock().await;
|
||||
|
||||
|
||||
if let Some(p) = &appd.profile {
|
||||
fs::write(p.dir().join(&path), content).await
|
||||
.map_err(|e| format!("Unable to write to {:?}: {}", path, e))?;
|
||||
@ -204,7 +221,7 @@ pub async fn set_cfg(
|
||||
|
||||
let mut appd = state.lock().await;
|
||||
if let Some(p) = &mut appd.profile {
|
||||
p.cfg.insert(key, value);
|
||||
p.data.cfg.insert(key, value);
|
||||
}
|
||||
|
||||
Ok(())
|
||||
|
Reference in New Issue
Block a user