From 4b31c41e123bdca863300ea66285ae879426ebcf Mon Sep 17 00:00:00 2001 From: Sebastian Wick Date: Sun, 8 Dec 2024 15:59:30 +0100 Subject: [PATCH] Connect receiving end after creating window Co-authored-by: Alyssa Ross --- src/application.rs | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/application.rs b/src/application.rs index 6475dec..36c0900 100644 --- a/src/application.rs +++ b/src/application.rs @@ -47,6 +47,7 @@ mod imp { root: ObjId, backend_shutdown_tx: oneshot::Sender<()>, tx: mpsc::Sender>, + rx: RefCell>>>, } impl AardvarkApplication { @@ -80,19 +81,14 @@ mod imp { .unwrap(); let automerge = RefCell::new(am); - let (backend_shutdown_tx, tx, mut rx) = network::run().expect("running p2p backend"); - - glib::spawn_future_local(async move { - while let Some(msg) = rx.recv().await { - println!("got {:?}", msg); - } - }); + let (backend_shutdown_tx, tx, rx) = network::run().expect("running p2p backend"); AardvarkApplication { automerge, root, backend_shutdown_tx, tx, + rx: RefCell::new(Some(rx)), window: OnceCell::new(), } } @@ -125,6 +121,14 @@ mod imp { app.imp().update_text(text); }), ); + + let mut rx = application.imp().rx.take().unwrap(); + glib::spawn_future_local(async move { + while let Some(msg) = rx.recv().await { + println!("got {:?}", msg); + } + }); + window }).clone();