debug complete process chained (bugged)

This commit is contained in:
王劲鹏
2019-11-13 16:08:12 +08:00
parent 9d641e2602
commit 6ba6995d10
7 changed files with 78 additions and 20 deletions

View File

@@ -63,7 +63,7 @@ dependencies {
implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.7'
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
implementation "io.reactivex.rxjava2:rxjava:2.2.14"
implementation 'org.greenrobot:eventbus:3.1.1'
api 'org.greenrobot:eventbus:3.1.1'
implementation 'com.lahm.library:easy-protector-release:1.1.0'
testImplementation 'junit:junit:4.12'

View File

@@ -157,4 +157,8 @@ public class DoricDriver implements IDoricDriver {
wsClient.close();
wsClient = null;
}
public void changeJSEngine(boolean isNative) {
doricJSEngine.changeJSEngine(isNative);
}
}

View File

@@ -30,6 +30,7 @@ import okhttp3.WebSocketListener;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.dev.event.EOFEvent;
import pub.doric.dev.event.EnterDebugEvent;
import pub.doric.dev.event.OpenEvent;
/**
@@ -67,13 +68,24 @@ public class WSClient extends WebSocketListener {
super.onMessage(webSocket, text);
try {
JSONObject jsonObject = new JSONObject(text);
String source = jsonObject.optString("source");
String script = jsonObject.optString("script");
for (DoricContext context : DoricContextManager.aliveContexts()) {
if (source.contains(context.getSource())) {
context.reload(script);
String cmd = jsonObject.optString("cmd");
switch (cmd) {
case "RELOAD": {
String source = jsonObject.optString("source");
String script = jsonObject.optString("script");
for (DoricContext context : DoricContextManager.aliveContexts()) {
if (source.contains(context.getSource())) {
context.reload(script);
}
}
}
break;
case "SWITCH_TO_DEBUG": {
EventBus.getDefault().post(new EnterDebugEvent());
}
break;
}
} catch (JSONException e) {
e.printStackTrace();
}

View File

@@ -0,0 +1,4 @@
package pub.doric.dev.event;
public class EnterDebugEvent {
}

View File

@@ -21,6 +21,12 @@ import android.os.Looper;
import android.os.Message;
import android.text.TextUtils;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue;
import java.util.ArrayList;
import pub.doric.DoricRegistry;
import pub.doric.extension.bridge.DoricBridgeExtension;
import pub.doric.extension.timer.DoricTimerExtension;
@@ -28,12 +34,6 @@ import pub.doric.utils.DoricConstant;
import pub.doric.utils.DoricLog;
import pub.doric.utils.DoricUtils;
import com.github.pengfeizhou.jscore.JSDecoder;
import com.github.pengfeizhou.jscore.JavaFunction;
import com.github.pengfeizhou.jscore.JavaValue;
import java.util.ArrayList;
/**
* @Description: Doric
* @Author: pengfei.zhou
@@ -54,7 +54,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
mJSHandler.post(new Runnable() {
@Override
public void run() {
initJSExecutor();
mDoricJSE = new DoricNativeJSExecutor();
injectGlobal();
initDoricRuntime();
}
});
@@ -65,10 +66,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
return mJSHandler;
}
private void initJSExecutor() {
mDoricJSE = new DoricNativeJSExecutor();
// mDoricJSE = new DoricRemoteJSExecutor();
private void injectGlobal() {
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
@Override
public JavaValue exec(JSDecoder[] args) {
@@ -212,4 +210,14 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
public DoricRegistry getRegistry() {
return mDoricRegistry;
}
public void changeJSEngine(boolean isNative) {
mDoricJSE.teardown();
if (isNative) {
mDoricJSE = new DoricNativeJSExecutor();
} else {
mDoricJSE = new DoricRemoteJSExecutor();
}
injectGlobal();
}
}