rename our subscriptions to services

This commit is contained in:
2026-09-05 14:10:29 +01:00
parent 61ed2ab85c
commit c82b470b9e
5 changed files with 27 additions and 27 deletions
+9 -9
View File
@@ -14,12 +14,12 @@ use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
use iced_layershell::to_layer_message; use iced_layershell::to_layer_message;
use crate::module::{BarModule, ModuleMsg}; use crate::module::{BarModule, ModuleMsg};
use crate::subscriptions::Subscription as ModuleSub; use crate::services::Service as ModuleService;
use crate::subscriptions::SubscriptionPayloadKind; use crate::services::ServicePayloadKind;
mod module; mod module;
mod popup; mod popup;
mod subscriptions; mod services;
/// Height of the bar in logical pixels. /// Height of the bar in logical pixels.
const BAR_HEIGHT: u32 = 36; const BAR_HEIGHT: u32 = 36;
@@ -36,8 +36,8 @@ struct Bar {
modules: BTreeMap<&'static str, Box<dyn BarModule>>, modules: BTreeMap<&'static str, Box<dyn BarModule>>,
/// Surface id of the open popup. /// Surface id of the open popup.
popup_id: Option<window::Id>, popup_id: Option<window::Id>,
/// Fan-out routing table: module id -> subscription kinds it wants. /// Fan-out routing table: module id -> services it wants.
routes: BTreeMap<&'static str, Vec<ModuleSub>>, routes: BTreeMap<&'static str, Vec<ModuleService>>,
} }
impl Bar { impl Bar {
@@ -46,7 +46,7 @@ impl Bar {
modules.insert("clock", Box::new(crate::module::clock::Clock::new())); modules.insert("clock", Box::new(crate::module::clock::Clock::new()));
let routes = modules let routes = modules
.iter() .iter()
.map(|(id, module)| (*id, module.subscriptions())) .map(|(id, module)| (*id, module.services()))
.collect(); .collect();
Self { Self {
active_popup: None, active_popup: None,
@@ -66,8 +66,8 @@ impl Bar {
pub(crate) enum Msg { pub(crate) enum Msg {
/// Routed module message; dispatch by `id`, module downcasts. /// Routed module message; dispatch by `id`, module downcasts.
Module(ModuleMsg), Module(ModuleMsg),
/// Subscription event; fan out by route key. /// Service event; fan out by route key.
Subscription(SubscriptionPayloadKind), Subscription(ServicePayloadKind),
/// The compositor confirmed a window closed. The popup is really gone. /// The compositor confirmed a window closed. The popup is really gone.
WindowClosed(window::Id), WindowClosed(window::Id),
} }
@@ -127,7 +127,7 @@ fn gather_subscriptions(bar: &Bar) -> Subscription<Message> {
let route_sub = Subscription::batch( let route_sub = Subscription::batch(
bar.routes bar.routes
.values() .values()
.flat_map(|x| x.iter().map(ModuleSub::subscription)) .flat_map(|x| x.iter().map(ModuleService::subscription))
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
); );
let close_events = window::close_events().map(|id| Message::Event(Msg::WindowClosed(id))); let close_events = window::close_events().map(|id| Message::Event(Msg::WindowClosed(id)));
+4 -4
View File
@@ -2,8 +2,8 @@ use iced::widget::{container, mouse_area, text};
use iced::{Element, Task}; use iced::{Element, Task};
use crate::module::{BarModule, ModuleMsg}; use crate::module::{BarModule, ModuleMsg};
use crate::subscriptions::clock::{ClockKind, ClockPayload}; use crate::services::clock::{ClockKind, ClockPayload};
use crate::subscriptions::Subscription; use crate::services::Service;
use crate::{Cmd, Message}; use crate::{Cmd, Message};
/// Clock module: subscribes to second ticks, renders the time in the bar. /// Clock module: subscribes to second ticks, renders the time in the bar.
@@ -88,8 +88,8 @@ impl BarModule for Clock {
} }
} }
fn subscriptions(&self) -> Vec<Subscription> { fn services(&self) -> Vec<Service> {
vec![Subscription::Clock(ClockKind::Seconds)] vec![Service::Clock(ClockKind::Seconds)]
} }
fn popup_size(&self) -> Option<(u32, u32)> { fn popup_size(&self) -> Option<(u32, u32)> {
+3 -3
View File
@@ -4,7 +4,7 @@ use std::sync::Arc;
use iced::{Element, Task}; use iced::{Element, Task};
use crate::subscriptions::Subscription; use crate::services::Service;
use crate::Message; use crate::Message;
pub mod clock; pub mod clock;
@@ -53,8 +53,8 @@ pub trait BarModule: Send {
/// Handles a routed message; may return app-level tasks (e.g. popups). /// Handles a routed message; may return app-level tasks (e.g. popups).
fn update(&mut self, msg: ModuleMsg) -> Task<Message>; fn update(&mut self, msg: ModuleMsg) -> Task<Message>;
/// What subscription kinds this module wants. /// What services this module wants.
fn subscriptions(&self) -> Vec<Subscription>; fn services(&self) -> Vec<Service>;
/// Requested popup size when it's not the generic small menu. /// Requested popup size when it's not the generic small menu.
fn popup_size(&self) -> Option<(u32, u32)> { fn popup_size(&self) -> Option<(u32, u32)> {
@@ -2,7 +2,7 @@ use std::collections::HashMap;
use iced::{futures::SinkExt, Subscription}; use iced::{futures::SinkExt, Subscription};
use crate::{subscriptions::SubscriptionPayloadKind, Message, Msg}; use crate::{services::ServicePayloadKind, Message, Msg};
/// What a clock subscription wants: the tick interval and payload selector. /// What a clock subscription wants: the tick interval and payload selector.
#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)] #[derive(Clone, Copy, PartialEq, Eq, Hash, Debug)]
@@ -42,7 +42,7 @@ impl ClockTicker {
for payload in clock.tick() { for payload in clock.tick() {
if sender if sender
.send(Message::Event(Msg::Subscription( .send(Message::Event(Msg::Subscription(
SubscriptionPayloadKind::Clock(payload), ServicePayloadKind::Clock(payload),
))) )))
.await .await
.is_err() .is_err()
@@ -2,7 +2,7 @@ use std::any::Any;
use std::sync::Arc; use std::sync::Arc;
use crate::{ use crate::{
subscriptions::clock::{ClockKind, ClockPayload, ClockTicker}, services::clock::{ClockKind, ClockPayload, ClockTicker},
Message, Message,
}; };
@@ -10,11 +10,11 @@ pub mod clock;
/// Route key a module subscribes with; `Clock(kind)` selects the ticker. /// Route key a module subscribes with; `Clock(kind)` selects the ticker.
#[derive(Clone, Copy, PartialEq, Eq)] #[derive(Clone, Copy, PartialEq, Eq)]
pub enum Subscription { pub enum Service {
Clock(ClockKind), Clock(ClockKind),
} }
impl Subscription { impl Service {
pub fn subscription(&self) -> iced::Subscription<Message> { pub fn subscription(&self) -> iced::Subscription<Message> {
match self { match self {
Self::Clock(_) => ClockTicker::run(), Self::Clock(_) => ClockTicker::run(),
@@ -22,19 +22,19 @@ impl Subscription {
} }
} }
/// A subscription event with a typed payload. The app only reads /// A service event with a typed payload. The app only reads
/// `key()` for fan-out; the consuming module downcasts the payload. /// `key()` for fan-out; the consuming module downcasts the payload.
#[derive(Clone, Debug)] #[derive(Clone, Debug)]
pub enum SubscriptionPayloadKind { pub enum ServicePayloadKind {
Clock(ClockPayload), Clock(ClockPayload),
} }
impl SubscriptionPayloadKind { impl ServicePayloadKind {
/// Route key for this event. One arm per kind — adding a subscription /// Route key for this event. One arm per kind — adding a service
/// touches only this match, never the routing code. /// touches only this match, never the routing code.
pub fn key(&self) -> Subscription { pub fn key(&self) -> Service {
match self { match self {
Self::Clock(payload) => Subscription::Clock(payload.kind), Self::Clock(payload) => Service::Clock(payload.kind),
} }
} }