Skip to content

Commit

Permalink
fix: fire window-specific event on Window emit_to/emit_all, closes #4493
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasfernog committed Jun 28, 2022
1 parent b857a00 commit 643ae84
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
5 changes: 5 additions & 0 deletions .changes/fix-window-emit-target.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"tauri": patch
---

Properly fill the origin window when using `emit_to` and `emit_all` from `Window`.
20 changes: 19 additions & 1 deletion core/tauri/src/window.rs
Original file line number Diff line number Diff line change
Expand Up @@ -520,7 +520,24 @@ impl<R: Runtime> PartialEq for Window<R> {
}
}

impl<R: Runtime> Manager<R> for Window<R> {}
impl<R: Runtime> Manager<R> for Window<R> {
fn emit_to<S: Serialize + Clone>(
&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<S: Serialize + Clone>(&self, event: &str, payload: S) -> crate::Result<()> {
self
.manager()
.emit_filter(event, Some(self.label()), payload, |_| true)
}
}
impl<R: Runtime> ManagerBase<R> for Window<R> {
fn manager(&self) -> &WindowManager<R> {
&self.manager
Expand Down Expand Up @@ -1339,6 +1356,7 @@ impl<R: Runtime> Window<R> {
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(),
Expand Down

0 comments on commit 643ae84

Please sign in to comment.