diff --git a/widget/build.rs b/widget/build.rs index 2559b5e..cc515dc 100644 --- a/widget/build.rs +++ b/widget/build.rs @@ -1,3 +1,3 @@ fn main() { slint_build::compile("ui/widget-popup.slint").unwrap(); -} \ No newline at end of file +} diff --git a/widget/src/main.rs b/widget/src/main.rs index a4350be..f4752c4 100644 --- a/widget/src/main.rs +++ b/widget/src/main.rs @@ -1,8 +1,8 @@ use owm_rs::free_api_v25::current::WeatherResponse; use owm_widg_config::config::Config; use owm_widg_config::general::ApiVersion; -use std::fs; use slint::SharedString; +use std::fs; slint::include_modules!(); @@ -30,21 +30,22 @@ fn main() -> Result<(), Box> { .sys .as_ref() .and_then(|s| s.country.clone()) - .unwrap_or_else(|| "".into()); + .unwrap_or_else(|| String::new()); let (weather_main, weather_description, icon) = if let Some(w) = resp.weather.first() { - ( - w.main.clone(), - w.description.clone(), - w.icon.clone(), - ) + (w.main.clone(), w.description.clone(), w.icon.clone()) } else { - ("N/A".into(), "N/A".into(), "".into()) + ("N/A".into(), "N/A".into(), String::new()) }; let temp = resp.main.as_ref().and_then(|m| m.temp).unwrap_or(0.0); let temperature = format!("{temp:.1}"); - let unit = "C"; + let unit = match cfg.query_params.units.as_str() { + "metric" => 'C', + "imperial" => 'F', + "standard" => 'K', + _ => '?', + }; // Create and show the UI let ui = MainWindow::new()?; @@ -67,8 +68,8 @@ fn main() -> Result<(), Box> { /// Convert OWM icon codes (e.g. "01d", "09n") to Nerd Font weather glyphs. fn icon_to_nerd_font(code: &str) -> String { match code { - "01d" => "", // clear day - "01n" => "", // clear night + "01d" => "", // clear day + "01n" => "", // clear night "02d" | "02n" => "", // few clouds "03d" | "03n" => "", // scattered clouds "04d" | "04n" => "", // broken clouds @@ -77,7 +78,7 @@ fn icon_to_nerd_font(code: &str) -> String { "11d" | "11n" => "", // thunderstorm "13d" | "13n" => "", // snow "50d" | "50n" => "", // mist - _ => "".into(), + _ => "", } .into() }