tauri-apps / tauri

Build smaller, faster, and more secure desktop and mobile applications with a web frontend.
https://tauri.app
Apache License 2.0
85.83k stars 2.6k forks source link

[bug] plugin-name.register_listener not allowed #10196

Open 501422650 opened 5 months ago

501422650 commented 5 months ago

Describe the bug

I was using Tauri to develop an APP running on the Android platform and tried to add a listener from js to listen for an Android plugin named bsp, but an error occurred while executing addPluginListener that stopped me from listening for an event called getget sent from kotlin code. image image image Line 116 - Msg: Failed to register listener: bsp.register_listener not allowed. Permissions associated with this command: / / /

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22631 X64
    ✔ WebView2: 126.0.2592.81
    ✔ MSVC: Visual Studio Community 2022
    ✔ rustc: 1.78.0 (9b00956e5 2024-04-29)
    ✔ cargo: 1.78.0 (54d8815d0 2024-03-26)
    ✔ rustup: 1.27.1 (54dd3d00f 2024-04-24)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 21.7.1
    - pnpm: 9.1.4
    - npm: 10.8.1

[-] Packages
    - tauri [RUST]: 2.0.0-beta.22
    - tauri-build [RUST]: 2.0.0-beta.17
    - wry [RUST]: 0.40.1
    - tao [RUST]: 0.28.1
    - tauri-cli [RUST]: 1.5.14
    - @tauri-apps/api [NPM]: 2.0.0-beta.13
    - @tauri-apps/cli [NPM]: 2.0.0-beta.20

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

Stack trace

No response

Additional context

No response

YLzone commented 4 months ago
  1. modify plugin directory build.rs, const COMMANDS: &[&str] = &["ping", "register_listener"]; and modify

  2. modify plugin directory permissions/default.toml [default] description = "Default permissions for the plugin" permissions = ["allow-ping", "allow-register-listener"]

  3. modify src-tauri/capabilities/default.json my plugin name is tester "permissions": [ ... "tester:default" ... ]

rtiagom commented 1 month ago

@YLzone Had a similar problem as you but I still cannot receive any events from Swift with trigger. Did you do anything different?

class RefreshControl: Plugin {
    @objc func testExample() {
       self.trigger("refresh", data: [:])
    }
}