Skip to content

Commit ae18442

Browse files
committed
refactor: change commbus initialization
1 parent d11d9d8 commit ae18442

File tree

2 files changed

+5
-5
lines changed

2 files changed

+5
-5
lines changed

Sources/Code/WASM/navdata_updater/src/dispatcher.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use crate::download::downloader::{DownloadStatus, NavdataDownloader};
55
use msfs::{commbus::*, MSFSEvent};
66

77
pub struct Dispatcher<'a> {
8-
commbus: Option<CommBus<'a>>,
8+
commbus: CommBus<'a>,
99
downloader: Rc<NavdataDownloader>,
1010
}
1111

1212
impl<'a> Dispatcher<'a> {
1313
pub fn new() -> Self {
1414
Dispatcher {
15-
commbus: None,
15+
commbus: CommBus::new(),
1616
downloader: Rc::new(NavdataDownloader::new()),
1717
}
1818
}
@@ -27,7 +27,7 @@ impl<'a> Dispatcher<'a> {
2727
}
2828
MSFSEvent::PreKill => {
2929
// Drop commbus so that we in turn unregister the events. TODO wait for the unregister functions to be ported into the msfs-rs library
30-
self.commbus = None;
30+
CommBus::unregister_all();
3131
}
3232

3333
_ => {}
@@ -37,9 +37,9 @@ impl<'a> Dispatcher<'a> {
3737
fn handle_initialized(&mut self) {
3838
CommBus::call("NAVIGRAPH_Initialized", "", CommBusBroadcastFlags::All);
3939
let captured_downloader = self.downloader.clone();
40-
self.commbus = CommBus::register("NAVIGRAPH_DownloadNavdata", move |args| {
40+
self.commbus.register("NAVIGRAPH_DownloadNavdata", move |args| {
4141
captured_downloader.download(args)
42-
});
42+
}).expect("Failed to register NAVIGRAPH_DownloadNavdata");
4343
}
4444

4545
fn handle_update(&mut self) {

0 commit comments

Comments
 (0)