Fix: Get unit from config

- Use conditionals to determine the temperature unit symbol from config
- cargo clippy
This commit is contained in:
Candifloss 2025-11-05 15:30:21 +05:30
parent 4fe5878d36
commit ccf9e8225f
2 changed files with 14 additions and 13 deletions

View File

@ -1,3 +1,3 @@
fn main() {
slint_build::compile("ui/widget-popup.slint").unwrap();
}
}

View File

@ -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()?;
@ -67,8 +68,8 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
/// 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()
}