Repository: tauri-apps/tauri
File: crates/tauri/src/manager/mod.rs (Rust)

Code before:
    )?;

    listeners.emit_filter(emit_args, Some(filter))?;

    Ok(())
  }

  #[cfg_attr(
    feature = "tracing",
    tracing::instrument("app::emit::to", skip(self, target, payload), fields(target))
  )]
  pub(crate) fn emit_to<S>(
    &self,
    target: EventTarget,
    event: EventName<&str>,
    payload: EmitPayload<'_, S>,
  ) -> crate::Result<()>
  where
    S: Serialize,
  {
    #[cfg(feature = "tracing")]
    tracing::Span::current().record("target", format!("{target:?}"));

    fn filter_target(target: &EventTarget, candidate: &EventTarget) -> bool {
      match target {
        // if targeting any label, emit using emit_filter and filter labels
        EventTarget::AnyLabel { label } => match candidate {
          EventTarget::Window { label: l }
          | EventTarget::Webview { label: l }
          | EventTarget::WebviewWindow { label: l }
          | EventTarget::AnyLabel { label: l } => l == label,
          _ => false,
        },
        EventTarget::Window { label } => match candidate {
          EventTarget::AnyLabel { label: l } | EventTarget::Window { label: l } => l == label,
          _ => false,
        },
        EventTarget::Webview { label } => match candidate {
          EventTarget::AnyLabel { label: l } | EventTarget::Webview { label: l } => l == label,
          _ => false,
        },
        EventTarget::WebviewWindow { label } => match candidate {
          EventTarget::AnyLabel { label: l } | EventTarget::WebviewWindow { label: l } => {
            l == label
          }
          _ => false,
        },
        // otherwise match same target
        _ => target == candidate,
      }
    }

Review comment (suggestion):
```suggestion
        // if targeting any label, filter matching labels
```

Code after:
    )?;

    listeners.emit_filter(emit_args, Some(filter))?;

    Ok(())
  }

  #[cfg_attr(
    feature = "tracing",
    tracing::instrument("app::emit::to", skip(self, target, payload), fields(target))
  )]
  pub(crate) fn emit_to<S>(
    &self,
    target: EventTarget,
    event: EventName<&str>,
    payload: EmitPayload<'_, S>,
  ) -> crate::Result<()>
  where
    S: Serialize,
  {
    #[cfg(feature = "tracing")]
    tracing::Span::current().record("target", format!("{target:?}"));

    fn filter_target(target: &EventTarget, candidate: &EventTarget) -> bool {
      match target {
        // if targeting any label, filter matching labels
        EventTarget::AnyLabel { label } => match candidate {
          EventTarget::Window { label: l }
          | EventTarget::Webview { label: l }
          | EventTarget::WebviewWindow { label: l }
          | EventTarget::AnyLabel { label: l } => l == label,
          _ => false,
        },
        EventTarget::Window { label } => match candidate {
          EventTarget::AnyLabel { label: l } | EventTarget::Window { label: l } => l == label,
          _ => false,
        },
        EventTarget::Webview { label } => match candidate {
          EventTarget::AnyLabel { label: l } | EventTarget::Webview { label: l } => l == label,
          _ => false,
        },
        EventTarget::WebviewWindow { label } => match candidate {
          EventTarget::AnyLabel { label: l } | EventTarget::WebviewWindow { label: l } => {
            l == label
          }
          _ => false,
        },
        // otherwise match same target
        _ => target == candidate,
      }
    }