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 androidx.appcompat.app.AppCompatActivity;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
|
import org.greenrobot.eventbus.Subscribe;
|
||||||
|
import org.greenrobot.eventbus.ThreadMode;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
|
|
||||||
import pub.doric.dev.DevPanel;
|
|
||||||
import pub.doric.Doric;
|
|
||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
|
import pub.doric.DoricDriver;
|
||||||
|
import pub.doric.dev.DevPanel;
|
||||||
import pub.doric.dev.LocalServer;
|
import pub.doric.dev.LocalServer;
|
||||||
|
import pub.doric.dev.event.EnterDebugEvent;
|
||||||
import pub.doric.utils.DoricUtils;
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
|
|
||||||
public class MainActivity extends AppCompatActivity {
|
public class MainActivity extends AppCompatActivity {
|
||||||
|
|
||||||
private DevPanel mDevPanel = new DevPanel();
|
private DevPanel mDevPanel = new DevPanel();
|
||||||
|
private DoricContext doricContext;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected void onCreate(Bundle savedInstanceState) {
|
protected void onCreate(Bundle savedInstanceState) {
|
||||||
super.onCreate(savedInstanceState);
|
super.onCreate(savedInstanceState);
|
||||||
|
|
||||||
setContentView(R.layout.activity_main);
|
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.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
// doricContext.callEntity("log");
|
// doricContext.callEntity("log");
|
||||||
doricContext.getRootNode().setRootView((FrameLayout) findViewById(R.id.root));
|
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
|
@Override
|
||||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||||
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
||||||
|
@ -63,7 +63,7 @@ dependencies {
|
|||||||
implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.7'
|
implementation 'cn.bingoogolapple:bga-qrcode-zxing:1.3.7'
|
||||||
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
|
implementation 'com.github.tbruyelle:rxpermissions:0.10.2'
|
||||||
implementation "io.reactivex.rxjava2:rxjava:2.2.14"
|
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'
|
implementation 'com.lahm.library:easy-protector-release:1.1.0'
|
||||||
|
|
||||||
testImplementation 'junit:junit:4.12'
|
testImplementation 'junit:junit:4.12'
|
||||||
|
@ -157,4 +157,8 @@ public class DoricDriver implements IDoricDriver {
|
|||||||
wsClient.close();
|
wsClient.close();
|
||||||
wsClient = null;
|
wsClient = null;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public void changeJSEngine(boolean isNative) {
|
||||||
|
doricJSEngine.changeJSEngine(isNative);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,6 +30,7 @@ import okhttp3.WebSocketListener;
|
|||||||
import pub.doric.DoricContext;
|
import pub.doric.DoricContext;
|
||||||
import pub.doric.DoricContextManager;
|
import pub.doric.DoricContextManager;
|
||||||
import pub.doric.dev.event.EOFEvent;
|
import pub.doric.dev.event.EOFEvent;
|
||||||
|
import pub.doric.dev.event.EnterDebugEvent;
|
||||||
import pub.doric.dev.event.OpenEvent;
|
import pub.doric.dev.event.OpenEvent;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -67,6 +68,9 @@ public class WSClient extends WebSocketListener {
|
|||||||
super.onMessage(webSocket, text);
|
super.onMessage(webSocket, text);
|
||||||
try {
|
try {
|
||||||
JSONObject jsonObject = new JSONObject(text);
|
JSONObject jsonObject = new JSONObject(text);
|
||||||
|
String cmd = jsonObject.optString("cmd");
|
||||||
|
switch (cmd) {
|
||||||
|
case "RELOAD": {
|
||||||
String source = jsonObject.optString("source");
|
String source = jsonObject.optString("source");
|
||||||
String script = jsonObject.optString("script");
|
String script = jsonObject.optString("script");
|
||||||
for (DoricContext context : DoricContextManager.aliveContexts()) {
|
for (DoricContext context : DoricContextManager.aliveContexts()) {
|
||||||
@ -74,6 +78,14 @@ public class WSClient extends WebSocketListener {
|
|||||||
context.reload(script);
|
context.reload(script);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
case "SWITCH_TO_DEBUG": {
|
||||||
|
EventBus.getDefault().post(new EnterDebugEvent());
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
} catch (JSONException e) {
|
} catch (JSONException e) {
|
||||||
e.printStackTrace();
|
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.os.Message;
|
||||||
import android.text.TextUtils;
|
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.DoricRegistry;
|
||||||
import pub.doric.extension.bridge.DoricBridgeExtension;
|
import pub.doric.extension.bridge.DoricBridgeExtension;
|
||||||
import pub.doric.extension.timer.DoricTimerExtension;
|
import pub.doric.extension.timer.DoricTimerExtension;
|
||||||
@ -28,12 +34,6 @@ import pub.doric.utils.DoricConstant;
|
|||||||
import pub.doric.utils.DoricLog;
|
import pub.doric.utils.DoricLog;
|
||||||
import pub.doric.utils.DoricUtils;
|
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
|
* @Description: Doric
|
||||||
* @Author: pengfei.zhou
|
* @Author: pengfei.zhou
|
||||||
@ -54,7 +54,8 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
mJSHandler.post(new Runnable() {
|
mJSHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
initJSExecutor();
|
mDoricJSE = new DoricNativeJSExecutor();
|
||||||
|
injectGlobal();
|
||||||
initDoricRuntime();
|
initDoricRuntime();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -65,10 +66,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
return mJSHandler;
|
return mJSHandler;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private void injectGlobal() {
|
||||||
private void initJSExecutor() {
|
|
||||||
mDoricJSE = new DoricNativeJSExecutor();
|
|
||||||
// mDoricJSE = new DoricRemoteJSExecutor();
|
|
||||||
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
|
mDoricJSE.injectGlobalJSFunction(DoricConstant.INJECT_LOG, new JavaFunction() {
|
||||||
@Override
|
@Override
|
||||||
public JavaValue exec(JSDecoder[] args) {
|
public JavaValue exec(JSDecoder[] args) {
|
||||||
@ -212,4 +210,14 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
public DoricRegistry getRegistry() {
|
public DoricRegistry getRegistry() {
|
||||||
return mDoricRegistry;
|
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")
|
const sourceMap = doMerge(path + ".map")
|
||||||
ws.connections.forEach(e => {
|
ws.connections.forEach(e => {
|
||||||
e.sendText(JSON.stringify({
|
e.sendText(JSON.stringify({
|
||||||
|
cmd: 'RELOAD',
|
||||||
script: data,
|
script: data,
|
||||||
source: path.match(/[^/\\]*$/)[0],
|
source: path.match(/[^/\\]*$/)[0],
|
||||||
sourceMap,
|
sourceMap,
|
||||||
|
Reference in New Issue
Block a user