aboutsummaryrefslogtreecommitdiff
path: root/src/file_registry.rs
diff options
context:
space:
mode:
Diffstat (limited to 'src/file_registry.rs')
-rw-r--r--src/file_registry.rs22
1 files changed, 16 insertions, 6 deletions
diff --git a/src/file_registry.rs b/src/file_registry.rs
index 6ebf986..7f062c8 100644
--- a/src/file_registry.rs
+++ b/src/file_registry.rs
@@ -5,11 +5,11 @@
use std::cell::RefCell;
use std::path::PathBuf;
-use relm4::ComponentController;
use relm4::component::Controller;
use relm4::gtk;
use crate::AppModel;
+use crate::actions::Action;
thread_local! {
/// Keeps window controllers alive for the lifetime of each window.
@@ -17,6 +17,9 @@ thread_local! {
/// Tracks which files are currently open to prevent duplicate windows.
static OPEN_FILES: RefCell<Vec<(PathBuf, gtk::Window)>> = const { RefCell::new(Vec::new()) };
+
+ /// Stores senders for all windows (including main window) to enable broadcasting.
+ static WINDOW_SENDERS: RefCell<Vec<relm4::Sender<Action>>> = const { RefCell::new(Vec::new()) };
}
/// Stores a window controller to keep it alive.
@@ -52,11 +55,18 @@ pub fn unregister_file(path: &PathBuf) {
});
}
-/// Broadcasts a message to all windows.
-pub fn broadcast_to_all_windows(message: crate::actions::Action) {
- WINDOW_CONTROLLERS.with_borrow(|controllers| {
- for controller in controllers {
- controller.sender().emit(message.clone());
+/// Registers a window's sender for broadcasting.
+pub fn register_sender(sender: relm4::Sender<Action>) {
+ WINDOW_SENDERS.with_borrow_mut(|senders| {
+ senders.push(sender);
+ });
+}
+
+/// Broadcasts a message to all windows via their registered senders.
+pub fn broadcast_to_all_windows(message: Action) {
+ WINDOW_SENDERS.with_borrow(|senders| {
+ for sender in senders {
+ sender.emit(message.clone());
}
});
}