react-native-stallion 2.0.0-alpha.2 → 2.0.0-alpha.4
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/java/com/stallion/StallionModule.java +12 -11
- package/android/src/main/java/com/stallion/events/StallionEventManager.java +11 -5
- package/android/src/main/java/com/stallion/networkmanager/StallionFileDownloader.java +7 -4
- package/android/src/main/java/com/stallion/networkmanager/StallionSyncHandler.java +2 -1
- package/android/src/main/java/com/stallion/storage/StallionStateManager.java +4 -1
- package/android/src/main/java/com/stallion/utils/StallionExceptionHandler.java +8 -14
- package/package.json +1 -1
|
@@ -17,7 +17,6 @@ import com.stallion.storage.StallionConfigConstants;
|
|
|
17
17
|
|
|
18
18
|
import com.stallion.storage.StallionMetaConstants;
|
|
19
19
|
import com.stallion.storage.StallionStateManager;
|
|
20
|
-
import com.stallion.utils.StallionExceptionHandler;
|
|
21
20
|
|
|
22
21
|
import org.json.JSONArray;
|
|
23
22
|
import org.json.JSONException;
|
|
@@ -28,20 +27,27 @@ import java.util.List;
|
|
|
28
27
|
|
|
29
28
|
@ReactModule(name = StallionConfigConstants.MODULE_NAME)
|
|
30
29
|
public class StallionModule extends ReactContextBaseJavaModule implements LifecycleEventListener {
|
|
31
|
-
private final ReactApplicationContext currentReactContext;
|
|
32
30
|
private final StallionStateManager stallionStateManager;
|
|
33
31
|
|
|
34
32
|
public StallionModule(ReactApplicationContext reactContext) {
|
|
35
33
|
super(reactContext);
|
|
36
34
|
StallionStateManager.init(reactContext);
|
|
37
35
|
this.stallionStateManager = StallionStateManager.getInstance();
|
|
38
|
-
this.
|
|
39
|
-
StallionExceptionHandler.initErrorBoundary(reactContext);
|
|
36
|
+
StallionEventManager.init(this.stallionStateManager);
|
|
40
37
|
reactContext.addLifecycleEventListener(this);
|
|
41
38
|
}
|
|
42
39
|
|
|
43
40
|
@Override
|
|
44
41
|
public void onHostResume() {
|
|
42
|
+
if (
|
|
43
|
+
StallionEventManager.getInstance().getEmitter() == null
|
|
44
|
+
&& getReactApplicationContext().getCatalystInstance() != null
|
|
45
|
+
) {
|
|
46
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter = getReactApplicationContext().getJSModule(
|
|
47
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter.class
|
|
48
|
+
);
|
|
49
|
+
StallionEventManager.getInstance().setEmitter(eventEmitter);
|
|
50
|
+
}
|
|
45
51
|
StallionSyncHandler.sync();
|
|
46
52
|
}
|
|
47
53
|
|
|
@@ -54,7 +60,8 @@ public class StallionModule extends ReactContextBaseJavaModule implements Lifecy
|
|
|
54
60
|
@Override
|
|
55
61
|
public void onCatalystInstanceDestroy() {
|
|
56
62
|
super.onCatalystInstanceDestroy();
|
|
57
|
-
|
|
63
|
+
stallionStateManager.setIsMounted(false);
|
|
64
|
+
getReactApplicationContext().removeLifecycleEventListener(this);
|
|
58
65
|
}
|
|
59
66
|
|
|
60
67
|
@Override
|
|
@@ -66,12 +73,6 @@ public class StallionModule extends ReactContextBaseJavaModule implements Lifecy
|
|
|
66
73
|
@ReactMethod
|
|
67
74
|
public void onLaunch(String launchData) {
|
|
68
75
|
stallionStateManager.setIsMounted(true);
|
|
69
|
-
|
|
70
|
-
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter = this.currentReactContext.getJSModule(
|
|
71
|
-
DeviceEventManagerModule.RCTDeviceEventEmitter.class
|
|
72
|
-
);
|
|
73
|
-
StallionEventManager.getInstance().setEmitter(eventEmitter);
|
|
74
|
-
|
|
75
76
|
checkPendingDownloads();
|
|
76
77
|
}
|
|
77
78
|
|
|
@@ -12,6 +12,7 @@ import org.json.JSONObject;
|
|
|
12
12
|
import java.util.Iterator;
|
|
13
13
|
import java.util.List;
|
|
14
14
|
import java.util.UUID;
|
|
15
|
+
import java.util.concurrent.atomic.AtomicReference;
|
|
15
16
|
|
|
16
17
|
public class StallionEventManager {
|
|
17
18
|
public static final String STALLION_NATIVE_EVENT_NAME = "STALLION_NATIVE_EVENT";
|
|
@@ -20,7 +21,7 @@ public class StallionEventManager {
|
|
|
20
21
|
|
|
21
22
|
private static StallionEventManager instance;
|
|
22
23
|
private final StallionStateManager stallionStateManager;
|
|
23
|
-
private DeviceEventManagerModule.RCTDeviceEventEmitter
|
|
24
|
+
private final AtomicReference<DeviceEventManagerModule.RCTDeviceEventEmitter> eventEmitterRef = new AtomicReference<>();
|
|
24
25
|
|
|
25
26
|
// Private constructor for Singleton
|
|
26
27
|
private StallionEventManager(StallionStateManager stateManager) {
|
|
@@ -35,7 +36,11 @@ public class StallionEventManager {
|
|
|
35
36
|
}
|
|
36
37
|
|
|
37
38
|
public void setEmitter(DeviceEventManagerModule.RCTDeviceEventEmitter deviceEmitter) {
|
|
38
|
-
|
|
39
|
+
eventEmitterRef.set(deviceEmitter);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
public DeviceEventManagerModule.RCTDeviceEventEmitter getEmitter() {
|
|
43
|
+
return eventEmitterRef.get();
|
|
39
44
|
}
|
|
40
45
|
|
|
41
46
|
// Get instance method
|
|
@@ -49,9 +54,9 @@ public class StallionEventManager {
|
|
|
49
54
|
public void sendEventWithoutCaching(String eventName, JSONObject eventPayload) {
|
|
50
55
|
try {
|
|
51
56
|
eventPayload.put("type", eventName);
|
|
52
|
-
|
|
57
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter = eventEmitterRef.get();
|
|
53
58
|
// Emit the event to React Native
|
|
54
|
-
if (eventEmitter != null) {
|
|
59
|
+
if (eventEmitter != null && stallionStateManager.getIsMounted()) {
|
|
55
60
|
eventEmitter.emit(STALLION_NATIVE_EVENT_NAME, eventPayload.toString());
|
|
56
61
|
}
|
|
57
62
|
|
|
@@ -69,8 +74,9 @@ public class StallionEventManager {
|
|
|
69
74
|
|
|
70
75
|
eventPayload.put("type", eventName);
|
|
71
76
|
|
|
77
|
+
DeviceEventManagerModule.RCTDeviceEventEmitter eventEmitter = eventEmitterRef.get();
|
|
72
78
|
// Emit the event to React Native
|
|
73
|
-
if (eventEmitter != null) {
|
|
79
|
+
if (eventEmitter != null && stallionStateManager.getIsMounted()) {
|
|
74
80
|
eventEmitter.emit(STALLION_NATIVE_EVENT_NAME, eventPayload.toString());
|
|
75
81
|
}
|
|
76
82
|
|
|
@@ -128,7 +128,7 @@ public class StallionFileDownloader {
|
|
|
128
128
|
|
|
129
129
|
// Ensure totalBytes is valid
|
|
130
130
|
if (totalBytes <= 0) {
|
|
131
|
-
callback.onReject(StallionApiConstants.DOWNLOAD_ERROR_PREFIX, "Invalid content length: "
|
|
131
|
+
callback.onReject(StallionApiConstants.DOWNLOAD_ERROR_PREFIX, "Invalid content length: ");
|
|
132
132
|
return;
|
|
133
133
|
}
|
|
134
134
|
|
|
@@ -158,7 +158,7 @@ public class StallionFileDownloader {
|
|
|
158
158
|
return;
|
|
159
159
|
}
|
|
160
160
|
} catch (IOException e) {
|
|
161
|
-
callback.onReject(StallionApiConstants.DOWNLOAD_ERROR_PREFIX, "IOException occurred: "
|
|
161
|
+
callback.onReject(StallionApiConstants.DOWNLOAD_ERROR_PREFIX, "IOException occurred: ");
|
|
162
162
|
throw e;
|
|
163
163
|
} finally {
|
|
164
164
|
if (connection != null) {
|
|
@@ -205,8 +205,11 @@ public class StallionFileDownloader {
|
|
|
205
205
|
callback.onReject(StallionApiConstants.DOWNLOAD_ERROR_PREFIX, StallionApiConstants.CORRUPTED_FILE_ERROR);
|
|
206
206
|
}
|
|
207
207
|
} catch (Exception e) {
|
|
208
|
-
String filesystemError = e.getMessage();
|
|
209
|
-
callback.onReject(
|
|
208
|
+
String filesystemError = e.getMessage() != null ? e.getMessage() : "Unknown filesystem error";
|
|
209
|
+
callback.onReject(
|
|
210
|
+
StallionApiConstants.DOWNLOAD_ERROR_PREFIX,
|
|
211
|
+
StallionApiConstants.DOWNLOAD_FILESYSTEM_ERROR_MESSAGE + filesystemError
|
|
212
|
+
);
|
|
210
213
|
} finally {
|
|
211
214
|
StallionFileManager.deleteFileOrFolderSilently(downloadedZip);
|
|
212
215
|
}
|
|
@@ -139,7 +139,8 @@ public class StallionSyncHandler {
|
|
|
139
139
|
private static void emitSyncError(Exception e) {
|
|
140
140
|
JSONObject syncErrorPayload = new JSONObject();
|
|
141
141
|
try {
|
|
142
|
-
|
|
142
|
+
String syncErrorString = e.getMessage() != null ? e.getMessage() : "Unknown error";
|
|
143
|
+
syncErrorPayload.put("meta", syncErrorString);
|
|
143
144
|
} catch (Exception ignored) { }
|
|
144
145
|
StallionEventManager.getInstance().sendEvent(
|
|
145
146
|
NativeProdEventTypes.SYNC_ERROR_PROD.toString(),
|
|
@@ -3,6 +3,8 @@ package com.stallion.storage;
|
|
|
3
3
|
import android.content.Context;
|
|
4
4
|
import android.content.SharedPreferences;
|
|
5
5
|
|
|
6
|
+
import com.stallion.utils.StallionExceptionHandler;
|
|
7
|
+
|
|
6
8
|
import org.json.JSONException;
|
|
7
9
|
import org.json.JSONObject;
|
|
8
10
|
|
|
@@ -32,6 +34,7 @@ public class StallionStateManager {
|
|
|
32
34
|
public static synchronized void init(Context context) {
|
|
33
35
|
if (instance == null) {
|
|
34
36
|
instance = new StallionStateManager(context);
|
|
37
|
+
StallionExceptionHandler.initErrorBoundary();
|
|
35
38
|
}
|
|
36
39
|
}
|
|
37
40
|
|
|
@@ -88,7 +91,7 @@ public class StallionStateManager {
|
|
|
88
91
|
public void setString(String key, String value) {
|
|
89
92
|
SharedPreferences.Editor editor = sharedPreferences.edit();
|
|
90
93
|
editor.putString(key, value);
|
|
91
|
-
editor.
|
|
94
|
+
editor.commit();
|
|
92
95
|
}
|
|
93
96
|
|
|
94
97
|
public StallionConfig getStallionConfig() {
|
|
@@ -1,10 +1,7 @@
|
|
|
1
1
|
package com.stallion.utils;
|
|
2
2
|
|
|
3
|
-
import android.app.Activity;
|
|
4
|
-
import android.content.Intent;
|
|
5
3
|
import android.util.Log;
|
|
6
4
|
|
|
7
|
-
import com.facebook.react.bridge.ReactApplicationContext;
|
|
8
5
|
import com.stallion.events.StallionEventConstants;
|
|
9
6
|
import com.stallion.events.StallionEventManager;
|
|
10
7
|
import com.stallion.storage.StallionMetaConstants;
|
|
@@ -17,11 +14,15 @@ public class StallionExceptionHandler {
|
|
|
17
14
|
private static Thread.UncaughtExceptionHandler _androidUncaughtExceptionHandler;
|
|
18
15
|
private static Thread _exceptionThread;
|
|
19
16
|
private static Throwable _exceptionThrowable;
|
|
20
|
-
private static
|
|
17
|
+
private static boolean isErrorBoundaryInitialized = false;
|
|
18
|
+
|
|
19
|
+
public static void initErrorBoundary() {
|
|
20
|
+
if (isErrorBoundaryInitialized) {
|
|
21
|
+
return; // Prevent multiple initializations
|
|
22
|
+
}
|
|
23
|
+
isErrorBoundaryInitialized = true;
|
|
21
24
|
|
|
22
|
-
public static void initErrorBoundary(ReactApplicationContext currentContext) {
|
|
23
25
|
_androidUncaughtExceptionHandler = Thread.getDefaultUncaughtExceptionHandler();
|
|
24
|
-
_reactActivity = currentContext.getCurrentActivity();
|
|
25
26
|
Thread.setDefaultUncaughtExceptionHandler((thread, throwable) -> {
|
|
26
27
|
_exceptionThread = thread;
|
|
27
28
|
_exceptionThrowable = throwable;
|
|
@@ -84,14 +85,7 @@ public class StallionExceptionHandler {
|
|
|
84
85
|
|
|
85
86
|
StallionSlotManager.rollbackStage();
|
|
86
87
|
|
|
87
|
-
|
|
88
|
-
Intent errorIntent = new Intent(_reactActivity, StallionErrorActivity.class);
|
|
89
|
-
errorIntent.putExtra("stack_trace_string", stackTraceString);
|
|
90
|
-
_reactActivity.startActivity(errorIntent);
|
|
91
|
-
_reactActivity.finish();
|
|
92
|
-
} else {
|
|
93
|
-
continueExceptionFlow();
|
|
94
|
-
}
|
|
88
|
+
continueExceptionFlow();
|
|
95
89
|
}
|
|
96
90
|
|
|
97
91
|
public static void continueExceptionFlow() {
|