From 02653bdae8d3b9da758f26c5297421d276d24c64 Mon Sep 17 00:00:00 2001 From: trivernis Date: Sun, 24 Oct 2021 13:23:50 +0200 Subject: [PATCH] =?UTF-8?q?Add=20more=20tracing=20and=20error=20handling?= =?UTF-8?q?=C2=A7?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: trivernis --- mediarepo-api/src/tauri_plugin/mod.rs | 1 + mediarepo-api/src/tauri_plugin/settings.rs | 9 ++++++--- mediarepo-api/src/tauri_plugin/state.rs | 1 + 3 files changed, 8 insertions(+), 3 deletions(-) diff --git a/mediarepo-api/src/tauri_plugin/mod.rs b/mediarepo-api/src/tauri_plugin/mod.rs index 801a384..6436aa7 100644 --- a/mediarepo-api/src/tauri_plugin/mod.rs +++ b/mediarepo-api/src/tauri_plugin/mod.rs @@ -47,6 +47,7 @@ impl Plugin for MediarepoPlugin { "mediarepo" } + #[tracing::instrument(skip(self, app, _config))] fn initialize( &mut self, app: &AppHandle, diff --git a/mediarepo-api/src/tauri_plugin/settings.rs b/mediarepo-api/src/tauri_plugin/settings.rs index 0b7d164..8fbcc68 100644 --- a/mediarepo-api/src/tauri_plugin/settings.rs +++ b/mediarepo-api/src/tauri_plugin/settings.rs @@ -7,14 +7,14 @@ use std::path::PathBuf; static SETTINGS_FILE: &str = "settings.toml"; -#[derive(Serialize, Deserialize, Clone)] +#[derive(Serialize, Debug, Deserialize, Clone)] pub struct Repository { pub(crate) name: String, pub(crate) path: Option, pub(crate) address: String, } -#[derive(Default, Serialize, Deserialize)] +#[derive(Default, Debug, Serialize, Deserialize)] pub struct Settings { pub repositories: HashMap, } @@ -27,6 +27,7 @@ fn get_settings_path() -> PathBuf { } /// Writes the settings to the file +#[tracing::instrument(level = "debug")] pub fn save_settings(settings: &Settings) -> PluginResult<()> { let settings_path = get_settings_path(); let settings_string = toml::to_string(&settings)?; @@ -36,8 +37,10 @@ pub fn save_settings(settings: &Settings) -> PluginResult<()> { } /// Loads the settings from the file +#[tracing::instrument(level = "debug")] pub fn load_settings() -> PluginResult { - 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(); if !config_path.exists() { fs::create_dir_all(&config_path)?; diff --git a/mediarepo-api/src/tauri_plugin/state.rs b/mediarepo-api/src/tauri_plugin/state.rs index f23178e..6833f99 100644 --- a/mediarepo-api/src/tauri_plugin/state.rs +++ b/mediarepo-api/src/tauri_plugin/state.rs @@ -59,6 +59,7 @@ pub struct AppState { } impl AppState { + #[tracing::instrument(level = "debug")] pub fn load() -> PluginResult { let settings = load_settings()?;