tauri icon indicating copy to clipboard operation
tauri copied to clipboard

[bug] use register_listener instead of registerListener.

Open GlosZhao opened this issue 11 months ago • 4 comments

Describe the bug

When using addPluginListener, I found that registerListener is not allowed. Upon further investigation, I discovered that addPluginListener internally uses registerListener. I believe this does not conform to Rust's naming conventions, and it should be corrected to the previous register_listener.

Reproduction

https://github.com/tauri-apps/tauri/blob/f5a59b93bfefb43ff131a7870b3c5d5e48c1ca1e/packages/api/src/core.ts#L165

Expected behavior

use register_listener instead of registerListener.

Full tauri info output

[✔] Environment
    - OS: Mac OS 15.1.1 arm64 (X64)
    ✔ Xcode Command Line Tools: installed
    ✔ rustc: 1.83.0 (90b35a623 2024-11-26) (Homebrew)
    ✔ cargo: 1.83.0
    ✔ rustup: 1.27.1 (2024-04-24)
    ✔ Rust toolchain: 
    - node: 18.20.2
    - pnpm: 9.10.0
    - npm: 10.5.0

[-] Packages
    - tauri 🦀: 2.1.1
    - tauri-build 🦀: 2.0.3
    - wry 🦀: 0.47.2
    - tao 🦀: 0.30.8
    - @tauri-apps/api : 2.0.0 (outdated, latest: 2.2.0)
    - @tauri-apps/cli : 2.0.3 (outdated, latest: 2.2.5)

[-] Plugins
    - tauri-plugin-shell 🦀: 2.0.2
    - @tauri-apps/plugin-shell : 2.0.0 (outdated, latest: 2.2.0)
    - tauri-plugin-http 🦀: 2.0.3
    - @tauri-apps/plugin-http : 2.0.0 (outdated, latest: 2.2.0)
    - tauri-plugin-os 🦀: 2.0.1
    - @tauri-apps/plugin-os : 2.0.0 (outdated, latest: 2.2.0)
    - tauri-plugin-fs 🦀: 2.0.3
    - @tauri-apps/plugin-fs : not installed!

[-] App
    - build-type: bundle
    - CSP:  xxxx
    - frontendDist: ../dist
    - devUrl: http://localhost:1420/
    - framework: Vue.js
    - bundler: Vite

Stack trace


Additional context

I am not clear about the rationale behind this change. I would appreciate it if I could receive a response explaining the reasoning.

GlosZhao avatar Jan 23 '25 17:01 GlosZhao

I believe this does not conform to Rust's naming conventions

does that matter considering that rust isn't really involved here? There's no registerListener / register_listener function in rust, only in kotlin / swift.

I am not clear about the rationale behind this change. I would appreciate it if I could receive a response explaining the reasoning.

Imo it was the less breaking way to hotfix it. ref https://github.com/tauri-apps/tauri/issues/8068 / https://github.com/tauri-apps/tauri/issues/10196


That said, i don't know why this is the only function that does not follow snake_case naming convention (even compared to its direct counterpart remove_listener) either. Maybe @lucasfernog knows if he looked into that for the PR 🤷 If this is fixable this should really wait until the next major of course.

FabianLars avatar Jan 23 '25 17:01 FabianLars

I believe this does not conform to Rust's naming conventions

does that matter considering that rust isn't really involved here? There's no registerListener / register_listener function in rust, only in kotlin / swift.

I am not clear about the rationale behind this change. I would appreciate it if I could receive a response explaining the reasoning.

Imo it was the less breaking way to hotfix it. ref #8068 / #10196

That said, i don't know why this is the only function that does not follow snake_case naming convention (even compared to its direct counterpart remove_listener) either. Maybe @lucasfernog knows if he looked into that for the PR 🤷 If this is fixable this should really wait until the next major of course.

Thank you for your response. I believe this was an unintended change. Referring to the Tauri documentation custom listeners should align with the official naming conventions. Otherwise, it could introduce unnecessary cognitive overhead for future maintenance.

GlosZhao avatar Jan 24 '25 12:01 GlosZhao

this issue do cause error. The question is:

  1. Any plugin use plugin listener, will use addPluginListener from api/core;
  2. but in plugin code, will allow-register-listener, which is not implemented by plugin itself;
  3. addPluginListener will invoke 'plugin|registerListener',which not allowed in plugin permissions, and will fail.

I don't know why it is an unintended change.

And more error may related with this issues.

  1. I use plugin-notification.
  2. I want to listen on notification event, so i use addPluginListener (which i fixed to avoid registerListener not allowed, by redefine addPluginListener).
  3. it works fine on simulator. But when i run on real Android or iOS phone, no event received by listeners.

whitemay avatar May 23 '25 03:05 whitemay

it works fine on simulator. But when i run on real Android or iOS phone, no event received by listeners.

Sounds like an issue unrelated to this one here tbh 🤔

FabianLars avatar May 23 '25 08:05 FabianLars