tauri-plugin-bluetooth-manager 0.1.0

A Tauri plugin to manage Bluetooth adapters and devices in Linux.
Documentation
use tauri::{
    async_runtime,
    plugin::{Builder, TauriPlugin},
    Manager, Runtime,
};

pub use models::*;

mod commands;
mod desktop;
mod error;
mod models;

pub use error::{Error, Result};

use desktop::BluetoothManager;

pub trait BluetoothManagerExt<R: Runtime> {
    fn bluetooth_manager(&self) -> &BluetoothManager;
}

impl<R: Runtime, T: Manager<R>> BluetoothManagerExt<R> for T {
    fn bluetooth_manager(&self) -> &BluetoothManager {
        self.state::<BluetoothManager>().inner()
    }
}

/// Initializes the plugin.
pub fn init<R: Runtime>() -> TauriPlugin<R> {
    Builder::<R>::new("bluetooth-manager")
        .invoke_handler(tauri::generate_handler![
            commands::list_adapters,
            commands::set_adapter_powered,
            commands::get_adapter_state,
            commands::start_scan,
            commands::stop_scan,
            commands::list_devices,
            commands::list_paired_devices,
            commands::connect_device,
            commands::disconnect_device,
            commands::get_device_info,
        ])
        .setup(|app_handle, api| {
            async_runtime::block_on(desktop::init(app_handle.clone(), api))?;
            Ok(())
        })
        .build()
}