a
This commit is contained in:
@@ -14,6 +14,7 @@ use iced_layershell::settings::{LayerShellSettings, Settings, StartMode};
|
|||||||
use iced_layershell::to_layer_message;
|
use iced_layershell::to_layer_message;
|
||||||
|
|
||||||
use common::{BarModule, ModuleEffect, ModuleMsg, Service as ModuleService, ServicePayloadKind};
|
use common::{BarModule, ModuleEffect, ModuleMsg, Service as ModuleService, ServicePayloadKind};
|
||||||
|
use services::IntoSubscription;
|
||||||
|
|
||||||
mod popup;
|
mod popup;
|
||||||
|
|
||||||
@@ -96,8 +97,9 @@ fn gather_subscriptions(bar: &Bar) -> Subscription<Message> {
|
|||||||
bar.routes
|
bar.routes
|
||||||
.values()
|
.values()
|
||||||
.flat_map(|wants| wants.iter())
|
.flat_map(|wants| wants.iter())
|
||||||
.map(|service| {
|
.map(|&service| {
|
||||||
services::subscription(service)
|
service
|
||||||
|
.into_subscription()
|
||||||
.map(|event| Message::Event(Msg::Subscription(event)))
|
.map(|event| Message::Event(Msg::Subscription(event)))
|
||||||
})
|
})
|
||||||
.collect::<Vec<_>>(),
|
.collect::<Vec<_>>(),
|
||||||
|
|||||||
@@ -1,14 +1,24 @@
|
|||||||
//! 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 crate under `crates/services/` plus one arm in
|
||||||
//! `subscription` — core never changes.
|
//! the impl below — core never changes.
|
||||||
|
|
||||||
use iced::Subscription;
|
use iced::Subscription;
|
||||||
|
|
||||||
use common::{Service, ServicePayloadKind};
|
use common::{Service, ServicePayloadKind};
|
||||||
|
|
||||||
/// The subscription backing a route key.
|
/// Conversion from a route key to the subscription backing it.
|
||||||
pub fn subscription(service: &Service) -> Subscription<ServicePayloadKind> {
|
///
|
||||||
match service {
|
/// An extension trait (not `impl From<Service> for Subscription<...>`) because
|
||||||
Service::Clock(_) => service_datetime::ClockTicker::run(),
|
/// both `Service` and `Subscription` are foreign to this crate — the orphan
|
||||||
|
/// rule blocks a foreign trait (`From`) on a foreign type (`Subscription`).
|
||||||
|
pub trait IntoSubscription {
|
||||||
|
fn into_subscription(self) -> Subscription<ServicePayloadKind>;
|
||||||
|
}
|
||||||
|
|
||||||
|
impl IntoSubscription for Service {
|
||||||
|
fn into_subscription(self) -> Subscription<ServicePayloadKind> {
|
||||||
|
match self {
|
||||||
|
Service::Clock(_) => service_datetime::ClockTicker::run(),
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user