debug panel update

This commit is contained in:
王劲鹏 2019-11-20 15:50:19 +08:00
parent fdc77dcd0e
commit 3d488f85c8
7 changed files with 145 additions and 15 deletions

View File

@ -0,0 +1,78 @@
package pub.doric.dev;
import android.app.Dialog;
import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.view.Window;
import android.widget.LinearLayout;
import android.widget.TextView;
import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import androidx.fragment.app.DialogFragment;
import com.google.gson.JsonObject;
import pub.doric.BuildConfig;
import pub.doric.Doric;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.R;
public class DebugContextPanel extends DialogFragment {
@Nullable
@Override
public View onCreateView(
@NonNull LayoutInflater inflater,
@Nullable ViewGroup container,
@Nullable Bundle savedInstanceState
) {
return inflater.inflate(R.layout.layout_debug_context, container, false);
}
@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {
Dialog dialog = super.onCreateDialog(savedInstanceState);
dialog.getWindow().requestFeature(Window.FEATURE_NO_TITLE);
return dialog;
}
@Override
public void onStart() {
super.onStart();
Dialog dialog = getDialog();
if (dialog != null) {
dialog.getWindow().setLayout(ViewGroup.LayoutParams.MATCH_PARENT, ViewGroup.LayoutParams.MATCH_PARENT);
}
LinearLayout container = getView().findViewById(R.id.container);
LayoutInflater inflater = LayoutInflater.from(getContext());
for (final DoricContext doricContext : DoricContextManager.aliveContexts()) {
View cell = inflater.inflate(R.layout.layout_debug_context_cell, container, false);
TextView contextIdTextView = cell.findViewById(R.id.context_id_text_view);
contextIdTextView.setText(doricContext.getContextId());
TextView sourceTextView = cell.findViewById(R.id.source_text_view);
sourceTextView.setText(doricContext.getSource());
cell.findViewById(R.id.debug_text_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("contextId", doricContext.getContextId());
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
jsonObject.addProperty("source", doricContext.getSource().replace(".js", ".ts"));
Doric.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
}
});
container.addView(cell);
}
}
}

View File

@ -6,6 +6,8 @@ import pub.doric.utils.DoricUtils;
public class DevKit implements IDevKit {
public static boolean isRunningInEmulator = false;
private static class Inner {
private static final DevKit sInstance = new DevKit();
}

View File

@ -13,7 +13,6 @@ import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.google.android.material.bottomsheet.BottomSheetDialogFragment;
import com.google.gson.JsonObject;
import com.lahm.library.EasyProtectorLib;
import com.lahm.library.EmulatorCheckCallback;
import com.tbruyelle.rxpermissions2.RxPermissions;
@ -24,10 +23,7 @@ import org.greenrobot.eventbus.ThreadMode;
import io.reactivex.disposables.Disposable;
import io.reactivex.functions.Consumer;
import pub.doric.BuildConfig;
import pub.doric.Doric;
import pub.doric.DoricContext;
import pub.doric.DoricContextManager;
import pub.doric.R;
import pub.doric.dev.event.ConnectExceptionEvent;
import pub.doric.dev.event.EOFExceptionEvent;
@ -35,7 +31,6 @@ import pub.doric.dev.event.OpenEvent;
public class DevPanel extends BottomSheetDialogFragment {
private boolean isRunningInEmulator = false;
static boolean isDevConnected = false;
public DevPanel() {
@ -61,7 +56,7 @@ public class DevPanel extends BottomSheetDialogFragment {
getView().findViewById(R.id.connect_dev_kit_text_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (isRunningInEmulator) {
if (DevKit.isRunningInEmulator) {
Doric.connectDevKit("ws://" + "10.0.2.2" + ":7777");
} else {
final RxPermissions rxPermissions = new RxPermissions(DevPanel.this);
@ -83,12 +78,8 @@ public class DevPanel extends BottomSheetDialogFragment {
getView().findViewById(R.id.debug_text_view).setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
for (DoricContext doricContext : DoricContextManager.aliveContexts()) {
JsonObject jsonObject = new JsonObject();
jsonObject.addProperty("contextId", doricContext.getContextId());
jsonObject.addProperty("projectHome", BuildConfig.PROJECT_HOME);
Doric.sendDevCommand(IDevKit.Command.DEBUG, jsonObject);
}
DebugContextPanel debugContextPanel = new DebugContextPanel();
debugContextPanel.show(getActivity().getSupportFragmentManager(), "DebugContextPanel");
dismissAllowingStateLoss();
}
});
@ -98,7 +89,7 @@ public class DevPanel extends BottomSheetDialogFragment {
public void onAttach(@NonNull Context context) {
super.onAttach(context);
EventBus.getDefault().register(this);
isRunningInEmulator = EasyProtectorLib.checkIsRunningInEmulator(context, new EmulatorCheckCallback() {
DevKit.isRunningInEmulator = EasyProtectorLib.checkIsRunningInEmulator(context, new EmulatorCheckCallback() {
@Override
public void findEmulator(String emulatorInfo) {
System.out.println(emulatorInfo);

View File

@ -23,6 +23,7 @@ import okhttp3.Request;
import okhttp3.Response;
import okhttp3.WebSocket;
import okhttp3.WebSocketListener;
import pub.doric.dev.DevKit;
import pub.doric.dev.event.QuitDebugEvent;
public class RemoteJSExecutor {
@ -36,7 +37,13 @@ public class RemoteJSExecutor {
.readTimeout(10, TimeUnit.SECONDS)
.writeTimeout(10, TimeUnit.SECONDS)
.build();
final Request request = new Request.Builder().url("ws://192.168.24.79:2080").build();
String ip;
if (DevKit.isRunningInEmulator) {
ip = "10.0.2.2";
} else {
ip = "192.168.24.79";
}
final Request request = new Request.Builder().url("ws://" + ip + ":2080").build();
final Thread current = Thread.currentThread();
webSocket = okHttpClient.newWebSocket(request, new WebSocketListener() {

View File

@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent">
<LinearLayout
android:id="@+id/container"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
</LinearLayout>
</ScrollView>

View File

@ -0,0 +1,38 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:id="@+id/context_id_text_view"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:gravity="center"
android:singleLine="true"
android:text="{Context Id}"
android:textSize="20sp" />
<TextView
android:id="@+id/source_text_view"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="3"
android:gravity="center"
android:singleLine="true"
android:text="{Source}"
android:textSize="20sp" />
<TextView
android:id="@+id/debug_text_view"
android:layout_width="0dp"
android:layout_height="60dp"
android:layout_weight="1"
android:background="#ff0000"
android:gravity="center"
android:singleLine="true"
android:text="Debug"
android:textColor="#ffffff"
android:textSize="20sp" />
</LinearLayout>

View File

@ -30,9 +30,10 @@ const createServer = () => {
let contextId = resultObject.data.contextId
let projectHome = resultObject.data.projectHome
let source = resultObject.data.source
console.log(connection.key + " request debug, project home: " + projectHome)
spawn('code', [projectHome, projectHome + "/src/Snake.ts"])
spawn('code', [projectHome, projectHome + "/src/" + source])
setTimeout(() => {
exec('osascript -e \'tell application "System Events"\ntell application "Visual Studio Code" to activate\nkey code 96\nend tell\'', (err, stdout, stderr) => {
if (err) {