Open jaydevelopsstuff opened 5 days ago
Based off @amrbashir's comment here, this seems to be a misunderstanding on my end about how the frontend Tauri events API works.
Apparently using listen
will receive all events with the specified name, ignoring the EventTarget
that may have been specified when emitting it. The only way to listen to events that target the current window is either getCurrent().listen("<event>", <handler>)
or listen("<event>", <handler>, { target: getCurrent().label })
.
This is strange.
emit_to
's documentation describes itself as "[emitting] an event to all [EventTarget]'s matching the given target
," so you would not expect that this matching could be overridden on the frontend simply by using the default listen
function.
In my honest opinion, I think the current functionality of listen
is flawed. listen
, by default, should only receive global events and events targeted at the window/webview it was called in. Ignoring the targeting intended by the backend should be separate, customizable functionality (perhaps listenAny
or listenWithFilter
functions).
If there is some other reasoning behind the current design of the listening API that I have missed, please let me know.
Note: This is likely not a bug but rather strange API design
Describe the bug
In v2, the
emit_to
method is straight up dysfuntional.The docs describe its functionality as "
Emits an event to all [EventTarget]'s matching the given target
," however, it seems to completely ignore theEventTarget
requirements that are passed.Reproduction
MRE Repo
Simply build, run and observe that when you press the "
Dispatch Event to window w/ label 'main-1'
," the event listener is triggered in both windows, not justmain-1
.Expected behavior
emit_to
is expected to function exactly as its documentation describes, only emitting toEventTarget
s that have a matching label.Full
tauri info
outputStack trace
No response
Additional context
No response