fucking something i forgot

This commit is contained in:
2026-09-12 12:24:36 +01:00
parent bdec970b62
commit 539c80cda9
20 changed files with 260 additions and 128 deletions
+2 -1
View File
@@ -9,5 +9,6 @@ path = "src/lib.rs"
[dependencies]
common = { path = "../common" }
service_datetime = { package = "service-datetime", path = "datetime" }
iced = { workspace = true }
tokio = { workspace = true }
chrono = { workspace = true }
-14
View File
@@ -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 }
-28
View File
@@ -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,
}
-11
View File
@@ -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::sync::Arc;
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
/// second rollover). Drive `tick` once per second.
+5 -5
View File
@@ -1,11 +1,13 @@
//! 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
//! the impl below — core never changes.
//! Adding a service is a new file under `src/` plus one arm in the impl below
//! — core never changes.
use iced::Subscription;
use common::{Service, ServiceEvent};
pub mod datetime;
/// Conversion from a route key to the subscription backing it.
///
/// An extension trait (not `impl From<Service> for Subscription<...>`) because
@@ -18,9 +20,7 @@ pub trait IntoSubscription {
impl IntoSubscription for Service {
fn into_subscription(self) -> Subscription<ServiceEvent> {
match self.0 {
key if key.starts_with(service_datetime::NAMESPACE) => {
service_datetime::ClockTicker::run()
}
key if key.starts_with(datetime::NAMESPACE) => datetime::ClockTicker::run(),
_ => Subscription::none(),
}
}