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,3 +1,3 @@
|
|||||||
fn main() {
|
fn main() {
|
||||||
slint_build::compile("ui/widget-popup.slint").unwrap();
|
slint_build::compile("ui/widget-popup.slint").unwrap();
|
||||||
}
|
}
|
||||||
|
|||||||
@ -1,8 +1,8 @@
|
|||||||
use owm_rs::free_api_v25::current::WeatherResponse;
|
use owm_rs::free_api_v25::current::WeatherResponse;
|
||||||
use owm_widg_config::config::Config;
|
use owm_widg_config::config::Config;
|
||||||
use owm_widg_config::general::ApiVersion;
|
use owm_widg_config::general::ApiVersion;
|
||||||
use std::fs;
|
|
||||||
use slint::SharedString;
|
use slint::SharedString;
|
||||||
|
use std::fs;
|
||||||
|
|
||||||
slint::include_modules!();
|
slint::include_modules!();
|
||||||
|
|
||||||
@ -30,21 +30,22 @@ fn main() -> Result<(), Box<dyn std::error::Error>> {
|
|||||||
.sys
|
.sys
|
||||||
.as_ref()
|
.as_ref()
|
||||||
.and_then(|s| s.country.clone())
|
.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() {
|
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 {
|
} 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 temp = resp.main.as_ref().and_then(|m| m.temp).unwrap_or(0.0);
|
||||||
let temperature = format!("{temp:.1}");
|
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
|
// Create and show the UI
|
||||||
let ui = MainWindow::new()?;
|
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.
|
/// Convert OWM icon codes (e.g. "01d", "09n") to Nerd Font weather glyphs.
|
||||||
fn icon_to_nerd_font(code: &str) -> String {
|
fn icon_to_nerd_font(code: &str) -> String {
|
||||||
match code {
|
match code {
|
||||||
"01d" => "", // clear day
|
"01d" => "", // clear day
|
||||||
"01n" => "", // clear night
|
"01n" => "", // clear night
|
||||||
"02d" | "02n" => "", // few clouds
|
"02d" | "02n" => "", // few clouds
|
||||||
"03d" | "03n" => "", // scattered clouds
|
"03d" | "03n" => "", // scattered clouds
|
||||||
"04d" | "04n" => "", // broken clouds
|
"04d" | "04n" => "", // broken clouds
|
||||||
@ -77,7 +78,7 @@ fn icon_to_nerd_font(code: &str) -> String {
|
|||||||
"11d" | "11n" => "", // thunderstorm
|
"11d" | "11n" => "", // thunderstorm
|
||||||
"13d" | "13n" => "", // snow
|
"13d" | "13n" => "", // snow
|
||||||
"50d" | "50n" => "", // mist
|
"50d" | "50n" => "", // mist
|
||||||
_ => "".into(),
|
_ => "",
|
||||||
}
|
}
|
||||||
.into()
|
.into()
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user