fucking something i forgot
This commit is contained in:
Generated
+129
-22
@@ -65,6 +65,56 @@ dependencies = [
|
|||||||
"libc",
|
"libc",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstream"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "824a212faf96e9acacdbd09febd34438f8f711fb84e09a8916013cd7815ca28d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"anstyle-parse",
|
||||||
|
"anstyle-query",
|
||||||
|
"anstyle-wincon",
|
||||||
|
"colorchoice",
|
||||||
|
"is_terminal_polyfill",
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle"
|
||||||
|
version = "1.0.14"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "940b3a0ca603d1eade50a4846a2afffd5ef57a9feac2c0e2ec2e14f9ead76000"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-parse"
|
||||||
|
version = "1.0.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "52ce7f38b242319f7cabaa6813055467063ecdc9d355bbb4ce0c68908cd8130e"
|
||||||
|
dependencies = [
|
||||||
|
"utf8parse",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-query"
|
||||||
|
version = "1.1.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "40c48f72fd53cd289104fc64099abca73db4166ad86ea0b4341abe65af83dadc"
|
||||||
|
dependencies = [
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "anstyle-wincon"
|
||||||
|
version = "3.0.11"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "291e6a250ff86cd4a820112fb8898808a366d8f9f58ce16d1f538353ad55747d"
|
||||||
|
dependencies = [
|
||||||
|
"anstyle",
|
||||||
|
"once_cell_polyfill",
|
||||||
|
"windows-sys 0.61.2",
|
||||||
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "arrayref"
|
name = "arrayref"
|
||||||
version = "0.3.9"
|
version = "0.3.9"
|
||||||
@@ -270,6 +320,46 @@ dependencies = [
|
|||||||
"windows-link",
|
"windows-link",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap"
|
||||||
|
version = "4.6.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "473c7e07f409a8d772161724aa8db6a765a2532a70f9667eeb7b49d3d02fbdca"
|
||||||
|
dependencies = [
|
||||||
|
"clap_builder",
|
||||||
|
"clap_derive",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_builder"
|
||||||
|
version = "4.6.6"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "7b48fea5a88e9ae728a2dcbedbfc0e730f7d60da42e1cb049a83c9fb8b789889"
|
||||||
|
dependencies = [
|
||||||
|
"anstream",
|
||||||
|
"anstyle",
|
||||||
|
"clap_lex",
|
||||||
|
"strsim",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_derive"
|
||||||
|
version = "4.6.4"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "d012d2b9d65aca7f18f4d9878a045bc17899bba951561ba5ec3c2ba1eed9a061"
|
||||||
|
dependencies = [
|
||||||
|
"heck",
|
||||||
|
"proc-macro2",
|
||||||
|
"quote",
|
||||||
|
"syn 3.0.5",
|
||||||
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "clap_lex"
|
||||||
|
version = "1.1.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "c8d4a3bb8b1e0c1050499d1815f5ab16d04f0959b233085fb31653fbfc9d98f9"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "clipboard-win"
|
name = "clipboard-win"
|
||||||
version = "5.4.1"
|
version = "5.4.1"
|
||||||
@@ -320,6 +410,12 @@ dependencies = [
|
|||||||
"unicode-width",
|
"unicode-width",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "colorchoice"
|
||||||
|
version = "1.0.5"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "1d07550c9036bf2ae0c684c4297d503f838287c83c53686d05370d0e139ae570"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "combine"
|
name = "combine"
|
||||||
version = "4.6.8"
|
version = "4.6.8"
|
||||||
@@ -335,6 +431,7 @@ name = "common"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"iced",
|
"iced",
|
||||||
|
"serde",
|
||||||
"toml",
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
@@ -352,12 +449,14 @@ name = "core"
|
|||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
|
"clap",
|
||||||
"common",
|
"common",
|
||||||
"iced",
|
"iced",
|
||||||
"iced_layershell",
|
"iced_layershell",
|
||||||
"modules",
|
"modules",
|
||||||
"services",
|
"services",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -1014,6 +1113,12 @@ version = "0.17.1"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
checksum = "ed5909b6e89a2db4456e54cd5f673791d7eca6732202bbf2a9cc504fe2f9b84a"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "heck"
|
||||||
|
version = "0.5.0"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "2304e00983f87ffb38b55b444b5e3b60a884b5d30c0fca7d82fe33449bbe55ea"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "hermit-abi"
|
name = "hermit-abi"
|
||||||
version = "0.5.3"
|
version = "0.5.3"
|
||||||
@@ -1418,6 +1523,12 @@ dependencies = [
|
|||||||
"hashbrown 0.17.1",
|
"hashbrown 0.17.1",
|
||||||
]
|
]
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "is_terminal_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "jni"
|
name = "jni"
|
||||||
version = "0.22.4"
|
version = "0.22.4"
|
||||||
@@ -1713,23 +1824,16 @@ dependencies = [
|
|||||||
"paste",
|
"paste",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "module-clock"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"common",
|
|
||||||
"iced",
|
|
||||||
"service-datetime",
|
|
||||||
"thiserror 2.0.20",
|
|
||||||
"toml",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "modules"
|
name = "modules"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"common",
|
"common",
|
||||||
"module-clock",
|
"iced",
|
||||||
|
"serde",
|
||||||
|
"services",
|
||||||
|
"thiserror 2.0.20",
|
||||||
|
"toml",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
@@ -2105,6 +2209,12 @@ version = "1.21.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "once_cell_polyfill"
|
||||||
|
version = "1.70.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "384b8ab6d37215f3c5301a95a4accb5d64aa607f1fcb26a11b5303878451b4fe"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "orbclient"
|
name = "orbclient"
|
||||||
version = "0.3.55"
|
version = "0.3.55"
|
||||||
@@ -2539,7 +2649,7 @@ dependencies = [
|
|||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "service-datetime"
|
name = "services"
|
||||||
version = "0.1.0"
|
version = "0.1.0"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"chrono",
|
"chrono",
|
||||||
@@ -2548,15 +2658,6 @@ dependencies = [
|
|||||||
"tokio",
|
"tokio",
|
||||||
]
|
]
|
||||||
|
|
||||||
[[package]]
|
|
||||||
name = "services"
|
|
||||||
version = "0.1.0"
|
|
||||||
dependencies = [
|
|
||||||
"common",
|
|
||||||
"iced",
|
|
||||||
"service-datetime",
|
|
||||||
]
|
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "shlex"
|
name = "shlex"
|
||||||
version = "2.0.1"
|
version = "2.0.1"
|
||||||
@@ -3104,6 +3205,12 @@ version = "1.0.4"
|
|||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
checksum = "b6c140620e7ffbb22c2dee59cafe6084a59b5ffc27a8859a5f0d494b5d52b6be"
|
||||||
|
|
||||||
|
[[package]]
|
||||||
|
name = "utf8parse"
|
||||||
|
version = "0.2.2"
|
||||||
|
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||||
|
checksum = "06abde3611657adf66d383f00b093d7faecc7fa57071cce2578660c9f1010821"
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "version_check"
|
name = "version_check"
|
||||||
version = "0.9.5"
|
version = "0.9.5"
|
||||||
|
|||||||
+2
-2
@@ -1,5 +1,5 @@
|
|||||||
[workspace]
|
[workspace]
|
||||||
members = ["crates/core", "crates/common", "crates/modules", "crates/modules/clock", "crates/services", "crates/services/datetime"]
|
members = ["crates/core", "crates/common", "crates/modules", "crates/services"]
|
||||||
resolver = "2"
|
resolver = "2"
|
||||||
|
|
||||||
[workspace.package]
|
[workspace.package]
|
||||||
@@ -14,7 +14,7 @@ chrono = "0.4"
|
|||||||
toml = "1.1"
|
toml = "1.1"
|
||||||
serde = { version = "1", features = ["derive"] }
|
serde = { version = "1", features = ["derive"] }
|
||||||
thiserror = "2"
|
thiserror = "2"
|
||||||
clap = { version = "4.5", features = ["derive"] }
|
clap = { version = "4.6.6", features = ["derive", "help"] }
|
||||||
|
|
||||||
# Optimize all dependencies even in dev builds; workspace members keep dev
|
# Optimize all dependencies even in dev builds; workspace members keep dev
|
||||||
# defaults (opt-level 0) and release settings under --release.
|
# defaults (opt-level 0) and release settings under --release.
|
||||||
|
|||||||
@@ -10,3 +10,4 @@ path = "src/lib.rs"
|
|||||||
[dependencies]
|
[dependencies]
|
||||||
iced = { workspace = true }
|
iced = { workspace = true }
|
||||||
toml = { workspace = true }
|
toml = { workspace = true }
|
||||||
|
serde = { workspace = true }
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use serde::{Deserialize, Serialize};
|
||||||
|
use toml::Table;
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize)]
|
||||||
|
pub struct BarbarConfig {
|
||||||
|
pub monitor: Option<String>,
|
||||||
|
pub ups: Option<i32>, // Updates per second
|
||||||
|
pub modules: Option<Table>, // 'clock': [clock settings]
|
||||||
|
pub services: Option<Table>, // 'clockticker': [clockticker settings]
|
||||||
|
}
|
||||||
@@ -4,10 +4,12 @@
|
|||||||
//! layer-shell effects). `common` is the hub every other crate depends on,
|
//! layer-shell effects). `common` is the hub every other crate depends on,
|
||||||
//! so it must stay acyclic and pure.
|
//! so it must stay acyclic and pure.
|
||||||
|
|
||||||
|
mod config;
|
||||||
mod effect;
|
mod effect;
|
||||||
mod module;
|
mod module;
|
||||||
mod service;
|
mod service;
|
||||||
|
|
||||||
|
pub use config::BarbarConfig;
|
||||||
pub use effect::ModuleEffect;
|
pub use effect::ModuleEffect;
|
||||||
pub use module::{BarModule, ModuleMsg};
|
pub use module::{BarModule, ModuleMsg};
|
||||||
pub use service::{Service, ServiceEvent};
|
pub use service::{Service, ServiceEvent};
|
||||||
|
|||||||
@@ -12,6 +12,8 @@ iced = { workspace = true }
|
|||||||
iced_layershell = { workspace = true }
|
iced_layershell = { workspace = true }
|
||||||
tokio = { workspace = true }
|
tokio = { workspace = true }
|
||||||
chrono = { workspace = true }
|
chrono = { workspace = true }
|
||||||
|
clap = {workspace = true}
|
||||||
|
toml = {workspace =true}
|
||||||
# Modules + services
|
# Modules + services
|
||||||
modules = { path = "../modules" }
|
modules = { path = "../modules" }
|
||||||
services = { path = "../services" }
|
services = { path = "../services" }
|
||||||
|
|||||||
@@ -0,0 +1,10 @@
|
|||||||
|
use clap::Parser;
|
||||||
|
use std::path::PathBuf;
|
||||||
|
|
||||||
|
#[derive(Parser)]
|
||||||
|
pub struct Args {
|
||||||
|
#[arg(short, long)]
|
||||||
|
pub config: PathBuf,
|
||||||
|
// #[arg(long)]
|
||||||
|
// demo: bool,
|
||||||
|
}
|
||||||
+21
-2
@@ -4,11 +4,17 @@
|
|||||||
//! `wlr-layer-shell`. Optional first CLI arg = target output name.
|
//! `wlr-layer-shell`. Optional first CLI arg = target output name.
|
||||||
//! Clicking a module's button spawns a LayerShell popup anchored to it.
|
//! Clicking a module's button spawns a LayerShell popup anchored to it.
|
||||||
|
|
||||||
|
use std::fs::File;
|
||||||
|
use std::io::Read;
|
||||||
|
|
||||||
|
use clap::Parser;
|
||||||
|
use common::BarbarConfig;
|
||||||
use iced_layershell::daemon;
|
use iced_layershell::daemon;
|
||||||
use iced_layershell::reexport::Anchor;
|
use iced_layershell::reexport::Anchor;
|
||||||
use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
|
use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
|
||||||
|
|
||||||
mod app;
|
mod app;
|
||||||
|
mod args;
|
||||||
mod msg;
|
mod msg;
|
||||||
mod popup;
|
mod popup;
|
||||||
mod subscription;
|
mod subscription;
|
||||||
@@ -22,8 +28,21 @@ pub(crate) use msg::{Message, Msg};
|
|||||||
const BAR_HEIGHT: u32 = 36;
|
const BAR_HEIGHT: u32 = 36;
|
||||||
|
|
||||||
fn main() -> Result<(), iced_layershell::Error> {
|
fn main() -> Result<(), iced_layershell::Error> {
|
||||||
let start_mode = match std::env::args().nth(1) {
|
let args = args::Args::parse();
|
||||||
Some(output) => StartMode::TargetScreen(output),
|
|
||||||
|
let config_handle = File::open(args.config);
|
||||||
|
let config: BarbarConfig;
|
||||||
|
if let Ok(mut config_file) = config_handle {
|
||||||
|
let mut string = String::new();
|
||||||
|
config_file.read_to_string(&mut string).unwrap();
|
||||||
|
config = toml::from_str(&string).unwrap();
|
||||||
|
} else {
|
||||||
|
println!("cant open config file");
|
||||||
|
return Ok(());
|
||||||
|
}
|
||||||
|
|
||||||
|
let start_mode = match config.monitor {
|
||||||
|
Some(x) => StartMode::TargetScreen(x),
|
||||||
None => StartMode::Active,
|
None => StartMode::Active,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@@ -9,4 +9,8 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
common = { path = "../common" }
|
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::widget::{container, mouse_area, text};
|
||||||
use iced::{Element, Task};
|
use iced::{Element, Task};
|
||||||
|
|
||||||
use common::{BarModule, ModuleEffect, ModuleMsg, Service};
|
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).
|
/// Big-text popup size (logical px).
|
||||||
const POPUP_W: u32 = 360;
|
const POPUP_W: u32 = 360;
|
||||||
@@ -30,11 +36,21 @@ pub struct Clock {
|
|||||||
show_seconds: bool,
|
show_seconds: bool,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Deserialize, Default)]
|
||||||
|
struct ClockConfig {
|
||||||
|
#[serde(default)]
|
||||||
|
format: bool,
|
||||||
|
}
|
||||||
|
|
||||||
impl Clock {
|
impl Clock {
|
||||||
pub fn new() -> Self {
|
pub fn new(config: Option<Table>) -> Self {
|
||||||
Self {
|
let module_config = config_clock(config);
|
||||||
|
match module_config {
|
||||||
|
Some(x) => Self {
|
||||||
value: "--:--:--".to_string(),
|
value: "--:--:--".to_string(),
|
||||||
show_seconds: true,
|
show_seconds: { x.format },
|
||||||
|
},
|
||||||
|
None => Self::default(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -54,10 +70,15 @@ impl Clock {
|
|||||||
|
|
||||||
impl Default for Clock {
|
impl Default for Clock {
|
||||||
fn default() -> Self {
|
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 {
|
impl BarModule for Clock {
|
||||||
fn id(&self) -> &'static str {
|
fn id(&self) -> &'static str {
|
||||||
"clock"
|
"clock"
|
||||||
@@ -105,12 +126,4 @@ impl BarModule for Clock {
|
|||||||
fn popup_size(&self) -> Option<(u32, u32)> {
|
fn popup_size(&self) -> Option<(u32, u32)> {
|
||||||
Some((POPUP_W, POPUP_H))
|
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
|
//! Bar module registry: constructs every enabled module. Adding a module is
|
||||||
//! a new crate under `crates/modules/` plus one entry in `all()` — core
|
//! a new file under `src/` plus one entry in `all()` — core never changes.
|
||||||
//! never changes.
|
|
||||||
|
|
||||||
|
mod clock;
|
||||||
|
|
||||||
|
pub use clock::{Clock, ClockError, ClockMsg};
|
||||||
use common::BarModule;
|
use common::BarModule;
|
||||||
|
use toml::Table;
|
||||||
|
|
||||||
/// One instance of every enabled module, ready to insert by `id()`.
|
/// One instance of every enabled module, ready to insert by `id()`.
|
||||||
pub fn all() -> Vec<Box<dyn BarModule>> {
|
pub fn all(module_config: Table) -> Vec<Box<dyn BarModule>> {
|
||||||
vec![Box::new(module_clock::Clock::new())]
|
vec![Box::new(clock::Clock::new(Some(module_config)))]
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -9,5 +9,6 @@ path = "src/lib.rs"
|
|||||||
|
|
||||||
[dependencies]
|
[dependencies]
|
||||||
common = { path = "../common" }
|
common = { path = "../common" }
|
||||||
service_datetime = { package = "service-datetime", path = "datetime" }
|
|
||||||
iced = { workspace = true }
|
iced = { workspace = true }
|
||||||
|
tokio = { workspace = true }
|
||||||
|
chrono = { workspace = true }
|
||||||
|
|||||||
@@ -1,14 +0,0 @@
|
|||||||
[package]
|
|
||||||
name = "service-datetime"
|
|
||||||
version.workspace = true
|
|
||||||
edition.workspace = true
|
|
||||||
|
|
||||||
[lib]
|
|
||||||
name = "service_datetime"
|
|
||||||
path = "src/lib.rs"
|
|
||||||
|
|
||||||
[dependencies]
|
|
||||||
common = { path = "../../common" }
|
|
||||||
iced = { workspace = true }
|
|
||||||
tokio = { workspace = true }
|
|
||||||
chrono = { workspace = true }
|
|
||||||
@@ -1,28 +0,0 @@
|
|||||||
use common::Service;
|
|
||||||
|
|
||||||
/// Route-key namespace owned by this service; keys are `"clock.<kind>"`.
|
|
||||||
pub const NAMESPACE: &str = "clock.";
|
|
||||||
|
|
||||||
/// What a clock subscription wants: the tick interval and payload selector.
|
|
||||||
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
|
||||||
pub enum ClockKind {
|
|
||||||
Mins,
|
|
||||||
Seconds,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl ClockKind {
|
|
||||||
/// Route key a module subscribes under to receive this kind's ticks.
|
|
||||||
pub fn key(self) -> Service {
|
|
||||||
Service(match self {
|
|
||||||
Self::Mins => "clock.mins",
|
|
||||||
Self::Seconds => "clock.seconds",
|
|
||||||
})
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/// Clock tick payload: the value plus the kind that produced it.
|
|
||||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
|
||||||
pub struct ClockPayload {
|
|
||||||
pub kind: ClockKind,
|
|
||||||
pub value: String,
|
|
||||||
}
|
|
||||||
@@ -1,11 +0,0 @@
|
|||||||
//! Clock service: emits a `ServiceEvent` whenever a clock kind's displayed
|
|
||||||
//! value changes (minute or second rollover).
|
|
||||||
//!
|
|
||||||
//! The ticker knows nothing about the app's `Message` type; it produces
|
|
||||||
//! protocol events from `common` that core routes to subscribed modules.
|
|
||||||
|
|
||||||
mod kind;
|
|
||||||
mod ticker;
|
|
||||||
|
|
||||||
pub use kind::{ClockKind, ClockPayload, NAMESPACE};
|
|
||||||
pub use ticker::ClockTicker;
|
|
||||||
@@ -1,11 +1,42 @@
|
|||||||
|
//! Clock service: emits a `ServiceEvent` whenever a clock kind's displayed
|
||||||
|
//! value changes (minute or second rollover).
|
||||||
|
//!
|
||||||
|
//! The ticker knows nothing about the app's `Message` type; it produces
|
||||||
|
//! protocol events from `common` that core routes to subscribed modules.
|
||||||
|
|
||||||
use std::collections::HashMap;
|
use std::collections::HashMap;
|
||||||
use std::sync::Arc;
|
use std::sync::Arc;
|
||||||
|
|
||||||
use iced::{futures::SinkExt, Subscription};
|
use iced::{futures::SinkExt, Subscription};
|
||||||
|
|
||||||
use common::ServiceEvent;
|
use common::{Service, ServiceEvent};
|
||||||
|
|
||||||
use crate::kind::{ClockKind, ClockPayload};
|
/// Route-key namespace owned by this service; keys are `"clock.<kind>"`.
|
||||||
|
pub const NAMESPACE: &str = "clock.";
|
||||||
|
|
||||||
|
/// What a clock subscription wants: the tick interval and payload selector.
|
||||||
|
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
|
||||||
|
pub enum ClockKind {
|
||||||
|
Mins,
|
||||||
|
Seconds,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl ClockKind {
|
||||||
|
/// Route key a module subscribes under to receive this kind's ticks.
|
||||||
|
pub fn key(self) -> Service {
|
||||||
|
Service(match self {
|
||||||
|
Self::Mins => "clock.mins",
|
||||||
|
Self::Seconds => "clock.seconds",
|
||||||
|
})
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
/// Clock tick payload: the value plus the kind that produced it.
|
||||||
|
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||||
|
pub struct ClockPayload {
|
||||||
|
pub kind: ClockKind,
|
||||||
|
pub value: String,
|
||||||
|
}
|
||||||
|
|
||||||
/// Emits a payload only when a kind's displayed value changes (minute or
|
/// Emits a payload only when a kind's displayed value changes (minute or
|
||||||
/// second rollover). Drive `tick` once per second.
|
/// second rollover). Drive `tick` once per second.
|
||||||
@@ -1,11 +1,13 @@
|
|||||||
//! Service registry: turns a route key into the subscription that backs it.
|
//! Service registry: turns a route key into the subscription that backs it.
|
||||||
//! Adding a service is a new crate under `crates/services/` plus one arm in
|
//! Adding a service is a new file under `src/` plus one arm in the impl below
|
||||||
//! the impl below — core never changes.
|
//! — core never changes.
|
||||||
|
|
||||||
use iced::Subscription;
|
use iced::Subscription;
|
||||||
|
|
||||||
use common::{Service, ServiceEvent};
|
use common::{Service, ServiceEvent};
|
||||||
|
|
||||||
|
pub mod datetime;
|
||||||
|
|
||||||
/// Conversion from a route key to the subscription backing it.
|
/// Conversion from a route key to the subscription backing it.
|
||||||
///
|
///
|
||||||
/// An extension trait (not `impl From<Service> for Subscription<...>`) because
|
/// An extension trait (not `impl From<Service> for Subscription<...>`) because
|
||||||
@@ -18,9 +20,7 @@ pub trait IntoSubscription {
|
|||||||
impl IntoSubscription for Service {
|
impl IntoSubscription for Service {
|
||||||
fn into_subscription(self) -> Subscription<ServiceEvent> {
|
fn into_subscription(self) -> Subscription<ServiceEvent> {
|
||||||
match self.0 {
|
match self.0 {
|
||||||
key if key.starts_with(service_datetime::NAMESPACE) => {
|
key if key.starts_with(datetime::NAMESPACE) => datetime::ClockTicker::run(),
|
||||||
service_datetime::ClockTicker::run()
|
|
||||||
}
|
|
||||||
_ => Subscription::none(),
|
_ => Subscription::none(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user