@onekeyfe/react-native-background-thread 1.1.19 → 1.1.21

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.
@@ -16,5 +16,7 @@ Pod::Spec.new do |s|
16
16
  s.source_files = "ios/**/*.{h,m,mm,swift,cpp}"
17
17
  s.public_header_files = "ios/**/*.h"
18
18
 
19
+ s.dependency 'ReactNativeNativeLogger'
20
+
19
21
  install_modules_dependencies(s)
20
22
  end
package/ios/BTLogger.h ADDED
@@ -0,0 +1,16 @@
1
+ #import <Foundation/Foundation.h>
2
+
3
+ NS_ASSUME_NONNULL_BEGIN
4
+
5
+ /// Lightweight logging wrapper that dynamically dispatches to OneKeyLog.
6
+ /// Avoids `@import ReactNativeNativeLogger` which fails in .mm (Objective-C++) files.
7
+ @interface BTLogger : NSObject
8
+
9
+ + (void)debug:(NSString *)message;
10
+ + (void)info:(NSString *)message;
11
+ + (void)warn:(NSString *)message;
12
+ + (void)error:(NSString *)message;
13
+
14
+ @end
15
+
16
+ NS_ASSUME_NONNULL_END
package/ios/BTLogger.m ADDED
@@ -0,0 +1,42 @@
1
+ #import "BTLogger.h"
2
+
3
+ static NSString *const kTag = @"BackgroundThread";
4
+
5
+ @implementation BTLogger
6
+
7
+ + (void)debug:(NSString *)message {
8
+ [self _log:@"debug::" message:message];
9
+ }
10
+
11
+ + (void)info:(NSString *)message {
12
+ [self _log:@"info::" message:message];
13
+ }
14
+
15
+ + (void)warn:(NSString *)message {
16
+ [self _log:@"warn::" message:message];
17
+ }
18
+
19
+ + (void)error:(NSString *)message {
20
+ [self _log:@"error::" message:message];
21
+ }
22
+
23
+ #pragma mark - Private
24
+
25
+ + (void)_log:(NSString *)selectorName message:(NSString *)message {
26
+ Class logClass = NSClassFromString(@"ReactNativeNativeLogger.OneKeyLog");
27
+ if (!logClass) {
28
+ logClass = NSClassFromString(@"OneKeyLog");
29
+ }
30
+ if (!logClass) {
31
+ return;
32
+ }
33
+ SEL sel = NSSelectorFromString(selectorName);
34
+ if (![logClass respondsToSelector:sel]) {
35
+ return;
36
+ }
37
+ typedef void (*LogFunc)(id, SEL, NSString *, NSString *);
38
+ LogFunc func = (LogFunc)[logClass methodForSelector:sel];
39
+ func(logClass, sel, kTag, message);
40
+ }
41
+
42
+ @end
@@ -1,4 +1,5 @@
1
1
  #import "BackgroundRunnerReactNativeDelegate.h"
2
+ #import "BTLogger.h"
2
3
 
3
4
  #include <jsi/JSIDynamic.h>
4
5
  #include <jsi/decorator.h>
@@ -156,45 +157,20 @@ static std::string safeGetStringProperty(jsi::Runtime &rt, const jsi::Object &ob
156
157
 
157
158
  _onMessageSandbox->call(runtime, {std::move(parsedValue)});
158
159
  } catch (const jsi::JSError &e) {
159
- // if (self.eventEmitter && self.hasOnErrorHandler) {
160
- // SandboxReactNativeViewEventEmitter::OnError errorEvent = {
161
- // .isFatal = false, .name = "JSError", .message = e.getMessage(), .stack = e.getStack()};
162
- // self.eventEmitter->onError(errorEvent);
163
- // }
160
+ [BTLogger error:[NSString stringWithFormat:@"JSError during postMessage: %s", e.getMessage().c_str()]];
164
161
  } catch (const std::exception &e) {
165
- // if (self.eventEmitter && self.hasOnErrorHandler) {
166
- // SandboxReactNativeViewEventEmitter::OnError errorEvent = {
167
- // .isFatal = false, .name = "RuntimeError", .message = e.what(), .stack = ""};
168
- // self.eventEmitter->onError(errorEvent);
169
- // }
162
+ [BTLogger error:[NSString stringWithFormat:@"RuntimeError during postMessage: %s", e.what()]];
170
163
  } catch (...) {
171
- NSLog(@"[BackgroundReactNativeDelegate] Runtime invalid during postMessage for sandbox %s", _origin.c_str());
164
+ [BTLogger error:[NSString stringWithFormat:@"Runtime invalid during postMessage for sandbox %s", _origin.c_str()]];
172
165
  }
