Merge pull request #265 from realm/nh/fixes_255_debug_server
start debug server only on when using chrome debug
This commit is contained in:
commit
ba0ff5fbaf
|
@ -9,7 +9,6 @@ import com.facebook.react.bridge.ReactContextBaseJavaModule;
|
|||
import com.facebook.soloader.SoLoader;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.lang.IllegalStateException;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
@ -56,13 +55,15 @@ public class RealmReactModule extends ReactContextBaseJavaModule {
|
|||
|
||||
@Override
|
||||
public Map<String, Object> getConstants() {
|
||||
// FIXME: Only start web server when in Chrome debug mode!
|
||||
if (!isContextInjected()) {
|
||||
startWebServer();
|
||||
}
|
||||
return Collections.EMPTY_MAP;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onCatalystInstanceDestroy() {
|
||||
clearContextInjectedFlag();
|
||||
stopWebServer();
|
||||
}
|
||||
|
||||
|
@ -127,6 +128,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 clearContextInjectedFlag();
|
||||
|
||||
// fileDir: path of the internal storage of the application
|
||||
private native void setDefaultRealmFileDirectory(String fileDir);
|
||||
|
||||
|
|
|
@ -10,6 +10,7 @@
|
|||
#include "platform.hpp"
|
||||
|
||||
static realm_js::RPCServer *s_rpc_server;
|
||||
extern bool realmContextInjected;
|
||||
|
||||
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_setDefaultRealmFileDirectory
|
||||
(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
|
||||
(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* args = env->GetStringUTFChars(chrome_args, NULL);
|
||||
realm_js::json json = realm_js::json::parse(args);
|
||||
|
@ -47,3 +47,15 @@ JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebu
|
|||
env->ReleaseStringUTFChars(chrome_args, args);
|
||||
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_clearContextInjectedFlag
|
||||
(JNIEnv *env, jclass)
|
||||
{
|
||||
realmContextInjected = false;
|
||||
}
|
||||
|
|
|
@ -29,6 +29,21 @@ JNIEXPORT jlong JNICALL Java_io_realm_react_RealmReactModule_setupChromeDebugMod
|
|||
JNIEXPORT jstring JNICALL Java_io_realm_react_RealmReactModule_processChromeDebugCommand
|
||||
(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: clearContextInjectedFlag
|
||||
*/
|
||||
JNIEXPORT void JNICALL Java_io_realm_react_RealmReactModule_clearContextInjectedFlag
|
||||
(JNIEnv *, jclass);
|
||||
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
#endif
|
||||
|
|
|
@ -18,6 +18,8 @@
|
|||
#define HOOK_SIZE 5
|
||||
#endif
|
||||
|
||||
bool realmContextInjected;
|
||||
|
||||
static void swap_function() __attribute__((constructor));
|
||||
|
||||
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();
|
||||
|
||||
RJSInitializeInContext(ctx);
|
||||
realmContextInjected = true;
|
||||
return ctx;
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue