Skip to main content

tauri_plugin_blew/
lib.rs

1use tauri::{plugin::TauriPlugin, Runtime};
2
3#[cfg(target_os = "android")]
4const PLUGIN_IDENTIFIER: &str = "org.jakebot.blew";
5
6/// Check whether Android BLE runtime permissions have been granted.
7///
8/// Always returns `true` on non-Android platforms.
9pub fn are_ble_permissions_granted() -> bool {
10    #[cfg(target_os = "android")]
11    {
12        blew::platform::android::are_ble_permissions_granted()
13    }
14    #[cfg(not(target_os = "android"))]
15    {
16        true
17    }
18}
19
20/// Check whether the app is running on an emulator or simulator.
21///
22/// Returns `true` on Android emulators and iOS simulators, `false` on real devices
23/// and non-mobile platforms.
24pub fn is_emulator() -> bool {
25    #[cfg(target_os = "android")]
26    {
27        blew::platform::android::is_emulator()
28    }
29    #[cfg(not(target_os = "android"))]
30    {
31        std::env::var("SIMULATOR_DEVICE_NAME").is_ok()
32    }
33}
34
35pub fn init<R: Runtime>() -> TauriPlugin<R> {
36    tauri::plugin::Builder::<R>::new("blew")
37        .setup(|_app, api| {
38            #[cfg(target_os = "android")]
39            {
40                let ctx = ndk_context::android_context();
41                let vm = unsafe { jni::JavaVM::from_raw(ctx.vm().cast()) };
42                blew::platform::android::init_jvm(vm);
43                api.register_android_plugin(PLUGIN_IDENTIFIER, "BlewPlugin")?;
44            }
45            let _ = api;
46            Ok(())
47        })
48        .build()
49}