Initial ForgeLM import
This commit is contained in:
commit
a392b9dc60
4296 files changed
+1212675
No files matched your search
@@ -0,0 +1,32 @@
|
||||
use std::path::PathBuf;
|
||||
|
||||
use tauri::{AppHandle, Manager};
|
||||
|
||||
use super::types::RuntimeConfig;
|
||||
|
||||
pub fn config_path(app: &AppHandle) -> Result<PathBuf, String> {
|
||||
let data_dir = app
|
||||
.path()
|
||||
.app_data_dir()
|
||||
.map_err(|e| format!("Cannot resolve app data dir: {e}"))?;
|
||||
std::fs::create_dir_all(&data_dir).map_err(|e| format!("Cannot create app data dir: {e}"))?;
|
||||
Ok(data_dir.join("config.json"))
|
||||
}
|
||||
|
||||
pub fn load_runtime_config(app: &AppHandle) -> Result<RuntimeConfig, String> {
|
||||
let path = config_path(app)?;
|
||||
if !path.exists() {
|
||||
return Ok(RuntimeConfig::default());
|
||||
}
|
||||
|
||||
let json = std::fs::read_to_string(&path).map_err(|e| format!("Read error: {e}"))?;
|
||||
serde_json::from_str(&json).map_err(|e| format!("Parse error: {e}"))
|
||||
}
|
||||
|
||||
pub fn save_runtime_config(app: &AppHandle, config: &RuntimeConfig) -> Result<(), String> {
|
||||
let path = config_path(app)?;
|
||||
let json =
|
||||
serde_json::to_string_pretty(config).map_err(|e| format!("Serialization error: {e}"))?;
|
||||
std::fs::write(&path, json).map_err(|e| format!("Write error: {e}"))?;
|
||||
Ok(())
|
||||
}
|
||||
Reference in new issue
Block a user