debug switch to native
This commit is contained in:
parent
fd8fe277a4
commit
cafec58778
@ -33,6 +33,8 @@ import pub.doric.DoricDriver;
|
|||||||
import pub.doric.dev.DevPanel;
|
import pub.doric.dev.DevPanel;
|
||||||
import pub.doric.dev.LocalServer;
|
import pub.doric.dev.LocalServer;
|
||||||
import pub.doric.dev.event.EnterDebugEvent;
|
import pub.doric.dev.event.EnterDebugEvent;
|
||||||
|
import pub.doric.dev.event.QuitDebugEvent;
|
||||||
|
import pub.doric.engine.ChangeEngineCallback;
|
||||||
import pub.doric.utils.DoricUtils;
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
|
|
||||||
@ -76,8 +78,32 @@ public class MainActivity extends AppCompatActivity {
|
|||||||
|
|
||||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
public void onEnterDebugEvent(EnterDebugEvent enterDebugEvent) {
|
public void onEnterDebugEvent(EnterDebugEvent enterDebugEvent) {
|
||||||
DoricDriver.getInstance().changeJSEngine(false);
|
DoricDriver.getInstance().changeJSEngine(false, new ChangeEngineCallback() {
|
||||||
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
@Override
|
||||||
|
public void changed() {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||||
|
public void onQuitDebugEvent(QuitDebugEvent quitDebugEvent) {
|
||||||
|
DoricDriver.getInstance().changeJSEngine(true, new ChangeEngineCallback() {
|
||||||
|
@Override
|
||||||
|
public void changed() {
|
||||||
|
runOnUiThread(new Runnable() {
|
||||||
|
@Override
|
||||||
|
public void run() {
|
||||||
|
doricContext.init(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -26,6 +26,7 @@ import java.util.concurrent.Executors;
|
|||||||
|
|
||||||
import pub.doric.async.AsyncCall;
|
import pub.doric.async.AsyncCall;
|
||||||
import pub.doric.async.AsyncResult;
|
import pub.doric.async.AsyncResult;
|
||||||
|
import pub.doric.engine.ChangeEngineCallback;
|
||||||
import pub.doric.engine.DoricJSEngine;
|
import pub.doric.engine.DoricJSEngine;
|
||||||
import pub.doric.utils.DoricConstant;
|
import pub.doric.utils.DoricConstant;
|
||||||
import pub.doric.utils.DoricLog;
|
import pub.doric.utils.DoricLog;
|
||||||
@ -135,7 +136,7 @@ public class DoricDriver implements IDoricDriver {
|
|||||||
return doricJSEngine.getRegistry();
|
return doricJSEngine.getRegistry();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeJSEngine(boolean isNative) {
|
public void changeJSEngine(boolean isNative, ChangeEngineCallback changeEngineCallback) {
|
||||||
doricJSEngine.changeJSEngine(isNative);
|
doricJSEngine.changeJSEngine(isNative, changeEngineCallback);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -87,6 +87,7 @@ public class DevPanel extends BottomSheetDialogFragment {
|
|||||||
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
|
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
|
||||||
Doric.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
|
Doric.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
|
||||||
}
|
}
|
||||||
|
dismissAllowingStateLoss();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,4 @@
|
|||||||
|
package pub.doric.dev.event;
|
||||||
|
|
||||||
|
public class QuitDebugEvent {
|
||||||
|
}
|
@ -0,0 +1,5 @@
|
|||||||
|
package pub.doric.engine;
|
||||||
|
|
||||||
|
public interface ChangeEngineCallback {
|
||||||
|
void changed();
|
||||||
|
}
|
@ -43,6 +43,7 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
private final Handler mJSHandler;
|
private final Handler mJSHandler;
|
||||||
private final DoricBridgeExtension mDoricBridgeExtension = new DoricBridgeExtension();
|
private final DoricBridgeExtension mDoricBridgeExtension = new DoricBridgeExtension();
|
||||||
private IDoricJSE mDoricJSE;
|
private IDoricJSE mDoricJSE;
|
||||||
|
private DoricNativeJSExecutor doricNativeJSExecutor;
|
||||||
private final DoricTimerExtension mTimerExtension;
|
private final DoricTimerExtension mTimerExtension;
|
||||||
private final DoricRegistry mDoricRegistry = new DoricRegistry();
|
private final DoricRegistry mDoricRegistry = new DoricRegistry();
|
||||||
|
|
||||||
@ -54,7 +55,9 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
mJSHandler.post(new Runnable() {
|
mJSHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mDoricJSE = new DoricNativeJSExecutor();
|
doricNativeJSExecutor = new DoricNativeJSExecutor();
|
||||||
|
|
||||||
|
mDoricJSE = doricNativeJSExecutor;
|
||||||
injectGlobal();
|
injectGlobal();
|
||||||
initDoricRuntime();
|
initDoricRuntime();
|
||||||
}
|
}
|
||||||
@ -211,17 +214,18 @@ public class DoricJSEngine implements Handler.Callback, DoricTimerExtension.Time
|
|||||||
return mDoricRegistry;
|
return mDoricRegistry;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void changeJSEngine(final boolean isNative) {
|
public void changeJSEngine(final boolean isNative, final ChangeEngineCallback changeEngineCallback) {
|
||||||
mJSHandler.post(new Runnable() {
|
mJSHandler.post(new Runnable() {
|
||||||
@Override
|
@Override
|
||||||
public void run() {
|
public void run() {
|
||||||
mDoricJSE.teardown();
|
|
||||||
if (isNative) {
|
if (isNative) {
|
||||||
mDoricJSE = new DoricNativeJSExecutor();
|
mDoricJSE.teardown();
|
||||||
|
mDoricJSE = doricNativeJSExecutor;
|
||||||
} else {
|
} else {
|
||||||
mDoricJSE = new DoricRemoteJSExecutor();
|
mDoricJSE = new DoricRemoteJSExecutor();
|
||||||
|
injectGlobal();
|
||||||
}
|
}
|
||||||
injectGlobal();
|
changeEngineCallback.changed();
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
@ -8,6 +8,7 @@ import com.google.gson.JsonElement;
|
|||||||
import com.google.gson.JsonObject;
|
import com.google.gson.JsonObject;
|
||||||
import com.google.gson.JsonPrimitive;
|
import com.google.gson.JsonPrimitive;
|
||||||
|
|
||||||
|
import org.greenrobot.eventbus.EventBus;
|
||||||
import org.jetbrains.annotations.NotNull;
|
import org.jetbrains.annotations.NotNull;
|
||||||
import org.json.JSONObject;
|
import org.json.JSONObject;
|
||||||
|
|
||||||
@ -23,6 +24,7 @@ import okhttp3.Request;
|
|||||||
import okhttp3.Response;
|
import okhttp3.Response;
|
||||||
import okhttp3.WebSocket;
|
import okhttp3.WebSocket;
|
||||||
import okhttp3.WebSocketListener;
|
import okhttp3.WebSocketListener;
|
||||||
|
import pub.doric.dev.event.QuitDebugEvent;
|
||||||
import pub.doric.utils.DoricUtils;
|
import pub.doric.utils.DoricUtils;
|
||||||
|
|
||||||
public class RemoteJSExecutor {
|
public class RemoteJSExecutor {
|
||||||
@ -56,7 +58,10 @@ public class RemoteJSExecutor {
|
|||||||
throw new RuntimeException("remote js executor cannot connect");
|
throw new RuntimeException("remote js executor cannot connect");
|
||||||
} else if (t instanceof EOFException) {
|
} else if (t instanceof EOFException) {
|
||||||
// 被远端强制断开
|
// 被远端强制断开
|
||||||
throw new RuntimeException("remote js executor eof");
|
System.out.println("remote js executor eof");
|
||||||
|
|
||||||
|
LockSupport.park(current);
|
||||||
|
EventBus.getDefault().post(new QuitDebugEvent());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -169,6 +174,6 @@ public class RemoteJSExecutor {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public void destroy() {
|
public void destroy() {
|
||||||
webSocket.close(0, "destroy");
|
webSocket.close(1000, "destroy");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user