AI models shared registry + Code cleanup + Better async handling + Some fixes, etc
This commit is contained in:
parent
b427eacf35
commit
5c3031c977
62 changed files with 1683 additions and 1239 deletions
|
|
@ -1,12 +1,14 @@
|
|||
pub mod structs;
|
||||
pub mod manager;
|
||||
|
||||
use crate::{config, APP_CONFIG_DIR};
|
||||
|
||||
use log::info;
|
||||
use std::fs::File;
|
||||
use std::io::{BufReader, Read};
|
||||
use std::io::BufReader;
|
||||
use std::path::PathBuf;
|
||||
|
||||
use serde_json;
|
||||
pub use manager::SettingsManager;
|
||||
|
||||
fn get_db_file_path() -> PathBuf {
|
||||
PathBuf::from(format!(
|
||||
|
|
@ -17,7 +19,6 @@ fn get_db_file_path() -> PathBuf {
|
|||
}
|
||||
|
||||
pub fn init_settings() -> structs::Settings {
|
||||
let mut db = None;
|
||||
let db_file_path = get_db_file_path();
|
||||
|
||||
info!(
|
||||
|
|
@ -26,23 +27,23 @@ pub fn init_settings() -> structs::Settings {
|
|||
);
|
||||
|
||||
if db_file_path.exists() {
|
||||
// try load existing settings
|
||||
if let Ok(mut db_file) = File::open(db_file_path) {
|
||||
if let Ok(db_file) = File::open(&db_file_path) {
|
||||
let reader = BufReader::new(db_file);
|
||||
if let Ok(parsed_json) = serde_json::from_reader(reader) {
|
||||
if let Ok(settings) = serde_json::from_reader(reader) {
|
||||
info!("Settings loaded.");
|
||||
db = Some(parsed_json);
|
||||
return settings;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if db.is_none() {
|
||||
// create default settings db file
|
||||
warn!("No settings file found or there was an error parsing it. Creating default struct.");
|
||||
db = Some(structs::Settings::default());
|
||||
}
|
||||
warn!("No settings file found or there was an error parsing it. Creating default struct.");
|
||||
structs::Settings::default()
|
||||
}
|
||||
|
||||
db.unwrap()
|
||||
/// init settings and return a SettingsManager ready to use
|
||||
pub fn init() -> SettingsManager {
|
||||
let settings = init_settings();
|
||||
SettingsManager::new(settings)
|
||||
}
|
||||
|
||||
pub fn save_settings(settings: &structs::Settings) -> Result<(), std::io::Error> {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue