This commit is contained in:
2026-09-12 21:50:09 +01:00
parent b20e03def7
commit b81eb967ee
17 changed files with 468 additions and 14 deletions
+2
View File
@@ -11,3 +11,5 @@ path = "src/lib.rs"
iced = { workspace = true }
toml = { workspace = true }
serde = { workspace = true }
chrono = { workspace = true }
serde_json = { workspace = true }
+2
View File
@@ -14,6 +14,8 @@ mod wire;
pub use config::BarbarConfig;
pub use effect::ModuleEffect;
pub use messages::{ClockKind, ClockMsg, ClockPayload};
pub use messages::modules::WeatherKind;
pub use messages::services::WeatherResponse;
pub use module::BarModule;
pub use service::Service;
pub use wire::{Endpoint, Inbox, Namespace, Target, Wire};
@@ -1,5 +1,7 @@
//! Messages owned by bar modules.
mod clock;
mod weather;
pub use clock::ClockMsg;
pub use weather::WeatherKind;
@@ -0,0 +1,7 @@
//! Weather module messages.
/// A module-local message for the weather tile (bar/popup interactions).
#[derive(Clone)]
pub enum WeatherKind {
Poke,
}
@@ -1,5 +1,7 @@
//! Messages owned by services.
mod datetime;
mod weather;
pub use datetime::{ClockKind, ClockPayload};
pub use weather::{WeatherKind, WeatherPayload, WeatherResponse};
@@ -0,0 +1,77 @@
use std::{any::Any, sync::Arc};
use serde::Deserialize;
use crate::Service;
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
pub enum WeatherKind {
State,
}
impl WeatherKind {
pub fn key(self) -> Service {
Service(match self {
Self::State => "weather.state",
})
}
}
#[derive(Clone, Debug)]
pub struct WeatherPayload {
pub kind: WeatherKind,
pub payload: Arc<dyn Any + Send + Sync>,
}
/// Open-Meteo forecast response.
#[derive(Debug, Deserialize)]
pub struct WeatherResponse {
pub latitude: f64,
pub longitude: f64,
pub generationtime_ms: f64,
pub utc_offset_seconds: i64,
pub timezone: String,
pub timezone_abbreviation: String,
pub elevation: f64,
pub hourly_units: HourlyUnits,
pub hourly: Hourly,
}
#[derive(Debug, Deserialize)]
pub struct HourlyUnits {
pub time: String,
pub temperature_2m: String,
pub rain: String,
pub showers: String,
pub precipitation: String,
pub relative_humidity_2m: String,
}
#[derive(Debug, Deserialize)]
pub struct Hourly {
#[serde(deserialize_with = "naive_dt::deserialize")]
pub time: Vec<chrono::NaiveDateTime>,
pub temperature_2m: Vec<f64>,
pub rain: Vec<f64>,
pub showers: Vec<f64>,
pub precipitation: Vec<f64>,
pub relative_humidity_2m: Vec<f64>,
}
/// Open-Meteo emits local timestamps as `"%Y-%m-%dT%H:%M"` (no seconds).
mod naive_dt {
use chrono::NaiveDateTime;
use serde::{de::Error, Deserialize, Deserializer};
const FMT: &str = "%Y-%m-%dT%H:%M";
pub fn deserialize<'de, D>(d: D) -> Result<Vec<NaiveDateTime>, D::Error>
where
D: Deserializer<'de>,
{
Vec::<String>::deserialize(d)?
.iter()
.map(|s| NaiveDateTime::parse_from_str(s, FMT).map_err(D::Error::custom))
.collect()
}
}