react-native-ble-nitro 1.3.0 → 1.4.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (37) hide show
  1. package/README.md +32 -10
  2. package/android/src/main/java/com/margelo/nitro/co/zyke/ble/BleNitroBleManager.kt +6 -0
  3. package/ios/BleNitroBleManager.swift +84 -2
  4. package/lib/commonjs/index.d.ts +4 -188
  5. package/lib/commonjs/index.d.ts.map +1 -1
  6. package/lib/commonjs/index.js +6 -441
  7. package/lib/commonjs/index.js.map +1 -1
  8. package/lib/commonjs/manager.d.ts +204 -0
  9. package/lib/commonjs/manager.d.ts.map +1 -0
  10. package/lib/commonjs/manager.js +469 -0
  11. package/lib/commonjs/manager.js.map +1 -0
  12. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts +2 -0
  13. package/lib/commonjs/specs/NativeBleNitro.nitro.d.ts.map +1 -1
  14. package/lib/index.d.ts +4 -188
  15. package/lib/index.js +3 -436
  16. package/lib/manager.d.ts +203 -0
  17. package/lib/manager.js +455 -0
  18. package/lib/specs/NativeBleNitro.nitro.d.ts +2 -0
  19. package/nitrogen/generated/android/BleNitroOnLoad.cpp +2 -0
  20. package/nitrogen/generated/android/c++/JFunc_void_std__vector_BLEDevice_.hpp +102 -0
  21. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.cpp +6 -1
  22. package/nitrogen/generated/android/c++/JHybridNativeBleNitroSpec.hpp +1 -0
  23. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_.kt +81 -0
  24. package/nitrogen/generated/android/kotlin/com/margelo/nitro/co/zyke/ble/HybridNativeBleNitroSpec.kt +9 -0
  25. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.cpp +8 -0
  26. package/nitrogen/generated/ios/BleNitro-Swift-Cxx-Bridge.hpp +38 -16
  27. package/nitrogen/generated/ios/c++/HybridNativeBleNitroSpecSwift.hpp +15 -9
  28. package/nitrogen/generated/ios/swift/Func_void_std__vector_BLEDevice_.swift +47 -0
  29. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec.swift +1 -0
  30. package/nitrogen/generated/ios/swift/HybridNativeBleNitroSpec_cxx.swift +22 -0
  31. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.cpp +1 -0
  32. package/nitrogen/generated/shared/c++/HybridNativeBleNitroSpec.hpp +6 -5
  33. package/package.json +9 -1
  34. package/src/__tests__/index.test.ts +24 -21
  35. package/src/index.ts +24 -600
  36. package/src/manager.ts +627 -0
  37. package/src/specs/NativeBleNitro.nitro.ts +4 -0
