feat: use sets etc.

This commit is contained in:
2025-02-27 16:42:43 +00:00
parent 3d96d89846
commit d25841853c
11 changed files with 587 additions and 563 deletions

View File

@ -147,16 +147,50 @@ pub async fn init_profile(
Ok(new_profile)
}
// #[tauri::command]
// pub async fn 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")
// }
// }
// the tauri fs plugin doesn't fucking work
#[tauri::command]
pub async fn profile_dir(
state: State<'_, Mutex<AppData>>
) -> Result<PathBuf, &str> {
pub async fn read_profile_data(
state: State<'_, Mutex<AppData>>,
path: PathBuf
) -> Result<String, String> {
let appd = state.lock().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 {
Ok(p.dir())
fs::write(p.dir().join(&path), content).await
.map_err(|e| format!("Unable to write to {:?}: {}", path, e))?;
Ok(())
} else {
Err("No profile loaded")
Err("No profile loaded".to_owned())
}
}