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