fucking something i forgot
This commit is contained in:
@@ -9,4 +9,8 @@ path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../common" }
|
||||
module_clock = { package = "module-clock", path = "clock" }
|
||||
services = { path = "../services" }
|
||||
iced = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
serde = {workspace = true}
|
||||
|
||||
@@ -1,15 +0,0 @@
|
||||
[package]
|
||||
name = "module-clock"
|
||||
version.workspace = true
|
||||
edition.workspace = true
|
||||
|
||||
[lib]
|
||||
name = "module_clock"
|
||||
path = "src/lib.rs"
|
||||
|
||||
[dependencies]
|
||||
common = { path = "../../common" }
|
||||
service_datetime = { package = "service-datetime", path = "../../services/datetime" }
|
||||
iced = { workspace = true }
|
||||
thiserror = { workspace = true }
|
||||
toml = { workspace = true }
|
||||
@@ -1,7 +0,0 @@
|
||||
//! Clock module: subscribes to second ticks, renders the time in the bar.
|
||||
//! Left-click toggles the seconds suffix; right-click opens a popup with
|
||||
//! the current time in large text.
|
||||
|
||||
mod module;
|
||||
|
||||
pub use module::{Clock, ClockError, ClockMsg};
|
||||
@@ -1,8 +1,14 @@
|
||||
//! Clock module: subscribes to second ticks, renders the time in the bar.
|
||||
//! Left-click toggles the seconds suffix; right-click opens a popup with
|
||||
//! the current time in large text.
|
||||
|
||||
use iced::widget::{container, mouse_area, text};
|
||||
use iced::{Element, Task};
|
||||
|
||||
use common::{BarModule, ModuleEffect, ModuleMsg, Service};
|
||||
use service_datetime::{ClockKind, ClockPayload};
|
||||
use serde::Deserialize;
|
||||
use services::datetime::{ClockKind, ClockPayload};
|
||||
use toml::Table;
|
||||
|
||||
/// Big-text popup size (logical px).
|
||||
const POPUP_W: u32 = 360;
|
||||
@@ -30,11 +36,21 @@ pub struct Clock {
|
||||
show_seconds: bool,
|
||||
}
|
||||
|
||||
#[derive(Deserialize, Default)]
|
||||
struct ClockConfig {
|
||||
#[serde(default)]
|
||||
format: bool,
|
||||
}
|
||||
|
||||
impl Clock {
|
||||
pub fn new() -> Self {
|
||||
Self {
|
||||
value: "--:--:--".to_string(),
|
||||
show_seconds: true,
|
||||
pub fn new(config: Option<Table>) -> Self {
|
||||
let module_config = config_clock(config);
|
||||
match module_config {
|
||||
Some(x) => Self {
|
||||
value: "--:--:--".to_string(),
|
||||
show_seconds: { x.format },
|
||||
},
|
||||
None => Self::default(),
|
||||
}
|
||||
}
|
||||
|
||||
@@ -54,10 +70,15 @@ impl Clock {
|
||||
|
||||
impl Default for Clock {
|
||||
fn default() -> Self {
|
||||
Self::new()
|
||||
Self::new(None)
|
||||
}
|
||||
}
|
||||
|
||||
fn config_clock(table: Option<Table>) -> Option<ClockConfig> {
|
||||
let clock = table?.get("clock")?.clone();
|
||||
clock.try_into().ok()
|
||||
}
|
||||
|
||||
impl BarModule for Clock {
|
||||
fn id(&self) -> &'static str {
|
||||
"clock"
|
||||
@@ -105,12 +126,4 @@ impl BarModule for Clock {
|
||||
fn popup_size(&self) -> Option<(u32, u32)> {
|
||||
Some((POPUP_W, POPUP_H))
|
||||
}
|
||||
fn config(&mut self, config: toml::Table) -> Result<(), Box<dyn std::error::Error>> {
|
||||
if let toml::Value::Boolean(e) = config["format"] {
|
||||
if e {
|
||||
self.show_seconds = true;
|
||||
};
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
}
|
||||
@@ -1,10 +1,13 @@
|
||||
//! Bar module registry: constructs every enabled module. Adding a module is
|
||||
//! a new crate under `crates/modules/` plus one entry in `all()` — core
|
||||
//! never changes.
|
||||
//! a new file under `src/` plus one entry in `all()` — core never changes.
|
||||
|
||||
mod clock;
|
||||
|
||||
pub use clock::{Clock, ClockError, ClockMsg};
|
||||
use common::BarModule;
|
||||
use toml::Table;
|
||||
|
||||
/// One instance of every enabled module, ready to insert by `id()`.
|
||||
pub fn all() -> Vec<Box<dyn BarModule>> {
|
||||
vec![Box::new(module_clock::Clock::new())]
|
||||
pub fn all(module_config: Table) -> Vec<Box<dyn BarModule>> {
|
||||
vec![Box::new(clock::Clock::new(Some(module_config)))]
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user