From 643ae846d86108b00cec748cd02a307b5badba18 Mon Sep 17 00:00:00 2001 From: Lucas Fernandes Nogueira Date: Tue, 28 Jun 2022 05:34:09 -0700 Subject: [PATCH] fix: fire window-specific event on Window emit_to/emit_all, closes #4493 (#4498) --- .changes/fix-window-emit-target.md | 5 +++++ core/tauri/src/window.rs | 20 +++++++++++++++++++- 2 files changed, 24 insertions(+), 1 deletion(-) create mode 100644 .changes/fix-window-emit-target.md diff --git a/.changes/fix-window-emit-target.md b/.changes/fix-window-emit-target.md new file mode 100644 index 000000000..005f832ef --- /dev/null +++ b/.changes/fix-window-emit-target.md @@ -0,0 +1,5 @@ +--- +"tauri": patch +--- + +Properly fill the origin window when using `emit_to` and `emit_all` from `Window`. diff --git a/core/tauri/src/window.rs b/core/tauri/src/window.rs index 143ccc110..d7d45c4ed 100644 --- a/core/tauri/src/window.rs +++ b/core/tauri/src/window.rs @@ -520,7 +520,24 @@ impl PartialEq for Window { } } -impl Manager for Window {} +impl Manager for Window { + fn emit_to( + &self, + label: &str, + event: &str, + payload: S, + ) -> crate::Result<()> { + self + .manager() + .emit_filter(event, Some(self.label()), payload, |w| label == w.label()) + } + + fn emit_all(&self, event: &str, payload: S) -> crate::Result<()> { + self + .manager() + .emit_filter(event, Some(self.label()), payload, |_| true) + } +} impl ManagerBase for Window { fn manager(&self) -> &WindowManager { &self.manager @@ -1339,6 +1356,7 @@ impl Window { source_window_label: Option<&str>, payload: S, ) -> crate::Result<()> { + println!("emit internal {:?} {:?}", event, source_window_label); self.eval(&format!( "window['{}']({{event: {}, windowLabel: {}, payload: {}}})", self.manager.event_emit_function_name(),