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

The event module is private despite being exposed in the public API #2733

Closed
anna-is-cute opened this issue Oct 12, 2021 · 7 comments
Closed
Labels
scope: core Core packages of Tauri type: bug

Comments

@anna-is-cute
Copy link

anna-is-cute commented Oct 12, 2021

Describe the bug

The event module is private, making it impossible to reference Event or EventHandler.

To Reproduce

  1. Try to import tauri::event::{Event, EventHandler}

Expected behavior

The module is not private.

Platform and Versions (required):

Operating System - Windows, version 10.0.19042 X64
Webview2 - 94.0.992.38

Node.js environment
  Node.js - 16.11.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.57.0-nightly
  cargo - 1.57.0-nightly

App directory structure
/.git
/.idea
/node_modules
/public
/src
/src-tauri

App
  tauri.rs - 1.0.0-beta.8
  build-type - bundle
  CSP - default-src blob: data: filesystem: ws: wss: http: https: tauri: 'unsafe-eval' 'unsafe-inline' 'self' img-src: 'self'
  distDir - Set automatically by Vue CLI plugin
  devPath - Set automatically by Vue CLI plugin
  framework - Vue.js (Vue CLI)
  bundler - Webpack

Additional context

I would like to do this:

fn some_func(&self) {
    self.handle.listen_global("send-packet", listener);
}

fn listener(event: Event) {
    // ...
}

Unfortunately, there is no way for me to use the necessary type, so this is impossible.

In addition, it is impossible to store the result of listen_global to be unlistened later, since there's no way to reference EventHandler in a struct.

I wonder if it's a Rust bug that the API is even allowed to do this. It's essentially exposing a private type in the public API, which you can't do normally.

@amrbashir
Copy link
Member

try importing Event enum directly

use tauri::Event;

@anna-is-cute
Copy link
Author

anna-is-cute commented Oct 12, 2021

try importing Event enum directly

That's a different type. The type used for the listener is imported in lib.rs as EmittedEvent.

@amrbashir
Copy link
Member

I see, thanks for reporting it, we probably need to combine these two event types.

@amrbashir amrbashir added the scope: core Core packages of Tauri label Dec 21, 2021
@Chaostheorie
Copy link
Contributor

It would be nice if the struct could either be combined (maybe adding the tauri::event::Event as an enum variant to tauri::Event?) or if tauri::event::Event could be renamed in the meantime. Otherwise, it's not possible to create external functions that handle the Event that's used in event callbacks.

I will create a POC for this issue with a renamed variant in the meantime. But it may be a good idea to address this before #2060 is finished. I've read somewhere that v1.0.0 will be coming soon, so it may be good to include it there.

@amrbashir
Copy link
Member

amrbashir commented Feb 2, 2022

@Chaostheorie yeah we definitely need to fix this before v1.

I think we decided internally that Event will be RunEvent because it used in App::run and EmittedEvent will be just Event and exported.

@Chaostheorie
Copy link
Contributor

@amrbashir That sounds awesome. I'm really looking forward to the new release.

Sidenote: RunEvent is already used by the runtime. Maybe call it AppEvent or add runtime::RunEvent to Event. Though you, and the team, most likely knew that anyway.

@amrbashir
Copy link
Member

I will move the discussion to your PR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
scope: core Core packages of Tauri type: bug
Projects
None yet
Development

No branches or pull requests

3 participants