Add more tracing and error handling§

Signed-off-by: trivernis <trivernis@protonmail.com>
pull/4/head
trivernis 3 years ago
parent d9495e83f5
commit 02653bdae8

@ -47,6 +47,7 @@ impl<R: Runtime> Plugin<R> for MediarepoPlugin<R> {
"mediarepo" "mediarepo"
} }
#[tracing::instrument(skip(self, app, _config))]
fn initialize( fn initialize(
&mut self, &mut self,
app: &AppHandle<R>, app: &AppHandle<R>,

@ -7,14 +7,14 @@ use std::path::PathBuf;
static SETTINGS_FILE: &str = "settings.toml"; static SETTINGS_FILE: &str = "settings.toml";
#[derive(Serialize, Deserialize, Clone)] #[derive(Serialize, Debug, Deserialize, Clone)]
pub struct Repository { pub struct Repository {
pub(crate) name: String, pub(crate) name: String,
pub(crate) path: Option<String>, pub(crate) path: Option<String>,
pub(crate) address: String, pub(crate) address: String,
} }
#[derive(Default, Serialize, Deserialize)] #[derive(Default, Debug, Serialize, Deserialize)]
pub struct Settings { pub struct Settings {
pub repositories: HashMap<String, Repository>, pub repositories: HashMap<String, Repository>,
} }
@ -27,6 +27,7 @@ fn get_settings_path() -> PathBuf {
} }
/// Writes the settings to the file /// Writes the settings to the file
#[tracing::instrument(level = "debug")]
pub fn save_settings(settings: &Settings) -> PluginResult<()> { pub fn save_settings(settings: &Settings) -> PluginResult<()> {
let settings_path = get_settings_path(); let settings_path = get_settings_path();
let settings_string = toml::to_string(&settings)?; let settings_string = toml::to_string(&settings)?;
@ -36,8 +37,10 @@ pub fn save_settings(settings: &Settings) -> PluginResult<()> {
} }
/// Loads the settings from the file /// Loads the settings from the file
#[tracing::instrument(level = "debug")]
pub fn load_settings() -> PluginResult<Settings> { pub fn load_settings() -> PluginResult<Settings> {
let dirs = ProjectDirs::from("com", "trivernis", "mediarepo").unwrap(); let dirs = ProjectDirs::from("com", "trivernis", "mediarepo")
.expect("Failed to get project directories");
let config_path = dirs.config_dir().to_path_buf(); let config_path = dirs.config_dir().to_path_buf();
if !config_path.exists() { if !config_path.exists() {
fs::create_dir_all(&config_path)?; fs::create_dir_all(&config_path)?;

@ -59,6 +59,7 @@ pub struct AppState {
} }
impl AppState { impl AppState {
#[tracing::instrument(level = "debug")]
pub fn load() -> PluginResult<Self> { pub fn load() -> PluginResult<Self> {
let settings = load_settings()?; let settings = load_settings()?;

Loading…
Cancel
Save