mirror of
https://github.com/status-im/realm-js.git
synced 2025-02-23 11:48:17 +00:00
start debug server only on when using chrome debug
This commit is contained in:
parent
2e3a3b5db8
commit
76981229ab
@ -9,7 +9,6 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|||||||
import com.facebook.soloader.SoLoader;
|
import com.facebook.soloader.SoLoader;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.lang.IllegalStateException;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -56,13 +55,16 @@ public class RealmReactModule extends ReactContextBaseJavaModule {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getConstants() {
|
public Map<String, Object> getConstants() {
|
||||||
// FIXME: Only start web server when in Chrome debug mode!
|
if (!isContextInjected()) {
|
||||||
|
startWebServer();
|
||||||
|
}
|
||||||
startWebServer();
|
startWebServer();
|
||||||
return Collections.EMPTY_MAP;
|
return Collections.EMPTY_MAP;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onCatalystInstanceDestroy() {
|
public void onCatalystInstanceDestroy() {
|
||||||
|
clearFlag();
|
||||||
stopWebServer();
|
stopWebServer();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -127,6 +129,12 @@ public class RealmReactModule extends ReactContextBaseJavaModule {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// return true if the Realm API was injected (return false when running in Chrome Debug)
|
||||||
|
private native boolean isContextInjected();
|
||||||
|
|
||||||
|
// clear the flag set when injecting Realm API
|
||||||
|
private native void clearFlag();
|
||||||
|
|
||||||
// fileDir: path of the internal storage of the application
|
// fileDir: path of the internal storage of the application
|
||||||
private native void setDefaultRealmFileDirectory(String fileDir);
|
private native void setDefaultRealmFileDirectory(String fileDir);
|
||||||
|
|
||||||
|
@ -10,6 +10,7 @@
|
|||||||
#include "platform.hpp"
|
#include "platform.hpp"
|
||||||
|
|
||||||
static realm_js::RPCServer *s_rpc_server;
|
static realm_js::RPCServer *s_rpc_server;
|
||||||
|
extern bool realmContextInjected;
|
||||||
|
|
||||||
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileDirectory
|
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileDirectory
|
||||||
(JNIEnv *env, jclass, jstring fileDir)
|
(JNIEnv *env, jclass, jstring fileDir)
|
||||||
@ -38,7 +39,6 @@ JNIEXPORT jlong JNICALL Java_io_realm_react_RealmReactModule_setupChromeDebugMod
|
|||||||
JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebugCommand
|
JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebugCommand
|
||||||
(JNIEnv *env, jclass, jstring chrome_cmd, jstring chrome_args)
|
(JNIEnv *env, jclass, jstring chrome_cmd, jstring chrome_args)
|
||||||
{
|
{
|
||||||
__android_log_print(ANDROID_LOG_VERBOSE, "JSRealm", "processChromeDebugCommand");
|
|
||||||
const char* cmd = env->GetStringUTFChars(chrome_cmd, NULL);
|
const char* cmd = env->GetStringUTFChars(chrome_cmd, NULL);
|
||||||
const char* args = env->GetStringUTFChars(chrome_args, NULL);
|
const char* args = env->GetStringUTFChars(chrome_args, NULL);
|
||||||
realm_js::json json = realm_js::json::parse(args);
|
realm_js::json json = realm_js::json::parse(args);
|
||||||
@ -47,3 +47,16 @@ JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebu
|
|||||||
env->ReleaseStringUTFChars(chrome_args, args);
|
env->ReleaseStringUTFChars(chrome_args, args);
|
||||||
return env->NewStringUTF(response.dump().c_str());
|
return env->NewStringUTF(response.dump().c_str());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
JNIEXPORT jboolean JNICALL Java_io_realm_react_RealmReactModule_isContextInjected
|
||||||
|
(JNIEnv *env, jclass)
|
||||||
|
{
|
||||||
|
return realmContextInjected;
|
||||||
|
}
|
||||||
|
|
||||||
|
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_clearFlag
|
||||||
|
(JNIEnv *env, jclass)
|
||||||
|
{
|
||||||
|
realmContextInjected = false;//might not be needed
|
||||||
|
|
||||||
|
}
|
@ -29,6 +29,21 @@ JNIEXPORT jlong JNICALL Java_io_realm_react_RealmReactModule_setupChromeDebugMod
|
|||||||
JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebugCommand
|
JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebugCommand
|
||||||
(JNIEnv *, jclass, jstring, jstring);
|
(JNIEnv *, jclass, jstring, jstring);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: io_realm_react_RealmReactModule
|
||||||
|
* Method: isContextInjected
|
||||||
|
*/
|
||||||
|
JNIEXPORT jboolean JNICALL Java_io_realm_react_RealmReactModule_isContextInjected
|
||||||
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Class: io_realm_react_RealmReactModule
|
||||||
|
* Method: clearFlag
|
||||||
|
*/
|
||||||
|
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_clearFlag
|
||||||
|
(JNIEnv *, jclass);
|
||||||
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -18,6 +18,8 @@
|
|||||||
#define HOOK_SIZE 5
|
#define HOOK_SIZE 5
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
bool realmContextInjected;
|
||||||
|
|
||||||
static void swap_function() __attribute__((constructor));
|
static void swap_function() __attribute__((constructor));
|
||||||
|
|
||||||
static JSGlobalContextRef create_context(JSContextGroupRef group, JSClassRef global_class)
|
static JSGlobalContextRef create_context(JSContextGroupRef group, JSClassRef global_class)
|
||||||
@ -36,6 +38,7 @@ static JSGlobalContextRef create_context(JSContextGroupRef group, JSClassRef glo
|
|||||||
realm::Realm::s_global_cache.clear();
|
realm::Realm::s_global_cache.clear();
|
||||||
|
|
||||||
RJSInitializeInContext(ctx);
|
RJSInitializeInContext(ctx);
|
||||||
|
realmContextInjected = true;
|
||||||
return ctx;
|
return ctx;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user