@@ -0,0 +1,102 @@
1
+ ///
2
+ /// JFunc_void_std__vector_BLEDevice_.hpp
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ #pragma once
9
+
10
+ #include <fbjni/fbjni.h>
11
+ #include <functional>
12
+
13
+ #include "BLEDevice.hpp"
14
+ #include <vector>
15
+ #include <functional>
16
+ #include "JBLEDevice.hpp"
17
+ #include <string>
18
+ #include "ManufacturerData.hpp"
19
+ #include "JManufacturerData.hpp"
20
+ #include "ManufacturerDataEntry.hpp"
21
+ #include "JManufacturerDataEntry.hpp"
22
+ #include <NitroModules/ArrayBuffer.hpp>
23
+ #include <NitroModules/JArrayBuffer.hpp>
24
+ #include <NitroModules/JUnit.hpp>
25
+
26
+ namespace margelo::nitro::co::zyke::ble {
27
+
28
+ using namespace facebook;
29
+
30
+ /**
31
+ * Represents the Java/Kotlin callback `(restoredPeripherals: Array<BLEDevice>) -> Unit`.
32
+ * This can be passed around between C++ and Java/Kotlin.
33
+ */
34
+ struct JFunc_void_std__vector_BLEDevice_: public jni::JavaClass<JFunc_void_std__vector_BLEDevice_> {
35
+ public:
36
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice_;";
37
+
38
+ public:
39
+ /**
40
+ * Invokes the function this `JFunc_void_std__vector_BLEDevice_` instance holds through JNI.
41
+ */
42
+ void invoke(const std::vector<BLEDevice>& restoredPeripherals) const {
43
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<jni::JArrayClass<JBLEDevice>> /* restoredPeripherals */)>("invoke");
44
+ method(self(), [&]() {
45
+ size_t __size = restoredPeripherals.size();
46
+ jni::local_ref<jni::JArrayClass<JBLEDevice>> __array = jni::JArrayClass<JBLEDevice>::newArray(__size);
47
+ for (size_t __i = 0; __i < __size; __i++) {
48
+ const auto& __element = restoredPeripherals[__i];
49
+ __array->setElement(__i, *JBLEDevice::fromCpp(__element));
50
+ }
51
+ return __array;
52
+ }());
53
+ }
54
+ };
55
+
56
+ /**
57
+ * An implementation of Func_void_std__vector_BLEDevice_ that is backed by a C++ implementation (using `std::function<...>`)
58
+ */
59
+ struct JFunc_void_std__vector_BLEDevice__cxx final: public jni::HybridClass<JFunc_void_std__vector_BLEDevice__cxx, JFunc_void_std__vector_BLEDevice_> {
60
+ public:
61
+ static jni::local_ref<JFunc_void_std__vector_BLEDevice_::javaobject> fromCpp(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& func) {
62
+ return JFunc_void_std__vector_BLEDevice__cxx::newObjectCxxArgs(func);
63
+ }
64
+
65
+ public:
66
+ /**
67
+ * Invokes the C++ `std::function<...>` this `JFunc_void_std__vector_BLEDevice__cxx` instance holds.
68
+ */
69
+ void invoke_cxx(jni::alias_ref<jni::JArrayClass<JBLEDevice>> restoredPeripherals) {
70
+ _func([&]() {
71
+ size_t __size = restoredPeripherals->size();
72
+ std::vector<BLEDevice> __vector;
73
+ __vector.reserve(__size);
74
+ for (size_t __i = 0; __i < __size; __i++) {
75
+ auto __element = restoredPeripherals->getElement(__i);
76
+ __vector.push_back(__element->toCpp());
77
+ }
78
+ return __vector;
79
+ }());
80
+ }
81
+
82
+ public:
83
+ [[nodiscard]]
84
+ inline const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& getFunction() const {
85
+ return _func;
86
+ }
87
+
88
+ public:
89
+ static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/co/zyke/ble/Func_void_std__vector_BLEDevice__cxx;";
90
+ static void registerNatives() {
91
+ registerHybrid({makeNativeMethod("invoke_cxx", JFunc_void_std__vector_BLEDevice__cxx::invoke_cxx)});
92
+ }
93
+
94
+ private:
95
+ explicit JFunc_void_std__vector_BLEDevice__cxx(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& func): _func(func) { }
96
+
97
+ private:
98
+ friend HybridBase;
99
+ std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)> _func;
100
+ };
101
+
102
+ } // namespace margelo::nitro::co::zyke::ble
@@ -42,11 +42,12 @@ namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
42
42
  #include <optional>
43
43
  #include <NitroModules/Promise.hpp>
44
44
  #include <NitroModules/JPromise.hpp>
45
+ #include <functional>
46
+ #include "JFunc_void_std__vector_BLEDevice_.hpp"
45
47
  #include "ScanFilter.hpp"
46
48
  #include "JScanFilter.hpp"
47
49
  #include "AndroidScanMode.hpp"
48
50
  #include "JAndroidScanMode.hpp"
49
- #include <functional>
50
51
  #include "JFunc_void_std__optional_BLEDevice__std__optional_std__string_.hpp"
51
52
  #include "JFunc_void_bool_std__string_std__string.hpp"
52
53
  #include "JFunc_void_std__string_bool_std__string.hpp"
@@ -81,6 +82,10 @@ namespace margelo::nitro::co::zyke::ble {
81
82
 
82
83
 
83
84
  // Methods
85
+ void JHybridNativeBleNitroSpec::setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) {
86
+ static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JFunc_void_std__vector_BLEDevice_::javaobject> /* callback */)>("setRestoreStateCallback_cxx");
87
+ method(_javaPart, JFunc_void_std__vector_BLEDevice__cxx::fromCpp(callback));
88
+ }
84
89
  void JHybridNativeBleNitroSpec::startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) {
85
90
  static const auto method = javaClassStatic()->getMethod<void(jni::alias_ref<JScanFilter> /* filter */, jni::alias_ref<JFunc_void_std__optional_BLEDevice__std__optional_std__string_::javaobject> /* callback */)>("startScan_cxx");
86
91
  method(_javaPart, JScanFilter::fromCpp(filter), JFunc_void_std__optional_BLEDevice__std__optional_std__string__cxx::fromCpp(callback));
@@ -53,6 +53,7 @@ namespace margelo::nitro::co::zyke::ble {
53
53
 
54
54
  public:
55
55
  // Methods
56
+ void setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) override;
56
57
  void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) override;
