Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

can't listen to tauri events in rust #2901

Closed
FabianLars opened this issue Nov 16, 2021 · 4 comments
Closed

can't listen to tauri events in rust #2901

FabianLars opened this issue Nov 16, 2021 · 4 comments

Comments

@FabianLars
Copy link
Member

Describe the bug

listening to tauri events (https://github.com/tauri-apps/tauri/blob/next/tooling/api/src/event.ts#L26) is not possible in rust via the .listen/.listen_global methods.
imo this is fine for window events as i feel like .on_window_event should be preferred here anyway, but unfortunately this makes the file drop and updater events completely inaccessible in rust.

Tried to look into it myself, but was to impatient to find the issue lol (aka didn't find it at first glance).
Also i'm not sure if it's actually desirable to reintroduce this way to listen to tauri events (as we have .on_(window|menu)_event hooks now).

To Reproduce

Add the following to the App Builder and drop files into the window.

.on_page_load(|window, _| {
    window.listen("tauri://file-drop", |event| {
        dbg!(event);
    });
})

Platform and Versions (required):

same behavior on current release and next branch.

Operating System - Windows, version 10.0.19043 X64
Webview2 - 95.0.1020.53

Node.js environment
Node.js - 16.13.0
@tauri-apps/cli - 1.0.0-beta.10
@tauri-apps/api - 1.0.0-beta.8

Global packages
npm - 8.0.0
yarn - 1.22.15

Rust environment
rustc - 1.56.1
cargo - 1.56.0

@lucasfernog
Copy link
Member

The Rust listeners are only triggered when an event is emitted from the webview. I guess I can change that.

@FabianLars
Copy link
Member Author

Yeah, it used to work some releases ago and the docs still mention this behavior. So either we change this or the docs 🤷

@lucasfernog
Copy link
Member

I don't think it was working before lol but I'll change the tauri://* events to also trigger the Rust listeners; changing the other way around would be a relatively large breaking change.

@FabianLars
Copy link
Member Author

Ha, you might be right. I looked through the commits of my main tauri project and i actually misremembered how i did stuff x)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants