tauri-apps / plugins-workspace

All of the official Tauri plugins in one place!
https://tauri.app
Apache License 2.0
863 stars 242 forks source link

[docs] Can't add nfc plugin as shown in readme #1131

Open gato25 opened 6 months ago

gato25 commented 6 months ago

Describe the bug

Tried to follow https://docs.rs/crate/tauri-plugin-nfc/latest

My lib.rs

[cfg_attr(mobile, tauri::mobile_entry_point)]

pub fn run() { tauri::Builder::default() .plugin(tauri_plugin_nfc::init()) .invoke_handler(tauri::generate_handler![greet]) .run(tauri::generate_context!()) .expect("error while running tauri application"); }

But this gives an error

.plugin(tauri_plugin_nfc::init()) | ^^^^ not found in `tauri_plugin_nfc

How do i solve this ?

I tried to import use tauri_plugin_nfc::init; but still same issue.

Reproduction

No response

Expected behavior

No response

Full tauri info output

[✔] Environment
    - OS: Windows 10.0.22621 X64
    ✔ WebView2: 123.0.2420.65
    ✔ MSVC: Visual Studio Build Tools 2022
    ✔ rustc: 1.77.0 (aedd173a2 2024-03-17)
    ✔ cargo: 1.77.0 (3fe68eabf 2024-02-29)
    ✔ rustup: 1.27.0 (bbb9276d2 2024-03-08)
    ✔ Rust toolchain: stable-x86_64-pc-windows-msvc (default)
    - node: 18.16.1
    - pnpm: 8.15.4
    - npm: 9.5.1

[-] Packages
    - tauri [RUST]: 2.0.0-beta.13
    - tauri-build [RUST]: 2.0.0-beta.10
    - wry [RUST]: 0.37.0
    - tao [RUST]: 0.26.1
    - @tauri-apps/api [NPM]: 2.0.0-beta.5
    - @tauri-apps/cli [NPM]: 2.0.0-beta.9

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

Stack trace

No response

Additional context

No response

FabianLars commented 6 months ago

Thanks, we will update the readme.

Because the plugin is mobile-only you have to register it like so:

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
  tauri::Builder::default()
    .setup(|app| {
        #[cfg(mobile)]
        {
            app.handle().plugin(tauri_plugin_nfc::init())?;
        }
    })
    .invoke_handler(tauri::generate_handler![greet])
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}
cleveng commented 2 months ago

Thanks, we will update the readme.

Because the plugin is mobile-only you have to register it like so:

#[cfg_attr(mobile, tauri::mobile_entry_point)]
pub fn run() {
  tauri::Builder::default()
    .setup(|app| {
        #[cfg(mobile)]
        {
            app.handle().plugin(tauri_plugin_nfc::init())?;
        }
    })
    .invoke_handler(tauri::generate_handler![greet])
    .run(tauri::generate_context!())
    .expect("error while running tauri application");
}
{
  "$schema": "../gen/schemas/mobile-schema.json",
****

the permissions, insert permissions of array then how do i easily test it working or not