From c58405c5cb968f4ffd055a79d89c330ce913f125 Mon Sep 17 00:00:00 2001 From: Luke Else Date: Sat, 22 Feb 2025 16:03:35 +0000 Subject: [PATCH] Added config file --- Cargo.toml | 14 ++++++++------ config.yml | 1 + src/app/mod.rs | 4 ++++ src/app/ui/tabs/metar_tab.rs | 2 +- src/main.rs | 3 +++ src/utils/config.rs | 20 ++++++++++++++++++++ src/utils/mod.rs | 1 + 7 files changed, 38 insertions(+), 7 deletions(-) create mode 100644 config.yml create mode 100644 src/utils/config.rs create mode 100644 src/utils/mod.rs diff --git a/Cargo.toml b/Cargo.toml index 48d415f..7c3b322 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -6,12 +6,14 @@ edition = "2021" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html [dependencies] -egui = "0.28.1" -eframe = "0.28.1" -tracing-subscriber = "0.3.16" -strum = { version = "0.26.3", features = ["derive"] } -tokio = { version = "1.39.2", features = ["full"] } -tokio-macros = { version = "2.4.0" } +egui = "0.31.0" +eframe = "0.31.0" +tracing-subscriber = "0.3.19" +strum = { version = "0.27.1", features = ["derive"] } +tokio = { version = "1.43.0", features = ["full"] } +tokio-macros = { version = "2.5.0" } async-trait = "0.1.86" futures = "0.3.31" reqwest = "0.12.12" +serde_yaml = "0.9.34" +serde = {version = "1.0.218", features = ["derive"]} diff --git a/config.yml b/config.yml new file mode 100644 index 0000000..8871bf7 --- /dev/null +++ b/config.yml @@ -0,0 +1 @@ +metar_url: "https://tgftp.nws.noaa.gov/data/observations/metar/stations/" diff --git a/src/app/mod.rs b/src/app/mod.rs index 9b4066f..f5186e8 100644 --- a/src/app/mod.rs +++ b/src/app/mod.rs @@ -2,9 +2,12 @@ mod metar; mod req; mod ui; +use crate::utils::config; + /// Stuct to store the state of the running application pub struct App<'a> { pub name: &'a str, + pub config: config::Config, tab_state: ui::tabs::TabState, } @@ -13,6 +16,7 @@ impl<'a> Default for App<'a> { fn default() -> Self { Self { name: "AvBag - Welcome", + config: config::Config::new(), tab_state: ui::tabs::TabState::default(), } } diff --git a/src/app/ui/tabs/metar_tab.rs b/src/app/ui/tabs/metar_tab.rs index 9114212..31d963c 100644 --- a/src/app/ui/tabs/metar_tab.rs +++ b/src/app/ui/tabs/metar_tab.rs @@ -53,7 +53,7 @@ impl Tab for MetarTab { let metar_clone = Arc::clone(&self.metar); task::spawn(async move { let metar = metar_clone.lock().await; - match metar.api.make_request(String::from("https://google.co.uk")).await { + match metar.api.make_request(String::from("")).await { Ok(response) => println!("{:?}", response), Err(e) => eprintln!("Request failed: {:?}", e), } diff --git a/src/main.rs b/src/main.rs index e2e9719..0b6bf36 100644 --- a/src/main.rs +++ b/src/main.rs @@ -2,6 +2,7 @@ mod app; mod error; mod theme; +mod utils; use app::App; use egui::ViewportBuilder; @@ -18,6 +19,8 @@ async fn main() -> Result<(), Box> { // Create a box to the app and then pass into app creator let app = Box::new(App::default()); + + println!("App: {:?}", app.config); //Start rendering and run the application Ok(eframe::run_native(app.name, options, Box::new(|_cc| Ok(app)))?) diff --git a/src/utils/config.rs b/src/utils/config.rs new file mode 100644 index 0000000..6b94c65 --- /dev/null +++ b/src/utils/config.rs @@ -0,0 +1,20 @@ +use serde::Deserialize; + +const DEFAULT_CONFIG: &str = "./config.yml"; + +#[derive(Debug, Default, Deserialize)] +pub struct Config { + pub metar_url: String, +} + +impl Config { + pub fn new() -> Self { + Config::from_file().unwrap() + } + + pub fn from_file() -> Result> { + let config_content = std::fs::read_to_string(DEFAULT_CONFIG)?; + let config: Config = serde_yaml::from_str(&config_content)?; + Ok(config) + } +} \ No newline at end of file diff --git a/src/utils/mod.rs b/src/utils/mod.rs new file mode 100644 index 0000000..a105933 --- /dev/null +++ b/src/utils/mod.rs @@ -0,0 +1 @@ +pub mod config; \ No newline at end of file