mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-11-27 07:28:46 +00:00
将消息的请求和响应分离,便于维护
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
import { v4 } from "uuid";
|
||||
import { Msg, Page, PluginEvent } from "../../../core/types";
|
||||
import { Msg, Page, PluginEvent, RequestNodeInfoData, RequestObjectData, ResponseNodeInfoData, ResponseObjectData, ResponseTreeInfoData } from "../../../core/types";
|
||||
import { ArrayData, BoolData, ColorData, EngineData, EnumData, Group, ImageData, Info, InvalidData, NodeInfoData, NumberData, ObjectData, ObjectItemRequestData, Property, StringData, TextData, TreeData, Vec2Data, Vec3Data, Vec4Data } from "../data";
|
||||
export class TestClient {
|
||||
recv(event: PluginEvent) {}
|
||||
@@ -100,8 +100,8 @@ export class TestServer {
|
||||
}
|
||||
recv(msg: string, data: any) {
|
||||
switch (msg) {
|
||||
case Msg.NodeInfo: {
|
||||
const id: string = data as string;
|
||||
case Msg.RequestNodeInfo: {
|
||||
const id: string = (data as RequestNodeInfoData).uuid;
|
||||
const node: Node = this.testData.findNode(id);
|
||||
let group = [];
|
||||
if (node) {
|
||||
@@ -111,37 +111,37 @@ export class TestServer {
|
||||
group.push(g);
|
||||
}
|
||||
const ret: NodeInfoData = new NodeInfoData(id, group);
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.NodeInfo, ret);
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseNodeInfo, ret as ResponseNodeInfoData);
|
||||
this.send(event);
|
||||
break;
|
||||
}
|
||||
case Msg.TreeInfo: {
|
||||
case Msg.RequstTreeInfo: {
|
||||
const ret: TreeData = new TreeData();
|
||||
this.testData.toTreeData(ret);
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, ret);
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.ResponseTreeInfo, ret as ResponseTreeInfoData);
|
||||
this.send(event);
|
||||
break;
|
||||
}
|
||||
case Msg.SetProperty: {
|
||||
case Msg.RequestSetProperty: {
|
||||
console.log(data);
|
||||
break;
|
||||
}
|
||||
case Msg.GetObjectItemData: {
|
||||
const objData = data as ObjectData;
|
||||
case Msg.RequestObjectItemData: {
|
||||
const objData: RequestObjectData = data as ObjectData;
|
||||
const info = this.testData.findInfo(objData.id);
|
||||
if (info && info instanceof ObjectData) {
|
||||
const ret: ObjectItemRequestData = {
|
||||
id: objData.id,
|
||||
data: info.testProperty(),
|
||||
};
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.GetObjectItemData, ret);
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.ResponseObjectItemData, ret as ResponseObjectData);
|
||||
this.send(event);
|
||||
} else {
|
||||
console.warn("not found data: ", objData.id);
|
||||
}
|
||||
break;
|
||||
}
|
||||
case Msg.LogData: {
|
||||
case Msg.RequestLogData: {
|
||||
console.log(data);
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
import ccui from "@xuyanfeng/cc-ui";
|
||||
import { storeToRefs } from "pinia";
|
||||
import { defineComponent, ref } from "vue";
|
||||
import { Msg, Page, PluginEvent } from "../../../core/types";
|
||||
import { Msg, Page, PluginEvent, ResponseUpdateFramesData } from "../../../core/types";
|
||||
import { Terminal } from "../../../scripts/terminal";
|
||||
import { bridge } from "../bridge";
|
||||
import { FrameDetails, Group, InvalidData, NodeInfoData, TreeData } from "../data";
|
||||
@@ -31,7 +31,8 @@ export default defineComponent({
|
||||
},
|
||||
setup(props, { emit }) {
|
||||
const { config } = storeToRefs(appStore());
|
||||
const show = ref(__DEV__);
|
||||
// 仅在web环境显示
|
||||
const show = ref(__DEV__ && !(chrome && chrome.runtime));
|
||||
// 测试发送的是纯数据
|
||||
const testData = {
|
||||
uuid: "d1NHXHs35F1rbFJZKeigkl",
|
||||
@@ -74,7 +75,7 @@ export default defineComponent({
|
||||
},
|
||||
onTerminal() {
|
||||
const t = new Terminal("flag");
|
||||
const event = new PluginEvent(Page.Background, Page.Background, Msg.NodeInfo, "");
|
||||
const event = new PluginEvent(Page.Background, Page.Background, Msg.ResponseTreeInfo, "");
|
||||
console.log(...t.message("1"));
|
||||
console.log(...t.log("newline", true));
|
||||
console.log(...t.log("oneline", false));
|
||||
@@ -92,7 +93,7 @@ export default defineComponent({
|
||||
active: true,
|
||||
children: [],
|
||||
};
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, data);
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.ResponseTreeInfo, data);
|
||||
bridge.doMessage(event);
|
||||
},
|
||||
onFrames() {
|
||||
@@ -100,16 +101,16 @@ export default defineComponent({
|
||||
{ url: "url1", frameID: 1 },
|
||||
{ url: "url2", frameID: 2 },
|
||||
];
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.UpdateFrames, data);
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseUpdateFrames, data as ResponseUpdateFramesData);
|
||||
testServer.send(event);
|
||||
},
|
||||
onTestNodeInfo() {
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.NodeInfo, testData);
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseTreeInfo, testData);
|
||||
testServer.send(event);
|
||||
},
|
||||
onNull() {
|
||||
const data = new NodeInfoData("", [new Group("", "1").buildProperty("dependAssets", new InvalidData("Null"))]);
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.NodeInfo, data);
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseTreeInfo, data);
|
||||
testServer.send(event);
|
||||
},
|
||||
};
|
||||
|
||||
Reference in New Issue
Block a user