tauri_plugin_bluetooth_manager/
lib.rs1use tauri::{
2 async_runtime,
3 plugin::{Builder, TauriPlugin},
4 Manager, Runtime,
5};
6
7pub use models::*;
8
9mod commands;
10mod desktop;
11mod error;
12mod models;
13
14pub use error::{Error, Result};
15
16use desktop::BluetoothManager;
17
18pub trait BluetoothManagerExt<R: Runtime> {
19 fn bluetooth_manager(&self) -> &BluetoothManager;
20}
21
22impl<R: Runtime, T: Manager<R>> BluetoothManagerExt<R> for T {
23 fn bluetooth_manager(&self) -> &BluetoothManager {
24 self.state::<BluetoothManager>().inner()
25 }
26}
27
28pub fn init<R: Runtime>() -> TauriPlugin<R> {
30 Builder::<R>::new("bluetooth-manager")
31 .invoke_handler(tauri::generate_handler![
32 commands::list_adapters,
33 commands::set_adapter_powered,
34 commands::get_adapter_state,
35 commands::start_scan,
36 commands::stop_scan,
37 commands::list_devices,
38 commands::list_paired_devices,
39 commands::connect_device,
40 commands::disconnect_device,
41 commands::get_device_info,
42 ])
43 .setup(|app_handle, api| {
44 async_runtime::block_on(desktop::init(app_handle.clone(), api))?;
45 Ok(())
46 })
47 .build()
48}