Skip to content

Commit 2a88bff

Browse files
committed
refactor: Add config accessor on Global
1 parent e18578c commit 2a88bff

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

src/global.rs

+10-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ pub use input_source::*;
1313
mod muxed_message;
1414
pub use muxed_message::*;
1515

16+
use crate::models::Config;
17+
1618
pub trait Message: Sized {
1719
type Data;
1820

@@ -66,6 +68,11 @@ impl Global {
6668
pub async fn subscribe_muxed(&self) -> broadcast::Receiver<MuxedMessage> {
6769
self.0.read().await.muxed_tx.subscribe()
6870
}
71+
72+
pub async fn read_config<T>(&self, f: impl FnOnce(&Config) -> T) -> T {
73+
let data = self.0.read().await;
74+
f(&data.config)
75+
}
6976
}
7077

7178
pub struct GlobalData {
@@ -75,10 +82,11 @@ pub struct GlobalData {
7582
next_input_source_id: usize,
7683
muxed_sources: HashMap<usize, Arc<InputSource<MuxedMessage>>>,
7784
next_muxed_source_id: usize,
85+
config: Config,
7886
}
7987

8088
impl GlobalData {
81-
pub fn new() -> Self {
89+
pub fn new(config: &Config) -> Self {
8290
let (input_tx, _) = broadcast::channel(4);
8391
let (muxed_tx, _) = broadcast::channel(4);
8492

@@ -89,6 +97,7 @@ impl GlobalData {
8997
next_input_source_id: 1,
9098
muxed_sources: Default::default(),
9199
next_muxed_source_id: 1,
100+
config: config.clone(),
92101
}
93102
}
94103

src/main.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ async fn run(opts: Opts) -> color_eyre::eyre::Result<()> {
2929
}
3030

3131
// Create the global state object
32-
let global = hyperion::global::GlobalData::new().wrap();
32+
let global = hyperion::global::GlobalData::new(&config).wrap();
3333

3434
// Initialize and spawn the devices
3535
let mut initialized_devices = 0;

0 commit comments

Comments
 (0)