feat: more breaking changes
This commit is contained in:
@ -1,6 +1,5 @@
|
||||
use log;
|
||||
use std::collections::HashMap;
|
||||
use std::path::PathBuf;
|
||||
use tokio::sync::Mutex;
|
||||
use tokio::fs;
|
||||
|
||||
@ -9,7 +8,7 @@ use crate::pkg::{Package, PkgKey};
|
||||
use crate::pkg_store::InstallResult;
|
||||
use crate::profile::Profile;
|
||||
use crate::appdata::AppData;
|
||||
use crate::{liner, start};
|
||||
use crate::{liner, start, util};
|
||||
|
||||
use tauri::{AppHandle, Manager, State};
|
||||
|
||||
@ -121,7 +120,7 @@ pub async fn load_profile(state: State<'_, Mutex<AppData>>, game: Game, name: St
|
||||
log::debug!("invoke: load_profile({} {:?})", game, name);
|
||||
|
||||
let mut appd = state.lock().await;
|
||||
appd.switch_profile(&game, &name).map_err(|e| e.to_string())?;
|
||||
appd.switch_profile(game, name).map_err(|e| e.to_string())?;
|
||||
Ok(())
|
||||
}
|
||||
|
||||
@ -133,17 +132,6 @@ pub async fn get_current_profile(state: State<'_, Mutex<AppData>>) -> Result<Opt
|
||||
Ok(appd.profile.clone())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn get_current_profile_dir(state: State<'_, Mutex<AppData>>) -> Result<PathBuf, &str> {
|
||||
let appd = state.lock().await;
|
||||
|
||||
if let Some(p) = &appd.profile {
|
||||
Ok(p.dir())
|
||||
} else {
|
||||
Err("No profile loaded")
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn save_current_profile(state: State<'_, Mutex<AppData>>) -> Result<(), ()> {
|
||||
log::debug!("invoke: save_current_profile");
|
||||
@ -161,54 +149,23 @@ pub async fn save_current_profile(state: State<'_, Mutex<AppData>>) -> Result<()
|
||||
#[tauri::command]
|
||||
pub async fn init_profile(
|
||||
state: State<'_, Mutex<AppData>>,
|
||||
exe_path: PathBuf
|
||||
game: Game,
|
||||
name: String
|
||||
) -> Result<Profile, String> {
|
||||
log::debug!("invoke: init_profile({:?})", exe_path);
|
||||
log::debug!("invoke: init_profile({}, {})", game, name);
|
||||
|
||||
let mut appd = state.lock().await;
|
||||
if let Some(new_profile) = Profile::new(exe_path) {
|
||||
new_profile.save().await;
|
||||
appd.profile = Some(new_profile.clone());
|
||||
fs::create_dir_all(new_profile.dir()).await
|
||||
.map_err(|e| format!("Unable to create the profile directory: {}", e))?;
|
||||
let new_profile = Profile::new(game, name);
|
||||
|
||||
Ok(new_profile)
|
||||
} else {
|
||||
Err("Unrecognized game".to_owned())
|
||||
}
|
||||
}
|
||||
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))?;
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn read_profile_data(
|
||||
state: State<'_, Mutex<AppData>>,
|
||||
path: PathBuf
|
||||
) -> Result<String, String> {
|
||||
let appd = state.lock().await;
|
||||
appd.profile = Some(new_profile.clone());
|
||||
new_profile.save().await;
|
||||
|
||||
if let Some(p) = &appd.profile {
|
||||
let res = fs::read_to_string(p.dir().join(&path)).await
|
||||
.map_err(|e| format!("Unable to open {:?}: {}", path, e))?;
|
||||
Ok(res)
|
||||
} else {
|
||||
Err("No profile loaded".to_owned())
|
||||
}
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn write_profile_data(
|
||||
state: State<'_, Mutex<AppData>>,
|
||||
path: PathBuf,
|
||||
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))?;
|
||||
Ok(())
|
||||
} else {
|
||||
Err("No profile loaded".to_owned())
|
||||
}
|
||||
Ok(new_profile)
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
@ -266,3 +223,10 @@ pub async fn list_displays() -> Result<Vec<String>, ()> {
|
||||
|
||||
Ok(Vec::new())
|
||||
}
|
||||
|
||||
#[tauri::command]
|
||||
pub async fn list_directories() -> Result<util::Dirs, ()> {
|
||||
log::debug!("invoke: list_directores");
|
||||
|
||||
Ok(util::all_dirs().clone())
|
||||
}
|
Reference in New Issue
Block a user