57
58
  bool stopScan() override;
58
59
  bool isScanning() override;
@@ -0,0 +1,81 @@
1
+ ///
2
+ /// Func_void_std__vector_BLEDevice_.kt
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ package com.margelo.nitro.co.zyke.ble
9
+
10
+ import androidx.annotation.Keep
11
+ import com.facebook.jni.HybridData
12
+ import com.facebook.proguard.annotations.DoNotStrip
13
+ import com.margelo.nitro.core.*
14
+ import dalvik.annotation.optimization.FastNative
15
+
16
+
17
+ /**
18
+ * Represents the JavaScript callback `(restoredPeripherals: array) => void`.
19
+ * This can be either implemented in C++ (in which case it might be a callback coming from JS),
20
+ * or in Kotlin/Java (in which case it is a native callback).
21
+ */
22
+ @DoNotStrip
23
+ @Keep
24
+ @Suppress("ClassName", "RedundantUnitReturnType")
25
+ fun interface Func_void_std__vector_BLEDevice_: (Array<BLEDevice>) -> Unit {
26
+ /**
27
+ * Call the given JS callback.
28
+ * @throws Throwable if the JS function itself throws an error, or if the JS function/runtime has already been deleted.
29
+ */
30
+ @DoNotStrip
31
+ @Keep
32
+ override fun invoke(restoredPeripherals: Array<BLEDevice>): Unit
33
+ }
34
+
35
+ /**
36
+ * Represents the JavaScript callback `(restoredPeripherals: array) => void`.
37
+ * This is implemented in C++, via a `std::function<...>`.
38
+ * The callback might be coming from JS.
39
+ */
40
+ @DoNotStrip
41
+ @Keep
42
+ @Suppress(
43
+ "KotlinJniMissingFunction", "unused",
44
+ "RedundantSuppression", "RedundantUnitReturnType", "FunctionName",
45
+ "ConvertSecondaryConstructorToPrimary", "ClassName", "LocalVariableName",
46
+ )
47
+ class Func_void_std__vector_BLEDevice__cxx: Func_void_std__vector_BLEDevice_ {
48
+ @DoNotStrip
49
+ @Keep
50
+ private val mHybridData: HybridData
51
+
52
+ @DoNotStrip
53
+ @Keep
54
+ private constructor(hybridData: HybridData) {
55
+ mHybridData = hybridData
56
+ }
57
+
58
+ @DoNotStrip
59
+ @Keep
60
+ override fun invoke(restoredPeripherals: Array<BLEDevice>): Unit
61
+ = invoke_cxx(restoredPeripherals)
62
+
63
+ @FastNative
64
+ private external fun invoke_cxx(restoredPeripherals: Array<BLEDevice>): Unit
65
+ }
66
+
67
+ /**
68
+ * Represents the JavaScript callback `(restoredPeripherals: array) => void`.
69
+ * This is implemented in Java/Kotlin, via a `(Array<BLEDevice>) -> Unit`.
70
+ * The callback is always coming from native.
71
+ */
72
+ @DoNotStrip
73
+ @Keep
74
+ @Suppress("ClassName", "RedundantUnitReturnType", "unused")
75
+ class Func_void_std__vector_BLEDevice__java(private val function: (Array<BLEDevice>) -> Unit): Func_void_std__vector_BLEDevice_ {
76
+ @DoNotStrip
77
+ @Keep
78
+ override fun invoke(restoredPeripherals: Array<BLEDevice>): Unit {
79
+ return this.function(restoredPeripherals)
80
+ }
81
+ }
@@ -40,6 +40,15 @@ abstract class HybridNativeBleNitroSpec: HybridObject() {
40
40
 
41
41
 
42
42
  // Methods
43
+ abstract fun setRestoreStateCallback(callback: (restoredPeripherals: Array<BLEDevice>) -> Unit): Unit
44
+
45
+ @DoNotStrip
46
+ @Keep
47
+ private fun setRestoreStateCallback_cxx(callback: Func_void_std__vector_BLEDevice_): Unit {
48
+ val __result = setRestoreStateCallback(callback)
49
+ return __result
50
+ }
51
+
43
52
  abstract fun startScan(filter: ScanFilter, callback: (device: BLEDevice?, error: String?) -> Unit): Unit
44
53
 
45
54
  @DoNotStrip
@@ -13,6 +13,14 @@
13
13
 
14
14
  namespace margelo::nitro::co::zyke::ble::bridge::swift {
15
15
 
16
+ // pragma MARK: std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>
17
+ Func_void_std__vector_BLEDevice_ create_Func_void_std__vector_BLEDevice_(void* _Nonnull swiftClosureWrapper) {
18
+ auto swiftClosure = BleNitro::Func_void_std__vector_BLEDevice_::fromUnsafe(swiftClosureWrapper);
19
+ return [swiftClosure = std::move(swiftClosure)](const std::vector<BLEDevice>& restoredPeripherals) mutable -> void {
20
+ swiftClosure.call(restoredPeripherals);
21
+ };
22
+ }
23
+
16
24
  // pragma MARK: std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>
17
25
  Func_void_std__optional_BLEDevice__std__optional_std__string_ create_Func_void_std__optional_BLEDevice__std__optional_std__string_(void* _Nonnull swiftClosureWrapper) {
18
26
  auto swiftClosure = BleNitro::Func_void_std__optional_BLEDevice__std__optional_std__string_::fromUnsafe(swiftClosureWrapper);
@@ -54,6 +54,17 @@ namespace BleNitro { class HybridNativeBleNitroSpec_cxx; }
54
54
  */
55
55
  namespace margelo::nitro::co::zyke::ble::bridge::swift {
56
56
 
57
+ // pragma MARK: std::vector<ManufacturerDataEntry>
58
+ /**
59
+ * Specialized version of `std::vector<ManufacturerDataEntry>`.
60
+ */
61
+ using std__vector_ManufacturerDataEntry_ = std::vector<ManufacturerDataEntry>;
62
+ inline std::vector<ManufacturerDataEntry> create_std__vector_ManufacturerDataEntry_(size_t size) {
63
+ std::vector<ManufacturerDataEntry> vector;
64
+ vector.reserve(size);
65
+ return vector;
66
+ }
67
+
57
68
  // pragma MARK: std::vector<std::string>
58
69
  /**
59
70
  * Specialized version of `std::vector<std::string>`.
@@ -65,17 +76,39 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
65
76
  return vector;
66
77
  }
67
78
 
68
- // pragma MARK: std::vector<ManufacturerDataEntry>
79
+ // pragma MARK: std::vector<BLEDevice>
69
80
  /**
70
- * Specialized version of `std::vector<ManufacturerDataEntry>`.
81
+ * Specialized version of `std::vector<BLEDevice>`.
71
82
  */
72
- using std__vector_ManufacturerDataEntry_ = std::vector<ManufacturerDataEntry>;
73
- inline std::vector<ManufacturerDataEntry> create_std__vector_ManufacturerDataEntry_(size_t size) {
74
- std::vector<ManufacturerDataEntry> vector;
83
+ using std__vector_BLEDevice_ = std::vector<BLEDevice>;
84
+ inline std::vector<BLEDevice> create_std__vector_BLEDevice_(size_t size) {
85
+ std::vector<BLEDevice> vector;
75
86
  vector.reserve(size);
76
87
  return vector;
77
88
  }
78
89
 
90
+ // pragma MARK: std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>
91
+ /**
92
+ * Specialized version of `std::function<void(const std::vector<BLEDevice>&)>`.
93
+ */
94
+ using Func_void_std__vector_BLEDevice_ = std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>;
95
+ /**
96
+ * Wrapper class for a `std::function<void(const std::vector<BLEDevice>& / * restoredPeripherals * /)>`, this can be used from Swift.
97
+ */
98
+ class Func_void_std__vector_BLEDevice__Wrapper final {
99
+ public:
100
+ explicit Func_void_std__vector_BLEDevice__Wrapper(std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>&& func): _function(std::make_unique<std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>>(std::move(func))) {}
101
+ inline void call(std::vector<BLEDevice> restoredPeripherals) const {
102
+ _function->operator()(restoredPeripherals);
103
+ }
104
+ private:
105
+ std::unique_ptr<std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>> _function;
106
+ } SWIFT_NONCOPYABLE;
107
+ Func_void_std__vector_BLEDevice_ create_Func_void_std__vector_BLEDevice_(void* _Nonnull swiftClosureWrapper);
108
+ inline Func_void_std__vector_BLEDevice__Wrapper wrap_Func_void_std__vector_BLEDevice_(Func_void_std__vector_BLEDevice_ value) {
109
+ return Func_void_std__vector_BLEDevice__Wrapper(std::move(value));
110
+ }
111
+
79
112
  // pragma MARK: std::optional<BLEDevice>
80
113
  /**
81
114
  * Specialized version of `std::optional<BLEDevice>`.
@@ -116,17 +149,6 @@ namespace margelo::nitro::co::zyke::ble::bridge::swift {
116
149
  return Func_void_std__optional_BLEDevice__std__optional_std__string__Wrapper(std::move(value));
117
150
  }
118
151
 
119
- // pragma MARK: std::vector<BLEDevice>
120
- /**
121
- * Specialized version of `std::vector<BLEDevice>`.
122
- */
123
- using std__vector_BLEDevice_ = std::vector<BLEDevice>;
124
- inline std::vector<BLEDevice> create_std__vector_BLEDevice_(size_t size) {
125
- std::vector<BLEDevice> vector;
126
- vector.reserve(size);
127
- return vector;
128
- }
129
-
130
152
  // pragma MARK: std::function<void(bool /* success */, const std::string& /* deviceId */, const std::string& /* error */)>
131
153
  /**
132
154
  * Specialized version of `std::function<void(bool, const std::string&, const std::string&)>`.
@@ -12,10 +12,6 @@
12
12
  // Forward declaration of `HybridNativeBleNitroSpec_cxx` to properly resolve imports.
13
13
  namespace BleNitro { class HybridNativeBleNitroSpec_cxx; }
14
14
 
15
- // Forward declaration of `ScanFilter` to properly resolve imports.
16
- namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
17
- // Forward declaration of `AndroidScanMode` to properly resolve imports.
18
- namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
19
15
  // Forward declaration of `BLEDevice` to properly resolve imports.
20
16
  namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
21
17
  // Forward declaration of `ManufacturerData` to properly resolve imports.
@@ -26,22 +22,26 @@ namespace margelo::nitro::co::zyke::ble { struct ManufacturerDataEntry; }
26
22
  namespace NitroModules { class ArrayBuffer; }
27
23
  // Forward declaration of `ArrayBufferHolder` to properly resolve imports.
28
24
  namespace NitroModules { class ArrayBufferHolder; }
25
+ // Forward declaration of `ScanFilter` to properly resolve imports.
26
+ namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
27
+ // Forward declaration of `AndroidScanMode` to properly resolve imports.
28
+ namespace margelo::nitro::co::zyke::ble { enum class AndroidScanMode; }
29
29
  // Forward declaration of `BLEState` to properly resolve imports.
30
30
  namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
31
31
  // Forward declaration of `OperationResult` to properly resolve imports.
32
32
  namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
33
33
 
34
- #include "ScanFilter.hpp"
35
- #include <string>
36
- #include <vector>
37
- #include "AndroidScanMode.hpp"
38
34
  #include "BLEDevice.hpp"
39
- #include <optional>
35
+ #include <vector>
40
36
  #include <functional>
37
+ #include <string>
41
38
  #include "ManufacturerData.hpp"
42
39
  #include "ManufacturerDataEntry.hpp"
43
40
  #include <NitroModules/ArrayBuffer.hpp>
44
41
  #include <NitroModules/ArrayBufferHolder.hpp>
42
+ #include "ScanFilter.hpp"
43
+ #include "AndroidScanMode.hpp"
44
+ #include <optional>
45
45
  #include "BLEState.hpp"
46
46
  #include "OperationResult.hpp"
47
47
  #include <NitroModules/Promise.hpp>
@@ -87,6 +87,12 @@ namespace margelo::nitro::co::zyke::ble {
87
87
 
88
88
  public:
89
89
  // Methods
90
+ inline void setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) override {
91
+ auto __result = _swiftPart.setRestoreStateCallback(callback);
92
+ if (__result.hasError()) [[unlikely]] {
93
+ std::rethrow_exception(__result.error());
94
+ }
95
+ }
90
96
  inline void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) override {
91
97
  auto __result = _swiftPart.startScan(filter, callback);
92
98
  if (__result.hasError()) [[unlikely]] {
@@ -0,0 +1,47 @@
1
+ ///
2
+ /// Func_void_std__vector_BLEDevice_.swift
3
+ /// This file was generated by nitrogen. DO NOT MODIFY THIS FILE.
4
+ /// https://github.com/mrousavy/nitro
5
+ /// Copyright © 2025 Marc Rousavy @ Margelo
6
+ ///
7
+
8
+ import NitroModules
9
+
10
+
11
+ /**
12
+ * Wraps a Swift `(_ restoredPeripherals: [BLEDevice]) -> Void` as a class.
13
+ * This class can be used from C++, e.g. to wrap the Swift closure as a `std::function`.
14
+ */
15
+ public final class Func_void_std__vector_BLEDevice_ {
16
+ public typealias bridge = margelo.nitro.co.zyke.ble.bridge.swift
17
+
18
+ private let closure: (_ restoredPeripherals: [BLEDevice]) -> Void
19
+
20
+ public init(_ closure: @escaping (_ restoredPeripherals: [BLEDevice]) -> Void) {
21
+ self.closure = closure
22
+ }
23
+
24
+ @inline(__always)
25
+ public func call(restoredPeripherals: bridge.std__vector_BLEDevice_) -> Void {
26
+ self.closure(restoredPeripherals.map({ __item in __item }))
27
+ }
28
+
29
+ /**
30
+ * Casts this instance to a retained unsafe raw pointer.
31
+ * This acquires one additional strong reference on the object!
32
+ */
33
+ @inline(__always)
34
+ public func toUnsafe() -> UnsafeMutableRawPointer {
35
+ return Unmanaged.passRetained(self).toOpaque()
36
+ }
37
+
38
+ /**
39
+ * Casts an unsafe pointer to a `Func_void_std__vector_BLEDevice_`.
40
+ * The pointer has to be a retained opaque `Unmanaged<Func_void_std__vector_BLEDevice_>`.
41
+ * This removes one strong reference from the object!
42
+ */
43
+ @inline(__always)
44
+ public static func fromUnsafe(_ pointer: UnsafeMutableRawPointer) -> Func_void_std__vector_BLEDevice_ {
45
+ return Unmanaged<Func_void_std__vector_BLEDevice_>.fromOpaque(pointer).takeRetainedValue()
46
+ }
47
+ }
@@ -14,6 +14,7 @@ public protocol HybridNativeBleNitroSpec_protocol: HybridObject {
14
14
 
15
15
 
16
16
  // Methods
17
+ func setRestoreStateCallback(callback: @escaping (_ restoredPeripherals: [BLEDevice]) -> Void) throws -> Void
17
18
  func startScan(filter: ScanFilter, callback: @escaping (_ device: BLEDevice?, _ error: String?) -> Void) throws -> Void
18
19
  func stopScan() throws -> Bool
19
20
  func isScanning() throws -> Bool
@@ -109,6 +109,28 @@ open class HybridNativeBleNitroSpec_cxx {
109
109
 
110
110
 
111
111
  // Methods
112
+ @inline(__always)
113
+ public final func setRestoreStateCallback(callback: bridge.Func_void_std__vector_BLEDevice_) -> bridge.Result_void_ {
114
+ do {
115
+ try self.__implementation.setRestoreStateCallback(callback: { () -> ([BLEDevice]) -> Void in
116
+ let __wrappedFunction = bridge.wrap_Func_void_std__vector_BLEDevice_(callback)
117
+ return { (__restoredPeripherals: [BLEDevice]) -> Void in
118
+ __wrappedFunction.call({ () -> bridge.std__vector_BLEDevice_ in
119
+ var __vector = bridge.create_std__vector_BLEDevice_(__restoredPeripherals.count)
120
+ for __item in __restoredPeripherals {
121
+ __vector.push_back(__item)
122
+ }
123
+ return __vector
124
+ }())
125
+ }
126
+ }())
127
+ return bridge.create_Result_void_()
128
+ } catch (let __error) {
129
+ let __exceptionPtr = __error.toCpp()
130
+ return bridge.create_Result_void_(__exceptionPtr)
131
+ }
132
+ }
133
+
112
134
  @inline(__always)
113
135
  public final func startScan(filter: ScanFilter, callback: bridge.Func_void_std__optional_BLEDevice__std__optional_std__string_) -> bridge.Result_void_ {
114
136
  do {
@@ -14,6 +14,7 @@ namespace margelo::nitro::co::zyke::ble {
14
14
  HybridObject::loadHybridMethods();
15
15
  // load custom methods/properties
16
16
  registerHybrids(this, [](Prototype& prototype) {
17
+ prototype.registerHybridMethod("setRestoreStateCallback", &HybridNativeBleNitroSpec::setRestoreStateCallback);
17
18
  prototype.registerHybridMethod("startScan", &HybridNativeBleNitroSpec::startScan);
18
19
  prototype.registerHybridMethod("stopScan", &HybridNativeBleNitroSpec::stopScan);
19
20
  prototype.registerHybridMethod("isScanning", &HybridNativeBleNitroSpec::isScanning);
@@ -13,10 +13,10 @@
13
13
  #error NitroModules cannot be found! Are you sure you installed NitroModules properly?
14
14
  #endif
15
15
 
16
- // Forward declaration of `ScanFilter` to properly resolve imports.
17
- namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
18
16
  // Forward declaration of `BLEDevice` to properly resolve imports.
19
17
  namespace margelo::nitro::co::zyke::ble { struct BLEDevice; }
18
+ // Forward declaration of `ScanFilter` to properly resolve imports.
19
+ namespace margelo::nitro::co::zyke::ble { struct ScanFilter; }
20
20
  // Forward declaration of `ArrayBuffer` to properly resolve imports.
21
21
  namespace NitroModules { class ArrayBuffer; }
22
22
  // Forward declaration of `BLEState` to properly resolve imports.
@@ -24,12 +24,12 @@ namespace margelo::nitro::co::zyke::ble { enum class BLEState; }
24
24
  // Forward declaration of `OperationResult` to properly resolve imports.
25
25
  namespace margelo::nitro::co::zyke::ble { struct OperationResult; }
26
26
 
27
- #include "ScanFilter.hpp"
28
27
  #include "BLEDevice.hpp"
28
+ #include <vector>
29
+ #include <functional>
30
+ #include "ScanFilter.hpp"
29
31
  #include <optional>
30
32
  #include <string>
31
- #include <functional>
32
- #include <vector>
33
33
  #include <NitroModules/ArrayBuffer.hpp>
34
34
  #include "BLEState.hpp"
35
35
  #include "OperationResult.hpp"
@@ -66,6 +66,7 @@ namespace margelo::nitro::co::zyke::ble {
66
66
 
67
67
  public:
68
68
  // Methods
69
+ virtual void setRestoreStateCallback(const std::function<void(const std::vector<BLEDevice>& /* restoredPeripherals */)>& callback) = 0;
69
70
  virtual void startScan(const ScanFilter& filter, const std::function<void(const std::optional<BLEDevice>& /* device */, const std::optional<std::string>& /* error */)>& callback) = 0;
70
71
  virtual bool stopScan() = 0;
71
72
  virtual bool isScanning() = 0;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "react-native-ble-nitro",
3
- "version": "1.3.0",
3
+ "version": "1.4.0",
4
4
  "description": "High-performance React Native BLE library built on Nitro Modules",
5
5
  "main": "lib/index.js",
6
6
  "types": "lib/index.d.ts",
@@ -15,6 +15,14 @@
15
15
  "types": "./lib/index.d.ts",
16
16
  "default": "./src/index.ts"
17
17
  },
18
+ "./manager": {
19
+ "react-native": "./src/manager.ts",
20
+ "typescript": "./src/manager.ts",
21
+ "import": "./lib/manager.js",
22
+ "require": "./lib/commonjs/manager.js",
23
+ "types": "./lib/manager.d.ts",
24
+ "default": "./src/manager.ts"
25
+ },
18
26
  "./plugin": {
19
27
  "import": "./plugin/build/index.js",
20
28
  "require": "./plugin/build/index.js",