Fix: Get unit from config
- Use conditionals to determine the temperature unit symbol from config - cargo clippy
This commit is contained in:
parent
4fe5878d36
commit
ccf9e8225f
@ -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<dyn std::error::Error>> {
|
||||
.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()?;
|
||||
@ -77,7 +78,7 @@ fn icon_to_nerd_font(code: &str) -> String {
|
||||
"11d" | "11n" => "", // thunderstorm
|
||||
"13d" | "13n" => "", // snow
|
||||
"50d" | "50n" => "", // mist
|
||||
_ => "".into(),
|
||||
_ => "",
|
||||
}
|
||||
.into()
|
||||
}
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user