code refactor
This commit is contained in:
parent
63550af3ad
commit
c55da9c640
@ -7,10 +7,11 @@ import pub.doric.DoricNativeDriver;
|
||||
public class DoricContextDebuggable {
|
||||
private DoricContext doricContext;
|
||||
private DoricDebugDriver doricDebugDriver;
|
||||
public static boolean isDebugging = false;
|
||||
public boolean isDebugging = false;
|
||||
|
||||
public DoricContextDebuggable(String contextId) {
|
||||
this.doricContext = DoricContextManager.getContext(contextId);
|
||||
isDebugging = true;
|
||||
}
|
||||
|
||||
public void startDebug() {
|
||||
|
@ -80,7 +80,7 @@ public class WSClient extends WebSocketListener {
|
||||
break;
|
||||
case "SWITCH_TO_DEBUG": {
|
||||
String contextId = jsonObject.optString("contextId");
|
||||
EventBus.getDefault().post(new EnterDebugEvent(contextId));
|
||||
EventBus.getDefault().post(new EnterDebugEvent());
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
@ -2,13 +2,4 @@ package pub.doric.devkit.event;
|
||||
|
||||
public class EnterDebugEvent {
|
||||
|
||||
private String contextId;
|
||||
|
||||
public EnterDebugEvent(String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,13 @@
|
||||
package pub.doric.devkit.event;
|
||||
|
||||
public class StartDebugEvent {
|
||||
private String contextId;
|
||||
|
||||
public StartDebugEvent(String contextId) {
|
||||
this.contextId = contextId;
|
||||
}
|
||||
|
||||
public String getContextId() {
|
||||
return contextId;
|
||||
}
|
||||
}
|
@ -1,4 +1,5 @@
|
||||
package pub.doric.devkit.event;
|
||||
|
||||
public class QuitDebugEvent {
|
||||
public class StopDebugEvent {
|
||||
|
||||
}
|
@ -25,7 +25,7 @@ import okhttp3.WebSocket;
|
||||
import okhttp3.WebSocketListener;
|
||||
import pub.doric.devkit.DevKit;
|
||||
import pub.doric.devkit.IStatusCallback;
|
||||
import pub.doric.devkit.event.QuitDebugEvent;
|
||||
import pub.doric.devkit.event.StopDebugEvent;
|
||||
|
||||
public class RemoteJSExecutor {
|
||||
private final WebSocket webSocket;
|
||||
@ -59,7 +59,7 @@ public class RemoteJSExecutor {
|
||||
System.out.println("remote js executor eof");
|
||||
|
||||
LockSupport.unpark(current);
|
||||
EventBus.getDefault().post(new QuitDebugEvent());
|
||||
EventBus.getDefault().post(new StopDebugEvent());
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -15,12 +15,14 @@ import androidx.fragment.app.DialogFragment;
|
||||
|
||||
import com.google.gson.JsonObject;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.devkit.DoricContextDebuggable;
|
||||
import pub.doric.devkit.DoricDev;
|
||||
import pub.doric.devkit.IDevKit;
|
||||
import pub.doric.devkit.R;
|
||||
import pub.doric.devkit.event.StartDebugEvent;
|
||||
|
||||
public class DebugContextPanel extends DialogFragment {
|
||||
|
||||
@ -69,7 +71,7 @@ public class DebugContextPanel extends DialogFragment {
|
||||
cell.findViewById(R.id.debug_text_view).setOnClickListener(new View.OnClickListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
DoricContextDebuggable.isDebugging = true;
|
||||
EventBus.getDefault().post(new StartDebugEvent(doricContext.getContextId()));
|
||||
JsonObject jsonObject = new JsonObject();
|
||||
jsonObject.addProperty("contextId", doricContext.getContextId());
|
||||
jsonObject.addProperty("source", doricContext.getSource().replace(".js", ".ts"));
|
||||
|
@ -30,8 +30,9 @@ import pub.doric.DoricContext;
|
||||
import pub.doric.DoricContextManager;
|
||||
import pub.doric.devkit.DoricContextDebuggable;
|
||||
import pub.doric.devkit.event.EnterDebugEvent;
|
||||
import pub.doric.devkit.event.QuitDebugEvent;
|
||||
import pub.doric.devkit.event.ReloadEvent;
|
||||
import pub.doric.devkit.event.StartDebugEvent;
|
||||
import pub.doric.devkit.event.StopDebugEvent;
|
||||
import pub.doric.devkit.util.SensorManagerHelper;
|
||||
|
||||
/**
|
||||
@ -77,30 +78,36 @@ public class DemoDebugActivity extends DoricActivity {
|
||||
sensorHelper.stop();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onStartDebugEvent(StartDebugEvent startDebugEvent) {
|
||||
doricContextDebuggable = new DoricContextDebuggable(startDebugEvent.getContextId());
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onEnterDebugEvent(EnterDebugEvent enterDebugEvent) {
|
||||
doricContextDebuggable = new DoricContextDebuggable(enterDebugEvent.getContextId());
|
||||
doricContextDebuggable.startDebug();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onQuitDebugEvent(StopDebugEvent quitDebugEvent) {
|
||||
doricContextDebuggable.stopDebug();
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onReloadEvent(ReloadEvent reloadEvent) {
|
||||
if (DoricContextDebuggable.isDebugging) {
|
||||
System.out.println("is debugging");
|
||||
} else {
|
||||
for (DoricContext context : DoricContextManager.aliveContexts()) {
|
||||
if (reloadEvent.source.contains(context.getSource())) {
|
||||
for (DoricContext context : DoricContextManager.aliveContexts()) {
|
||||
if (reloadEvent.source.contains(context.getSource())) {
|
||||
if (doricContextDebuggable != null &&
|
||||
doricContextDebuggable.isDebugging &&
|
||||
doricContextDebuggable.getContext().getContextId().equals(context.getContextId())) {
|
||||
System.out.println("is debugging context id: " + context.getContextId());
|
||||
} else {
|
||||
context.reload(reloadEvent.script);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Subscribe(threadMode = ThreadMode.MAIN)
|
||||
public void onQuitDebugEvent(QuitDebugEvent quitDebugEvent) {
|
||||
doricContextDebuggable.stopDebug();
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onKeyDown(int keyCode, KeyEvent event) {
|
||||
if (KeyEvent.KEYCODE_MENU == event.getKeyCode()) {
|
||||
|
Reference in New Issue
Block a user