fix: fire window-specific event on Window emit_to/emit_all, closes #4493 (#4498)

This commit is contained in:
Lucas Fernandes Nogueira
2022-06-28 05:34:09 -07:00
committed by GitHub
parent b857a00679
commit 643ae846d8
2 changed files with 24 additions and 1 deletions

View File

@@ -0,0 +1,5 @@
---
"tauri": patch
---
Properly fill the origin window when using `emit_to` and `emit_all` from `Window`.

View File

@@ -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
@@ -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(),