173
166
  }];
174
167
  }
175
168
 
176
169
  - (bool)routeMessage:(const std::string &)message toSandbox:(const std::string &)targetId
177
170
  {
178
- // auto &registry = SandboxRegistry::getInstance();
179
- // auto target = registry.find(targetId);
180
- // if (!target) {
181
- // return false;
182
- // }
183
-
184
- // // Check if the current sandbox is permitted to send messages to the target
185
- // if (!registry.isPermittedFrom(_origin, targetId)) {
186
- // // if (self.eventEmitter && self.hasOnErrorHandler) {
187
- // // std::string errorMessage =
188
- // // fmt::format("Access denied: Sandbox '{}' is not permitted to send messages to '{}'", _origin, targetId);
189
- // // SandboxReactNativeViewEventEmitter::OnError errorEvent = {
190
- // // .isFatal = false, .name = "AccessDeniedError", .message = errorMessage, .stack = ""};
191
- // // self.eventEmitter->onError(errorEvent);
192
- // // }
193
- // return false;
194
- // }
195
-
196
- // target->postMessage(message);
197
- return true;
171
+ // Sandbox routing is not yet implemented. Deny all cross-sandbox messages by default.
172
+ [BTLogger warn:@"routeMessage denied: sandbox routing not implemented"];
173
+ return false;
198
174
  }
199
175
 
200
176
  - (void)hostDidStart:(RCTHost *)host
@@ -1,5 +1,6 @@
1
1
  #import "BackgroundThread.h"
2
2
  #import "BackgroundThreadManager.h"
3
+ #import "BTLogger.h"
3
4
 
4
5
 
5
6
  @implementation BackgroundThread
@@ -8,6 +9,7 @@
8
9
  - (std::shared_ptr<facebook::react::TurboModule>)getTurboModule:
9
10
  (const facebook::react::ObjCTurboModule::InitParams &)params
10
11
  {
12
+ [BTLogger info:@"BackgroundThread module initialized"];
11
13
  return std::make_shared<facebook::react::NativeBackgroundThreadSpecJSI>(params);
12
14
  }
13
15
 
@@ -13,6 +13,7 @@
13
13
  #import "RCTAppDependencyProvider.h"
14
14
  #endif
15
15
  #import "BackgroundRunnerReactNativeDelegate.h"
16
+ #import "BTLogger.h"
16
17
 
17
18
  @interface BackgroundThreadManager ()
18
19
  @property (nonatomic, strong) BackgroundReactNativeDelegate *reactNativeFactoryDelegate;
@@ -50,7 +51,12 @@ static NSString *const MODULE_DEBUG_URL = @"http://localhost:8082/apps/mobile/ba
50
51
  #pragma mark - Public Methods
51
52
 
52
53
  - (void)startBackgroundRunner {
54
+ #if DEBUG
53
55
  [self startBackgroundRunnerWithEntryURL:MODULE_DEBUG_URL];
56
+ #else
57
+ // In production, use the bundled background.bundle (not the debug HTTP URL)
58
+ [self startBackgroundRunnerWithEntryURL:@"background.bundle"];
59
+ #endif
54
60
  }
55
61
 
56
62
  - (void)startBackgroundRunnerWithEntryURL:(NSString *)entryURL {
@@ -58,7 +64,8 @@ static NSString *const MODULE_DEBUG_URL = @"http://localhost:8082/apps/mobile/ba
58
64
  return;
59
65
  }
60
66
  self.isStarted = YES;
61
-
67
+ [BTLogger info:[NSString stringWithFormat:@"Starting background runner with entryURL: %@", entryURL]];
68
+
62
69
  dispatch_async(dispatch_get_main_queue(), ^{
63
70
  NSDictionary *initialProperties = @{};
64
71
  NSDictionary *launchOptions = @{};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@onekeyfe/react-native-background-thread",
3
- "version": "1.1.19",
3
+ "version": "1.1.21",
4
4
  "description": "react-native-background-thread",
5
5
  "main": "./lib/module/index.js",
6
6
  "types": "./lib/typescript/src/index.d.ts",