debug complete process chained (bugged)
This commit is contained in:
parent
9d641e2602
commit
6ba6995d10
@ -22,24 +22,31 @@ import android.widget.FrameLayout;
|
||||
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
import org.greenrobot.eventbus.Subscribe;
|
||||
import org.greenrobot.eventbus.ThreadMode;
|
||||
|
||||
import java.io.IOException;
|
||||
|
||||
import pub.doric.dev.DevPanel;
|
||||
import pub.doric.Doric;
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricDriver;
|
||||
import pub.doric.dev.DevPanel;
|
||||
import pub.doric.dev.LocalServer;
|
||||
import pub.doric.dev.event.EnterDebugEvent;
|
||||
import pub.doric.utils.DoricUtils;
|
||||
|
||||
|
||||
public class MainActivity extends AppCompatActivity {
|
||||
|
||||
private DevPanel mDevPanel = new DevPanel();
|
||||
private DoricContext doricContext;
|
||||
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
|
||||
setContentView(R.layout.activity_main);
|
||||
DoricContext doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/Snake.js"), "test");
|
||||
doricContext = DoricContext.create(this, DoricUtils.readAssetFile("demo/Snake.js"), "test");
|
||||
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
// doricContext.callEntity("log");
|
||||
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
|
||||
@ -52,6 +59,28 @@ public class MainActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAttachedToWindow() {
|
||||
super.onAttachedToWindow();
|
||||
|
||||
EventBus.getDefault().register(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onDestroy() {
|
||||
super.onDestroy();
|
||||
|
||||
EventBus.getDefault().unregister(this);
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEnterDebugEvent(EnterDebugEvent enterDebugEvent) {
|
||||
((FrameLayout) findViewById(R.id.root)).removeAllViews();
|
||||
DoricDriver.getInstance().changeJSEngine(false);
|
||||
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
||||
|
@ -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'
|
||||
|
@ -157,4 +157,8 @@ public class DoricDriver implements IDoricDriver {
|
||||
wsClient.close();
|
||||
wsClient = null;
|
||||
}
|
||||
|
||||
public void changeJSEngine(boolean isNative) {
|
||||
doricJSEngine.changeJSEngine(isNative);
|
||||
}
|
||||
}
|
||||
|
@ -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();
|
||||
}
|
||||
|
@ -0,0 +1,4 @@
|
||||
package pub.doric.dev.event;
|
||||
|
||||
public class EnterDebugEvent {
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -19,6 +19,7 @@ setTimeout(() => {
|
||||
const sourceMap = doMerge(path + ".map")
|
||||
ws.connections.forEach(e => {
|
||||
e.sendText(JSON.stringify({
|
||||
cmd: 'RELOAD',
|
||||
script: data,
|
||||
source: path.match(/[^/\\]*$/)[0],
|
||||
sourceMap,
|
||||
|
Reference in New Issue
Block a user