feat: use sets etc.
This commit is contained in:
@ -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())
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user