react-native-nitro-cookies 1.0.3 → 1.1.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.
- package/android/src/main/cpp/cpp-adapter.cpp +4 -1
- package/ios/NitroCookies.swift +57 -49
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.cpp +31 -37
- package/nitrogen/generated/android/c++/JHybridNitroCookiesSpec.hpp +19 -22
- package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/HybridNitroCookiesSpec.kt +15 -18
- package/nitrogen/generated/android/nitrocookiesOnLoad.cpp +26 -16
- package/nitrogen/generated/android/nitrocookiesOnLoad.hpp +13 -4
- package/package.json +4 -4
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
#include <jni.h>
|
|
2
|
+
#include <fbjni/fbjni.h>
|
|
2
3
|
#include "nitrocookiesOnLoad.hpp"
|
|
3
4
|
|
|
4
5
|
JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
5
|
-
return
|
|
6
|
+
return facebook::jni::initialize(vm, [=] {
|
|
7
|
+
margelo::nitro::nitrocookies::registerAllNatives();
|
|
8
|
+
});
|
|
6
9
|
}
|
package/ios/NitroCookies.swift
CHANGED
|
@@ -187,6 +187,45 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
|
|
|
187
187
|
return url
|
|
188
188
|
}
|
|
189
189
|
|
|
190
|
+
// MARK: - WebKit Main-Thread Helpers
|
|
191
|
+
|
|
192
|
+
/**
|
|
193
|
+
* Run a WKHTTPCookieStore operation on the main thread and return a result.
|
|
194
|
+
*
|
|
195
|
+
* All WKHTTPCookieStore interactions must happen on the main thread to avoid
|
|
196
|
+
* EXC_BREAKPOINT crashes in WebKit's non-thread-safe internal data structures.
|
|
197
|
+
*/
|
|
198
|
+
@available(iOS 11.0, *)
|
|
199
|
+
private func withWebKitStore<T>(
|
|
200
|
+
_ operation: @escaping (WKHTTPCookieStore, @escaping (T) -> Void) -> Void
|
|
201
|
+
) async -> T {
|
|
202
|
+
await withCheckedContinuation { continuation in
|
|
203
|
+
DispatchQueue.main.async {
|
|
204
|
+
let store = WKWebsiteDataStore.default().httpCookieStore
|
|
205
|
+
operation(store) { result in
|
|
206
|
+
continuation.resume(returning: result)
|
|
207
|
+
}
|
|
208
|
+
}
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
|
|
212
|
+
/**
|
|
213
|
+
* Run a void WKHTTPCookieStore operation on the main thread.
|
|
214
|
+
*/
|
|
215
|
+
@available(iOS 11.0, *)
|
|
216
|
+
private func withWebKitStoreVoid(
|
|
217
|
+
_ operation: @escaping (WKHTTPCookieStore, @escaping () -> Void) -> Void
|
|
218
|
+
) async {
|
|
219
|
+
await withCheckedContinuation { (continuation: CheckedContinuation<Void, Never>) in
|
|
220
|
+
DispatchQueue.main.async {
|
|
221
|
+
let store = WKWebsiteDataStore.default().httpCookieStore
|
|
222
|
+
operation(store) {
|
|
223
|
+
continuation.resume(returning: ())
|
|
224
|
+
}
|
|
225
|
+
}
|
|
226
|
+
}
|
|
227
|
+
}
|
|
228
|
+
|
|
190
229
|
// MARK: - Synchronous Cookie Operations
|
|
191
230
|
|
|
192
231
|
/**
|
|
@@ -267,18 +306,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
|
|
|
267
306
|
if useWebKit == true {
|
|
268
307
|
// Use WKHTTPCookieStore
|
|
269
308
|
if #available(iOS 11.0, *) {
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
// For iOS 13+, WKWebsiteDataStore.default() is already @MainActor, so wrapping in MainActor.run is redundant.
|
|
273
|
-
// This workaround is safe for iOS 13+ and does not introduce any performance penalty or behavioral change,
|
|
274
|
-
// as MainActor.run is a no-op when already on the main actor. This ensures compatibility across all supported iOS versions.
|
|
275
|
-
let store = await MainActor.run {
|
|
276
|
-
WKWebsiteDataStore.default().httpCookieStore
|
|
277
|
-
}
|
|
278
|
-
await withCheckedContinuation { continuation in
|
|
279
|
-
store.setCookie(httpCookie) {
|
|
280
|
-
continuation.resume(returning: ())
|
|
281
|
-
}
|
|
309
|
+
await self.withWebKitStoreVoid { store, done in
|
|
310
|
+
store.setCookie(httpCookie) { done() }
|
|
282
311
|
}
|
|
283
312
|
return true
|
|
284
313
|
} else {
|
|
@@ -303,13 +332,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
|
|
|
303
332
|
|
|
304
333
|
if useWebKit == true {
|
|
305
334
|
if #available(iOS 11.0, *) {
|
|
306
|
-
let
|
|
307
|
-
|
|
308
|
-
}
|
|
309
|
-
let httpCookies = await withCheckedContinuation { continuation in
|
|
310
|
-
store.getAllCookies { cookies in
|
|
311
|
-
continuation.resume(returning: cookies)
|
|
312
|
-
}
|
|
335
|
+
let httpCookies: [HTTPCookie] = await self.withWebKitStore { store, done in
|
|
336
|
+
store.getAllCookies { cookies in done(cookies) }
|
|
313
337
|
}
|
|
314
338
|
let filteredCookies = httpCookies.filter { cookie in
|
|
315
339
|
self.isMatchingDomain(cookieDomain: cookie.domain,
|
|
@@ -339,20 +363,16 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
|
|
|
339
363
|
return Promise.async {
|
|
340
364
|
if useWebKit == true {
|
|
341
365
|
if #available(iOS 11.0, *) {
|
|
342
|
-
let
|
|
343
|
-
|
|
366
|
+
let cookies: [HTTPCookie] = await self.withWebKitStore { store, done in
|
|
367
|
+
store.getAllCookies { cookies in done(cookies) }
|
|
344
368
|
}
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
for cookie in cookies {
|
|
351
|
-
await withCheckedContinuation { continuation in
|
|
352
|
-
store.delete(cookie) {
|
|
353
|
-
continuation.resume(returning: ())
|
|
354
|
-
}
|
|
369
|
+
await self.withWebKitStoreVoid { store, done in
|
|
370
|
+
let group = DispatchGroup()
|
|
371
|
+
for cookie in cookies {
|
|
372
|
+
group.enter()
|
|
373
|
+
store.delete(cookie) { group.leave() }
|
|
355
374
|
}
|
|
375
|
+
group.notify(queue: .main) { done() }
|
|
356
376
|
}
|
|
357
377
|
return true
|
|
358
378
|
} else {
|
|
@@ -416,13 +436,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
|
|
|
416
436
|
return Promise.async {
|
|
417
437
|
if useWebKit == true {
|
|
418
438
|
if #available(iOS 11.0, *) {
|
|
419
|
-
let
|
|
420
|
-
|
|
421
|
-
}
|
|
422
|
-
let cookies = await withCheckedContinuation { continuation in
|
|
423
|
-
store.getAllCookies { cookies in
|
|
424
|
-
continuation.resume(returning: cookies)
|
|
425
|
-
}
|
|
439
|
+
let cookies: [HTTPCookie] = await self.withWebKitStore { store, done in
|
|
440
|
+
store.getAllCookies { cookies in done(cookies) }
|
|
426
441
|
}
|
|
427
442
|
return cookies.map { self.createCookieData(from: $0) }
|
|
428
443
|
} else {
|
|
@@ -446,13 +461,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
|
|
|
446
461
|
|
|
447
462
|
if useWebKit == true {
|
|
448
463
|
if #available(iOS 11.0, *) {
|
|
449
|
-
let
|
|
450
|
-
|
|
451
|
-
}
|
|
452
|
-
let cookies = await withCheckedContinuation { continuation in
|
|
453
|
-
store.getAllCookies { cookies in
|
|
454
|
-
continuation.resume(returning: cookies)
|
|
455
|
-
}
|
|
464
|
+
let cookies: [HTTPCookie] = await self.withWebKitStore { store, done in
|
|
465
|
+
store.getAllCookies { cookies in done(cookies) }
|
|
456
466
|
}
|
|
457
467
|
let matchingCookie = cookies.first { cookie in
|
|
458
468
|
cookie.name == name &&
|
|
@@ -461,10 +471,8 @@ public class HybridNitroCookies: HybridNitroCookiesSpec {
|
|
|
461
471
|
}
|
|
462
472
|
|
|
463
473
|
if let cookie = matchingCookie {
|
|
464
|
-
await
|
|
465
|
-
store.delete(cookie) {
|
|
466
|
-
continuation.resume(returning: ())
|
|
467
|
-
}
|
|
474
|
+
await self.withWebKitStoreVoid { store, done in
|
|
475
|
+
store.delete(cookie) { done() }
|
|
468
476
|
}
|
|
469
477
|
return true
|
|
470
478
|
} else {
|
|
@@ -21,37 +21,31 @@ namespace margelo::nitro::nitrocookies { struct Cookie; }
|
|
|
21
21
|
|
|
22
22
|
namespace margelo::nitro::nitrocookies {
|
|
23
23
|
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
});
|
|
24
|
+
std::shared_ptr<JHybridNitroCookiesSpec> JHybridNitroCookiesSpec::JavaPart::getJHybridNitroCookiesSpec() {
|
|
25
|
+
auto hybridObject = JHybridObject::JavaPart::getJHybridObject();
|
|
26
|
+
auto castHybridObject = std::dynamic_pointer_cast<JHybridNitroCookiesSpec>(hybridObject);
|
|
27
|
+
if (castHybridObject == nullptr) [[unlikely]] {
|
|
28
|
+
throw std::runtime_error("Failed to downcast JHybridObject to JHybridNitroCookiesSpec!");
|
|
29
|
+
}
|
|
30
|
+
return castHybridObject;
|
|
32
31
|
}
|
|
33
32
|
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
return method(_javaPart);
|
|
33
|
+
jni::local_ref<JHybridNitroCookiesSpec::CxxPart::jhybriddata> JHybridNitroCookiesSpec::CxxPart::initHybrid(jni::alias_ref<jhybridobject> jThis) {
|
|
34
|
+
return makeCxxInstance(jThis);
|
|
37
35
|
}
|
|
38
36
|
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
37
|
+
std::shared_ptr<JHybridObject> JHybridNitroCookiesSpec::CxxPart::createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) {
|
|
38
|
+
auto castJavaPart = jni::dynamic_ref_cast<JHybridNitroCookiesSpec::JavaPart>(javaPart);
|
|
39
|
+
if (castJavaPart == nullptr) [[unlikely]] {
|
|
40
|
+
throw std::runtime_error("Failed to cast JHybridObject::JavaPart to JHybridNitroCookiesSpec::JavaPart!");
|
|
42
41
|
}
|
|
43
|
-
return
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
void JHybridNitroCookiesSpec::dispose() noexcept {
|
|
47
|
-
static const auto method = javaClassStatic()->getMethod<void()>("dispose");
|
|
48
|
-
method(_javaPart);
|
|
42
|
+
return std::make_shared<JHybridNitroCookiesSpec>(castJavaPart);
|
|
49
43
|
}
|
|
50
44
|
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
45
|
+
void JHybridNitroCookiesSpec::CxxPart::registerNatives() {
|
|
46
|
+
registerHybrid({
|
|
47
|
+
makeNativeMethod("initHybrid", JHybridNitroCookiesSpec::CxxPart::initHybrid),
|
|
48
|
+
});
|
|
55
49
|
}
|
|
56
50
|
|
|
57
51
|
// Properties
|
|
@@ -59,7 +53,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
59
53
|
|
|
60
54
|
// Methods
|
|
61
55
|
std::vector<Cookie> JHybridNitroCookiesSpec::getSync(const std::string& url) {
|
|
62
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JCookie>>(jni::alias_ref<jni::JString> /* url */)>("getSync");
|
|
56
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<jni::JArrayClass<JCookie>>(jni::alias_ref<jni::JString> /* url */)>("getSync");
|
|
63
57
|
auto __result = method(_javaPart, jni::make_jstring(url));
|
|
64
58
|
return [&]() {
|
|
65
59
|
size_t __size = __result->size();
|
|
@@ -73,22 +67,22 @@ namespace margelo::nitro::nitrocookies {
|
|
|
73
67
|
}();
|
|
74
68
|
}
|
|
75
69
|
bool JHybridNitroCookiesSpec::setSync(const std::string& url, const Cookie& cookie) {
|
|
76
|
-
static const auto method = javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<JCookie> /* cookie */)>("setSync");
|
|
70
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<JCookie> /* cookie */)>("setSync");
|
|
77
71
|
auto __result = method(_javaPart, jni::make_jstring(url), JCookie::fromCpp(cookie));
|
|
78
72
|
return static_cast<bool>(__result);
|
|
79
73
|
}
|
|
80
74
|
bool JHybridNitroCookiesSpec::setFromResponseSync(const std::string& url, const std::string& value) {
|
|
81
|
-
static const auto method = javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* value */)>("setFromResponseSync");
|
|
75
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* value */)>("setFromResponseSync");
|
|
82
76
|
auto __result = method(_javaPart, jni::make_jstring(url), jni::make_jstring(value));
|
|
83
77
|
return static_cast<bool>(__result);
|
|
84
78
|
}
|
|
85
79
|
bool JHybridNitroCookiesSpec::clearByNameSync(const std::string& url, const std::string& name) {
|
|
86
|
-
static const auto method = javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* name */)>("clearByNameSync");
|
|
80
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jboolean(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* name */)>("clearByNameSync");
|
|
87
81
|
auto __result = method(_javaPart, jni::make_jstring(url), jni::make_jstring(name));
|
|
88
82
|
return static_cast<bool>(__result);
|
|
89
83
|
}
|
|
90
84
|
std::shared_ptr<Promise<bool>> JHybridNitroCookiesSpec::set(const std::string& url, const Cookie& cookie, std::optional<bool> useWebKit) {
|
|
91
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<JCookie> /* cookie */, jni::alias_ref<jni::JBoolean> /* useWebKit */)>("set");
|
|
85
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<JCookie> /* cookie */, jni::alias_ref<jni::JBoolean> /* useWebKit */)>("set");
|
|
92
86
|
auto __result = method(_javaPart, jni::make_jstring(url), JCookie::fromCpp(cookie), useWebKit.has_value() ? jni::JBoolean::valueOf(useWebKit.value()) : nullptr);
|
|
93
87
|
return [&]() {
|
|
94
88
|
auto __promise = Promise<bool>::create();
|
|
@@ -104,7 +98,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
104
98
|
}();
|
|
105
99
|
}
|
|
106
100
|
std::shared_ptr<Promise<std::vector<Cookie>>> JHybridNitroCookiesSpec::get(const std::string& url, std::optional<bool> useWebKit) {
|
|
107
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JBoolean> /* useWebKit */)>("get");
|
|
101
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JBoolean> /* useWebKit */)>("get");
|
|
108
102
|
auto __result = method(_javaPart, jni::make_jstring(url), useWebKit.has_value() ? jni::JBoolean::valueOf(useWebKit.value()) : nullptr);
|
|
109
103
|
return [&]() {
|
|
110
104
|
auto __promise = Promise<std::vector<Cookie>>::create();
|
|
@@ -129,7 +123,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
129
123
|
}();
|
|
130
124
|
}
|
|
131
125
|
std::shared_ptr<Promise<bool>> JHybridNitroCookiesSpec::clearAll(std::optional<bool> useWebKit) {
|
|
132
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JBoolean> /* useWebKit */)>("clearAll");
|
|
126
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JBoolean> /* useWebKit */)>("clearAll");
|
|
133
127
|
auto __result = method(_javaPart, useWebKit.has_value() ? jni::JBoolean::valueOf(useWebKit.value()) : nullptr);
|
|
134
128
|
return [&]() {
|
|
135
129
|
auto __promise = Promise<bool>::create();
|
|
@@ -145,7 +139,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
145
139
|
}();
|
|
146
140
|
}
|
|
147
141
|
std::shared_ptr<Promise<bool>> JHybridNitroCookiesSpec::setFromResponse(const std::string& url, const std::string& value) {
|
|
148
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* value */)>("setFromResponse");
|
|
142
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* value */)>("setFromResponse");
|
|
149
143
|
auto __result = method(_javaPart, jni::make_jstring(url), jni::make_jstring(value));
|
|
150
144
|
return [&]() {
|
|
151
145
|
auto __promise = Promise<bool>::create();
|
|
@@ -161,7 +155,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
161
155
|
}();
|
|
162
156
|
}
|
|
163
157
|
std::shared_ptr<Promise<std::vector<Cookie>>> JHybridNitroCookiesSpec::getFromResponse(const std::string& url) {
|
|
164
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */)>("getFromResponse");
|
|
158
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */)>("getFromResponse");
|
|
165
159
|
auto __result = method(_javaPart, jni::make_jstring(url));
|
|
166
160
|
return [&]() {
|
|
167
161
|
auto __promise = Promise<std::vector<Cookie>>::create();
|
|
@@ -186,7 +180,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
186
180
|
}();
|
|
187
181
|
}
|
|
188
182
|
std::shared_ptr<Promise<std::vector<Cookie>>> JHybridNitroCookiesSpec::getAll(std::optional<bool> useWebKit) {
|
|
189
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JBoolean> /* useWebKit */)>("getAll");
|
|
183
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JBoolean> /* useWebKit */)>("getAll");
|
|
190
184
|
auto __result = method(_javaPart, useWebKit.has_value() ? jni::JBoolean::valueOf(useWebKit.value()) : nullptr);
|
|
191
185
|
return [&]() {
|
|
192
186
|
auto __promise = Promise<std::vector<Cookie>>::create();
|
|
@@ -211,7 +205,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
211
205
|
}();
|
|
212
206
|
}
|
|
213
207
|
std::shared_ptr<Promise<bool>> JHybridNitroCookiesSpec::clearByName(const std::string& url, const std::string& name, std::optional<bool> useWebKit) {
|
|
214
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* name */, jni::alias_ref<jni::JBoolean> /* useWebKit */)>("clearByName");
|
|
208
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>(jni::alias_ref<jni::JString> /* url */, jni::alias_ref<jni::JString> /* name */, jni::alias_ref<jni::JBoolean> /* useWebKit */)>("clearByName");
|
|
215
209
|
auto __result = method(_javaPart, jni::make_jstring(url), jni::make_jstring(name), useWebKit.has_value() ? jni::JBoolean::valueOf(useWebKit.value()) : nullptr);
|
|
216
210
|
return [&]() {
|
|
217
211
|
auto __promise = Promise<bool>::create();
|
|
@@ -227,7 +221,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
227
221
|
}();
|
|
228
222
|
}
|
|
229
223
|
std::shared_ptr<Promise<void>> JHybridNitroCookiesSpec::flush() {
|
|
230
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("flush");
|
|
224
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("flush");
|
|
231
225
|
auto __result = method(_javaPart);
|
|
232
226
|
return [&]() {
|
|
233
227
|
auto __promise = Promise<void>::create();
|
|
@@ -242,7 +236,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
242
236
|
}();
|
|
243
237
|
}
|
|
244
238
|
std::shared_ptr<Promise<bool>> JHybridNitroCookiesSpec::removeSessionCookies() {
|
|
245
|
-
static const auto method = javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("removeSessionCookies");
|
|
239
|
+
static const auto method = _javaPart->javaClassStatic()->getMethod<jni::local_ref<JPromise::javaobject>()>("removeSessionCookies");
|
|
246
240
|
auto __result = method(_javaPart);
|
|
247
241
|
return [&]() {
|
|
248
242
|
auto __promise = Promise<bool>::create();
|
|
@@ -18,34 +18,33 @@ namespace margelo::nitro::nitrocookies {
|
|
|
18
18
|
|
|
19
19
|
using namespace facebook;
|
|
20
20
|
|
|
21
|
-
class JHybridNitroCookiesSpec: public
|
|
22
|
-
public virtual HybridNitroCookiesSpec {
|
|
21
|
+
class JHybridNitroCookiesSpec: public virtual HybridNitroCookiesSpec, public virtual JHybridObject {
|
|
23
22
|
public:
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
HybridBase
|
|
33
|
-
|
|
23
|
+
struct JavaPart: public jni::JavaClass<JavaPart, JHybridObject::JavaPart> {
|
|
24
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrocookies/HybridNitroCookiesSpec;";
|
|
25
|
+
std::shared_ptr<JHybridNitroCookiesSpec> getJHybridNitroCookiesSpec();
|
|
26
|
+
};
|
|
27
|
+
struct CxxPart: public jni::HybridClass<CxxPart, JHybridObject::CxxPart> {
|
|
28
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrocookies/HybridNitroCookiesSpec$CxxPart;";
|
|
29
|
+
static jni::local_ref<jhybriddata> initHybrid(jni::alias_ref<jhybridobject> jThis);
|
|
30
|
+
static void registerNatives();
|
|
31
|
+
using HybridBase::HybridBase;
|
|
32
|
+
protected:
|
|
33
|
+
std::shared_ptr<JHybridObject> createHybridObject(const jni::local_ref<JHybridObject::JavaPart>& javaPart) override;
|
|
34
|
+
};
|
|
34
35
|
|
|
35
36
|
public:
|
|
37
|
+
explicit JHybridNitroCookiesSpec(const jni::local_ref<JHybridNitroCookiesSpec::JavaPart>& javaPart):
|
|
38
|
+
HybridObject(HybridNitroCookiesSpec::TAG),
|
|
39
|
+
JHybridObject(javaPart),
|
|
40
|
+
_javaPart(jni::make_global(javaPart)) {}
|
|
36
41
|
~JHybridNitroCookiesSpec() override {
|
|
37
42
|
// Hermes GC can destroy JS objects on a non-JNI Thread.
|
|
38
43
|
jni::ThreadScope::WithClassLoader([&] { _javaPart.reset(); });
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
public:
|
|
42
|
-
|
|
43
|
-
bool equals(const std::shared_ptr<HybridObject>& other) override;
|
|
44
|
-
void dispose() noexcept override;
|
|
45
|
-
std::string toString() override;
|
|
46
|
-
|
|
47
|
-
public:
|
|
48
|
-
inline const jni::global_ref<JHybridNitroCookiesSpec::javaobject>& getJavaPart() const noexcept {
|
|
47
|
+
inline const jni::global_ref<JHybridNitroCookiesSpec::JavaPart>& getJavaPart() const noexcept {
|
|
49
48
|
return _javaPart;
|
|
50
49
|
}
|
|
51
50
|
|
|
@@ -70,9 +69,7 @@ namespace margelo::nitro::nitrocookies {
|
|
|
70
69
|
std::shared_ptr<Promise<bool>> removeSessionCookies() override;
|
|
71
70
|
|
|
72
71
|
private:
|
|
73
|
-
|
|
74
|
-
using HybridBase::HybridBase;
|
|
75
|
-
jni::global_ref<JHybridNitroCookiesSpec::javaobject> _javaPart;
|
|
72
|
+
jni::global_ref<JHybridNitroCookiesSpec::JavaPart> _javaPart;
|
|
76
73
|
};
|
|
77
74
|
|
|
78
75
|
} // namespace margelo::nitro::nitrocookies
|
package/nitrogen/generated/android/kotlin/com/margelo/nitro/nitrocookies/HybridNitroCookiesSpec.kt
CHANGED
|
@@ -25,23 +25,6 @@ import com.margelo.nitro.core.HybridObject
|
|
|
25
25
|
"LocalVariableName", "PropertyName", "PrivatePropertyName", "FunctionName"
|
|
26
26
|
)
|
|
27
27
|
abstract class HybridNitroCookiesSpec: HybridObject() {
|
|
28
|
-
@DoNotStrip
|
|
29
|
-
private var mHybridData: HybridData = initHybrid()
|
|
30
|
-
|
|
31
|
-
init {
|
|
32
|
-
super.updateNative(mHybridData)
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
override fun updateNative(hybridData: HybridData) {
|
|
36
|
-
mHybridData = hybridData
|
|
37
|
-
super.updateNative(hybridData)
|
|
38
|
-
}
|
|
39
|
-
|
|
40
|
-
// Default implementation of `HybridObject.toString()`
|
|
41
|
-
override fun toString(): String {
|
|
42
|
-
return "[HybridObject NitroCookies]"
|
|
43
|
-
}
|
|
44
|
-
|
|
45
28
|
// Properties
|
|
46
29
|
|
|
47
30
|
|
|
@@ -98,7 +81,21 @@ abstract class HybridNitroCookiesSpec: HybridObject() {
|
|
|
98
81
|
@Keep
|
|
99
82
|
abstract fun removeSessionCookies(): Promise<Boolean>
|
|
100
83
|
|
|
101
|
-
|
|
84
|
+
// Default implementation of `HybridObject.toString()`
|
|
85
|
+
override fun toString(): String {
|
|
86
|
+
return "[HybridObject NitroCookies]"
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
// C++ backing class
|
|
90
|
+
@DoNotStrip
|
|
91
|
+
@Keep
|
|
92
|
+
protected open class CxxPart(javaPart: HybridNitroCookiesSpec): HybridObject.CxxPart(javaPart) {
|
|
93
|
+
// C++ JHybridNitroCookiesSpec::CxxPart::initHybrid(...)
|
|
94
|
+
external override fun initHybrid(): HybridData
|
|
95
|
+
}
|
|
96
|
+
override fun createCxxPart(): CxxPart {
|
|
97
|
+
return CxxPart(this)
|
|
98
|
+
}
|
|
102
99
|
|
|
103
100
|
companion object {
|
|
104
101
|
protected const val TAG = "HybridNitroCookiesSpec"
|
|
@@ -21,24 +21,34 @@
|
|
|
21
21
|
namespace margelo::nitro::nitrocookies {
|
|
22
22
|
|
|
23
23
|
int initialize(JavaVM* vm) {
|
|
24
|
+
return facebook::jni::initialize(vm, []() {
|
|
25
|
+
::margelo::nitro::nitrocookies::registerAllNatives();
|
|
26
|
+
});
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
struct JHybridNitroCookiesSpecImpl: public jni::JavaClass<JHybridNitroCookiesSpecImpl, JHybridNitroCookiesSpec::JavaPart> {
|
|
30
|
+
static auto constexpr kJavaDescriptor = "Lcom/margelo/nitro/nitrocookies/NitroCookies;";
|
|
31
|
+
static std::shared_ptr<JHybridNitroCookiesSpec> create() {
|
|
32
|
+
static auto constructorFn = javaClassStatic()->getConstructor<JHybridNitroCookiesSpecImpl::javaobject()>();
|
|
33
|
+
jni::local_ref<JHybridNitroCookiesSpec::JavaPart> javaPart = javaClassStatic()->newObject(constructorFn);
|
|
34
|
+
return javaPart->getJHybridNitroCookiesSpec();
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
void registerAllNatives() {
|
|
24
39
|
using namespace margelo::nitro;
|
|
25
40
|
using namespace margelo::nitro::nitrocookies;
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
auto instance = object.create();
|
|
38
|
-
return instance->cthis()->shared();
|
|
39
|
-
}
|
|
40
|
-
);
|
|
41
|
-
});
|
|
41
|
+
|
|
42
|
+
// Register native JNI methods
|
|
43
|
+
margelo::nitro::nitrocookies::JHybridNitroCookiesSpec::CxxPart::registerNatives();
|
|
44
|
+
|
|
45
|
+
// Register Nitro Hybrid Objects
|
|
46
|
+
HybridObjectRegistry::registerHybridObjectConstructor(
|
|
47
|
+
"NitroCookies",
|
|
48
|
+
[]() -> std::shared_ptr<HybridObject> {
|
|
49
|
+
return JHybridNitroCookiesSpecImpl::create();
|
|
50
|
+
}
|
|
51
|
+
);
|
|
42
52
|
}
|
|
43
53
|
|
|
44
54
|
} // namespace margelo::nitro::nitrocookies
|
|
@@ -6,20 +6,29 @@
|
|
|
6
6
|
///
|
|
7
7
|
|
|
8
8
|
#include <jni.h>
|
|
9
|
+
#include <functional>
|
|
9
10
|
#include <NitroModules/NitroDefines.hpp>
|
|
10
11
|
|
|
11
12
|
namespace margelo::nitro::nitrocookies {
|
|
12
13
|
|
|
14
|
+
[[deprecated("Use registerNatives() instead.")]]
|
|
15
|
+
int initialize(JavaVM* vm);
|
|
16
|
+
|
|
13
17
|
/**
|
|
14
|
-
*
|
|
15
|
-
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`)
|
|
18
|
+
* Register the native (C++) part of nitrocookies, and autolinks all Hybrid Objects.
|
|
19
|
+
* Call this in your `JNI_OnLoad` function (probably inside `cpp-adapter.cpp`),
|
|
20
|
+
* inside a `facebook::jni::initialize(vm, ...)` call.
|
|
16
21
|
* Example:
|
|
17
22
|
* ```cpp (cpp-adapter.cpp)
|
|
18
23
|
* JNIEXPORT jint JNICALL JNI_OnLoad(JavaVM* vm, void*) {
|
|
19
|
-
* return
|
|
24
|
+
* return facebook::jni::initialize(vm, []() {
|
|
25
|
+
* // register all nitrocookies HybridObjects
|
|
26
|
+
* margelo::nitro::nitrocookies::registerNatives();
|
|
27
|
+
* // any other custom registrations go here.
|
|
28
|
+
* });
|
|
20
29
|
* }
|
|
21
30
|
* ```
|
|
22
31
|
*/
|
|
23
|
-
|
|
32
|
+
void registerAllNatives();
|
|
24
33
|
|
|
25
34
|
} // namespace margelo::nitro::nitrocookies
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "react-native-nitro-cookies",
|
|
3
|
-
"version": "1.0
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "Fetch, Get Cookies 🍪 at the Speed of Nitro",
|
|
5
5
|
"main": "./lib/module/index.js",
|
|
6
6
|
"types": "./lib/typescript/src/index.d.ts",
|
|
@@ -77,17 +77,17 @@
|
|
|
77
77
|
"@types/react": "19.2.14",
|
|
78
78
|
"del-cli": "6.0.0",
|
|
79
79
|
"jest": "30.2.0",
|
|
80
|
-
"nitrogen": "0.
|
|
80
|
+
"nitrogen": "0.35.0",
|
|
81
81
|
"react": "19.2.3",
|
|
82
82
|
"react-native": "0.84.0",
|
|
83
83
|
"react-native-builder-bob": "0.40.18",
|
|
84
|
-
"react-native-nitro-modules": "0.
|
|
84
|
+
"react-native-nitro-modules": "0.35.0",
|
|
85
85
|
"typescript": "5.9.3"
|
|
86
86
|
},
|
|
87
87
|
"peerDependencies": {
|
|
88
88
|
"react": "*",
|
|
89
89
|
"react-native": "*",
|
|
90
|
-
"react-native-nitro-modules": "
|
|
90
|
+
"react-native-nitro-modules": ">=0.35.0 <1.0.0"
|
|
91
91
|
},
|
|
92
92
|
"prettier": {
|
|
93
93
|
"quoteProps": "consistent",
|