From 9c5d618bf89692e2cc7f2bc13a7cd12406c729f8 Mon Sep 17 00:00:00 2001 From: Olaf Wintermann Date: Fri, 29 May 2026 17:15:22 +0200 Subject: [PATCH] remove broadcast receiver from BackendHandle --- application/src/backend.rs | 6 +----- application/src/main.rs | 3 +-- application/src/notebook.rs | 7 ++++--- application/src/window.rs | 5 ++++- 4 files changed, 10 insertions(+), 11 deletions(-) diff --git a/application/src/backend.rs b/application/src/backend.rs index 500dcd9..223ef1d 100644 --- a/application/src/backend.rs +++ b/application/src/backend.rs @@ -29,8 +29,7 @@ type CmdFuture = Pin + Send>>; pub struct BackendHandle { pub backend: Arc, pub tx: tokio::sync::mpsc::UnboundedSender, - pub btx: tokio::sync::broadcast::Sender, - pub brx: tokio::sync::broadcast::Receiver + pub btx: tokio::sync::broadcast::Sender } impl Clone for BackendHandle { @@ -39,7 +38,6 @@ impl Clone for BackendHandle { backend: self.backend.clone(), tx: self.tx.clone(), btx: self.btx.clone(), - brx: self.btx.subscribe() } } } @@ -180,7 +178,6 @@ impl Backend { pub fn start(self) -> (BackendHandle, JoinHandle<()>) { let (tx, mut rx) = mpsc::unbounded_channel::(); let broadcast_tx = self.broadcast.clone(); - let broadcast_rx = broadcast_tx.subscribe(); let backend = Arc::new(self); let backend_clone = backend.clone(); @@ -228,7 +225,6 @@ impl Backend { backend: backend_clone, tx: tx, btx: broadcast_tx, - brx: broadcast_rx, }; (backend_handle, join) diff --git a/application/src/main.rs b/application/src/main.rs index 72eb8ae..6612cdc 100644 --- a/application/src/main.rs +++ b/application/src/main.rs @@ -36,7 +36,7 @@ use std::env; use entity::collection::{create_notebook_hierarchy, Node}; use ui_rs::{ui}; use ui_rs::ui::*; -use crate::backend::{Backend, BackendHandle}; +use crate::backend::{Backend, BackendHandle, BroadcastMessage}; use crate::window::*; fn main() { @@ -105,7 +105,6 @@ fn init_backend() -> Result { struct App { backend: BackendHandle, - notebooks: Vec, } diff --git a/application/src/notebook.rs b/application/src/notebook.rs index cfafe64..0eb23c8 100644 --- a/application/src/notebook.rs +++ b/application/src/notebook.rs @@ -1,3 +1,4 @@ +use std::rc::Rc; use ui_rs::{action, ui_actions, UiModel}; use ui_rs::ui::*; @@ -7,7 +8,7 @@ use crate::backend::BackendHandle; #[derive(UiModel)] pub struct Notebook { pub doc_ref: UiDocRef, - pub backend: BackendHandle, + pub backend: Rc, pub collection_id: i32, pub selected_note: Option>, @@ -21,7 +22,7 @@ impl Notebook { pub fn new(id: i32, backend: &BackendHandle) -> Self { Notebook { doc_ref: Default::default(), - backend: backend.clone(), + backend: Rc::new(backend.clone()), collection_id: id, selected_note: None, notes: Default::default() @@ -45,7 +46,7 @@ impl Notebook { if let Some(mut doc) = self.doc_ref.get_doc() { // save the note let note_proxy = current.doc_proxy(); - let backend = self.backend.clone(); + let backend = self.backend.as_ref().clone(); let collection_id = self.collection_id; note_proxy.call_mainthread(move |_doc, note|{ note.save(collection_id, &backend); diff --git a/application/src/window.rs b/application/src/window.rs index 1b90746..450dc99 100644 --- a/application/src/window.rs +++ b/application/src/window.rs @@ -40,6 +40,8 @@ pub struct MainWindow { pub obj: UiObjRef, pub backend: BackendHandle, + + pub broadcast_rx: tokio::sync::broadcast::Receiver, selected_notebook: Option>, @@ -56,6 +58,7 @@ impl MainWindow { MainWindow { obj: UiObjRef::default(), backend: app.backend.clone(), + broadcast_rx: app.backend.btx.subscribe(), selected_notebook: None, groups: Vec::new(), notebooks: UiSourceList::default() @@ -84,7 +87,7 @@ impl MainWindow { #[action] pub fn message(&mut self, _event: &ActionEvent) { - while let Ok(msg) = self.backend.brx.try_recv() { + while let Ok(msg) = self.broadcast_rx.try_recv() { match msg { BroadcastMessage::NotebookStructureUpdate(nodes) => self.update_notebook_structure(&nodes), } -- 2.47.3