msg type -> wire::push() -> update handle wire into module/service/ect
This commit is contained in:
+20
-6
@@ -1,10 +1,11 @@
|
||||
use std::collections::BTreeMap;
|
||||
use std::collections::{BTreeMap, BTreeSet};
|
||||
|
||||
use iced::window;
|
||||
|
||||
use common::{BarModule, Service};
|
||||
use common::{BarModule, Inbox, Service};
|
||||
use toml::Table;
|
||||
|
||||
/// Application state: module registry + popup bookkeeping.
|
||||
/// Application state: module registry, routing, popup bookkeeping.
|
||||
pub(crate) struct Bar {
|
||||
/// Module whose popup is open; None = closed.
|
||||
pub(crate) active_popup: Option<String>,
|
||||
@@ -14,22 +15,35 @@ pub(crate) struct Bar {
|
||||
pub(crate) popup_id: Option<window::Id>,
|
||||
/// Fan-out routing table: module id -> services it wants.
|
||||
pub(crate) routes: BTreeMap<&'static str, Vec<Service>>,
|
||||
/// One inbound mailbox per running service, keyed by route key. Modules
|
||||
/// send here (`Target::Service`) to talk to a running service.
|
||||
pub(crate) inputs: BTreeMap<&'static str, Inbox>,
|
||||
}
|
||||
|
||||
impl Bar {
|
||||
pub(crate) fn new() -> Self {
|
||||
pub(crate) fn new(modules_config_table: &Table) -> Self {
|
||||
// Registry owns construction: adding a module never edits this file.
|
||||
let modules: BTreeMap<&'static str, Box<dyn BarModule>> =
|
||||
modules::all().into_iter().map(|m| (m.id(), m)).collect();
|
||||
let routes = modules
|
||||
modules::all(modules_config_table.clone())
|
||||
.into_iter()
|
||||
.map(|m| (m.id(), m))
|
||||
.collect();
|
||||
let routes: BTreeMap<&'static str, Vec<Service>> = modules
|
||||
.iter()
|
||||
.map(|(id, module)| (*id, module.services()))
|
||||
.collect();
|
||||
// One inbox per distinct service any module wants.
|
||||
let wanted: BTreeSet<&'static str> = routes.values().flatten().map(|s| s.0).collect();
|
||||
let inputs = wanted
|
||||
.into_iter()
|
||||
.map(|key| (key, Inbox::new(key)))
|
||||
.collect();
|
||||
Self {
|
||||
active_popup: None,
|
||||
modules,
|
||||
popup_id: None,
|
||||
routes,
|
||||
inputs,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user