use color_eyre::Result; use futures_lite::stream::StreamExt; use gtk::{Button, prelude::*}; use gtk::{Label, Orientation}; use serde::Deserialize; use tokio::sync::{broadcast, mpsc}; use zbus; use zbus::fdo::PropertiesProxy; use crate::clients::upower::BatteryState; use crate::config::CommonConfig; use crate::gtk_helpers::{IronbarGtkExt, IronbarLabelExt}; use crate::image::ImageProvider; use crate::modules::PopupButton; use crate::modules::{ Module, ModuleInfo, ModuleParts, ModulePopup, ModuleUpdateEvent, WidgetContext, }; use crate::{glib_recv, module_impl, send_async, spawn, try_send}; const DAY: i64 = 24 * 60 * 60; const HOUR: i64 = 60 * 60; const MINUTE: i64 = 60; #[derive(Debug, Deserialize, Clone)] #[cfg_attr(feature = "schema", derive(schemars::JsonSchema))] pub struct UpowerModule { /// The format string to use for the widget button label. /// For available tokens, see [below](#formatting-tokens). /// /// **Default**: `{percentage}%` #[serde(default = "default_format")] format: String, /// The size to render the icon at, in pixels. /// /// **Default**: `24` #[serde(default = "default_icon_size")] icon_size: i32, /// See [common options](module-level-options#common-options). #[serde(flatten)] pub common: Option, } fn default_format() -> String { String::from("{percentage}%") } const fn default_icon_size() -> i32 { 24 } #[derive(Clone, Debug)] pub struct UpowerProperties { percentage: f64, icon_name: String, state: BatteryState, time_to_full: i64, time_to_empty: i64, } impl Module