use chrono::Duration; use chrono_tz::Tz; use cron::Schedule; use serde::{Deserialize, Serialize}; use validated_newtype::validated_newtype; validated_newtype! { #[derive(Debug, PartialOrd, Ord, PartialEq, Eq, Serialize, Clone, Copy)] u8 => pub Percent if |n: &u8| *n <= 100; error "percent must in range 0-100" } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] pub struct Config { pub name: String, pub battery: BatteryConfig, pub time: TimeConfig, pub device: DeviceConfig, } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] pub struct BatteryConfig { pub alert: Percent, pub low: Percent, pub restart_powerd_threshold: Percent, } #[serde_with::serde_as] #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] pub struct TimeConfig { pub timezone: Tz, pub update_schedule: Schedule, #[serde_as(as = "serde_with::DurationSeconds")] pub delay_on_error: Duration, #[serde_as(as = "serde_with::DurationSeconds")] pub delay_before_suspend: Duration, #[serde_as(as = "serde_with::DurationSeconds")] pub delay_low_battery: Duration, } #[derive(Debug, Deserialize, Serialize, Clone, PartialEq, Eq)] pub struct DeviceConfig { pub use_rtc: bool, pub full_refresh: bool, pub orientation: Orientation, pub status_box_location: Corner, } #[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)] pub enum Orientation { PortraitUp, PortraitDown, LandscapeLeft, LandscapeRight, } #[derive(Debug, Clone, Copy, Deserialize, Serialize, PartialEq, Eq)] pub enum Corner { TopLeft, TopRight, BottomLeft, BottomRight, }