mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-19 16:38:41 +00:00
追加测试server的逻辑
This commit is contained in:
parent
52fe01c01b
commit
bacf6817ad
@ -1,19 +1,22 @@
|
||||
import CCP from "cc-plugin/src/ccp/entry-render";
|
||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||
import { TestClient, testServer, TestServer } from "./test/server";
|
||||
export type BackgroundCallback = (data: PluginEvent, sender: any) => void;
|
||||
class ConnectBackground {
|
||||
class ConnectBackground implements TestClient {
|
||||
connect: chrome.runtime.Port | null = null;
|
||||
|
||||
constructor() {
|
||||
this._initConnect();
|
||||
}
|
||||
|
||||
private _initConnect() {
|
||||
if (chrome && chrome.runtime) {
|
||||
if (CCP.Adaptation.Env.isChromeRuntime) {
|
||||
this.connect = chrome.runtime.connect({ name: Page.Devtools });
|
||||
this.connect.onDisconnect.addListener(() => {
|
||||
console.log(`%c[Connect-Dis]`, "color:red;")
|
||||
this.connect = null;
|
||||
})
|
||||
} else {
|
||||
testServer.add(this);
|
||||
}
|
||||
}
|
||||
/**
|
||||
@ -28,16 +31,20 @@ class ConnectBackground {
|
||||
});
|
||||
}
|
||||
}
|
||||
testMessage(data: PluginEvent) {
|
||||
recv(event: PluginEvent): void {
|
||||
this.doCallback(event);
|
||||
}
|
||||
doCallback(data: PluginEvent) {
|
||||
if (this.callback) {
|
||||
this.callback(data, null);
|
||||
}
|
||||
}
|
||||
sendMsgToContentScript(msg: Msg, data?: any) {
|
||||
if (!chrome || !chrome.devtools) {
|
||||
return;
|
||||
if (CCP.Adaptation.Env.isChromeDevtools) {
|
||||
this.postMessageToBackground(msg, data);
|
||||
} else {
|
||||
testServer.recv(msg, data);
|
||||
}
|
||||
this.postMessageToBackground(msg, data);
|
||||
}
|
||||
postMessageToBackground(msg: Msg, data?: any) {
|
||||
if (this.connect) {
|
||||
|
@ -259,6 +259,12 @@ export class Group {
|
||||
}
|
||||
|
||||
export interface NodeInfoData {
|
||||
uuid: string;// 节点的uuid
|
||||
/**
|
||||
* 节点的uuid
|
||||
*/
|
||||
uuid: string;
|
||||
/**
|
||||
* 组件数据
|
||||
*/
|
||||
group: Group[];
|
||||
}
|
||||
|
@ -23,7 +23,7 @@
|
||||
</slot>
|
||||
</CCInput>
|
||||
<div class="treeList">
|
||||
<CCTree :value="treeData"></CCTree>
|
||||
<CCTree :value="treeData" @node-click="handleNodeClick"></CCTree>
|
||||
<!-- <el-tree
|
||||
:data="treeData"
|
||||
ref="tree"
|
||||
@ -78,10 +78,10 @@ import Bus, { BusMsg } from "./bus";
|
||||
import { connectBackground } from "./connectBackground";
|
||||
import { EngineData, FrameDetails, Info, NodeInfoData, ObjectData, ObjectItemRequestData, TreeData } from "./data";
|
||||
import { appStore, RefreshType } from "./store";
|
||||
import Test from "./test.vue";
|
||||
ccui.components.CCAd;
|
||||
import Test from "./test/test.vue";
|
||||
import properties from "./ui/propertys.vue";
|
||||
import SettingsVue from "./ui/settings.vue";
|
||||
ccui.components.CCAd;
|
||||
const { CCTree, CCFootBar, CCDialog, CCInput, CCButton, CCInputNumber, CCSelect, CCButtonGroup, CCCheckBox, CCColor, CCDivider } = ccui.components;
|
||||
interface FrameInfo {
|
||||
label: string;
|
||||
|
46
cc-inspector/src/views/devtools/test/server.ts
Normal file
46
cc-inspector/src/views/devtools/test/server.ts
Normal file
@ -0,0 +1,46 @@
|
||||
import { Msg, Page, PluginEvent } from "../../../core/types";
|
||||
import { NodeInfoData, TreeData } from "../data";
|
||||
export class TestClient {
|
||||
recv(event: PluginEvent) {
|
||||
|
||||
}
|
||||
}
|
||||
export class TestServer {
|
||||
private clients: TestClient[] = [];
|
||||
add(client: TestClient) {
|
||||
this.clients.push(client);
|
||||
}
|
||||
recv(msg: string, data: any) {
|
||||
switch (msg) {
|
||||
case Msg.NodeInfo: {
|
||||
console.log(data);
|
||||
const ret: NodeInfoData = {
|
||||
uuid: "1",
|
||||
group: []
|
||||
};
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.NodeInfo, ret);
|
||||
this.send(event);
|
||||
break;
|
||||
}
|
||||
case Msg.TreeInfo: {
|
||||
const data: TreeData = {
|
||||
id: "1",
|
||||
text: "root",
|
||||
active: true,
|
||||
children: [],
|
||||
};
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, data);
|
||||
this.send(event);
|
||||
break;
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
send(event: PluginEvent) {
|
||||
this.clients.forEach((client) => {
|
||||
client.recv(event)
|
||||
});
|
||||
}
|
||||
}
|
||||
export const testServer = new TestServer();
|
@ -11,9 +11,10 @@
|
||||
import ccui from "@xuyanfeng/cc-ui";
|
||||
import { ITreeData } from "@xuyanfeng/cc-ui/types/cc-tree/const";
|
||||
import { defineComponent, ref } from "vue";
|
||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||
import { connectBackground } from "./connectBackground";
|
||||
import { TreeData } from "./data";
|
||||
import { Msg, Page, PluginEvent } from "../../../core/types";
|
||||
import { connectBackground } from "../connectBackground";
|
||||
import { TreeData } from "../data";
|
||||
import { TestServer } from "./server";
|
||||
const { CCButton, CCSection } = ccui.components;
|
||||
export default defineComponent({
|
||||
name: "test",
|
||||
@ -40,7 +41,7 @@ export default defineComponent({
|
||||
children: [],
|
||||
};
|
||||
const event = new PluginEvent(Page.Inject, Page.Devtools, Msg.TreeInfo, data);
|
||||
connectBackground.testMessage(event);
|
||||
connectBackground.doCallback(event);
|
||||
},
|
||||
};
|
||||
},
|
@ -398,7 +398,7 @@
|
||||
|
||||
"@types/chrome@0.0.133":
|
||||
version "0.0.133"
|
||||
resolved "http://mirrors.cloud.tencent.com/npm/@types/chrome/-/chrome-0.0.133.tgz#9e1d55441584ba2d5274ca84db36427da9c5dc6e"
|
||||
resolved "https://mirrors.cloud.tencent.com/npm/@types/chrome/-/chrome-0.0.133.tgz#9e1d55441584ba2d5274ca84db36427da9c5dc6e"
|
||||
integrity sha512-G8uIUdaCTBILprQvQXBWGXZxjAWbkCkFQit17cdH3zYQEwU8f/etNl8+M7e8MRz9Xj8daHaVpysneMZMx8/ldQ==
|
||||
dependencies:
|
||||
"@types/filesystem" "*"
|
||||
@ -461,16 +461,16 @@
|
||||
"@types/serve-static" "*"
|
||||
|
||||
"@types/filesystem@*":
|
||||
version "0.0.35"
|
||||
resolved "http://mirrors.cloud.tencent.com/npm/@types/filesystem/-/filesystem-0.0.35.tgz#6d6766626083e2b397c09bdc57092827120db11d"
|
||||
integrity sha512-1eKvCaIBdrD2mmMgy5dwh564rVvfEhZTWVQQGRNn0Nt4ZEnJ0C8oSUCzvMKRA4lGde5oEVo+q2MrTTbV/GHDCQ==
|
||||
version "0.0.36"
|
||||
resolved "https://mirrors.cloud.tencent.com/npm/@types/filesystem/-/filesystem-0.0.36.tgz#7227c2d76bfed1b21819db310816c7821d303857"
|
||||
integrity sha512-vPDXOZuannb9FZdxgHnqSwAG/jvdGM8Wq+6N4D/d80z+D4HWH+bItqsZaVRQykAn6WEVeEkLm2oQigyHtgb0RA==
|
||||
dependencies:
|
||||
"@types/filewriter" "*"
|
||||
|
||||
"@types/filewriter@*":
|
||||
version "0.0.32"
|
||||
resolved "http://mirrors.cloud.tencent.com/npm/@types/filewriter/-/filewriter-0.0.32.tgz#3cf7e0f870e54e60ed1bbd9280fa24a9444d3b48"
|
||||
integrity sha512-Kpi2GXQyYJdjL8mFclL1eDgihn1SIzorMZjD94kdPZh9E4VxGOeyjPxi5LpsM4Zku7P0reqegZTt2GxhmA9VBg==
|
||||
version "0.0.33"
|
||||
resolved "https://mirrors.cloud.tencent.com/npm/@types/filewriter/-/filewriter-0.0.33.tgz#d9d611db9d9cd99ae4e458de420eeb64ad604ea8"
|
||||
integrity sha512-xFU8ZXTw4gd358lb2jw25nxY9QAgqn2+bKKjKOYfNCzN4DKCFetK7sPtrlpg66Ywe3vWY9FNxprZawAh9wfJ3g==
|
||||
|
||||
"@types/fs-extra@9.0.1":
|
||||
version "9.0.1"
|
||||
@ -488,9 +488,9 @@
|
||||
"@types/node" "*"
|
||||
|
||||
"@types/har-format@*":
|
||||
version "1.2.15"
|
||||
resolved "http://mirrors.cloud.tencent.com/npm/@types/har-format/-/har-format-1.2.15.tgz#f352493638c2f89d706438a19a9eb300b493b506"
|
||||
integrity sha512-RpQH4rXLuvTXKR0zqHq3go0RVXYv/YVqv4TnPH95VbwUxZdQlK1EtcMvQvMpDngHbt13Csh9Z4qT9AbkiQH5BA==
|
||||
version "1.2.16"
|
||||
resolved "https://mirrors.cloud.tencent.com/npm/@types/har-format/-/har-format-1.2.16.tgz#b71ede8681400cc08b3685f061c31e416cf94944"
|
||||
integrity sha512-fluxdy7ryD3MV6h8pTfTYpy/xQzCFC7m89nOH9y94cNqJ1mDIDPut7MnRHI3F6qRmh/cT2fUjG1MLdCNb4hE9A==
|
||||
|
||||
"@types/html-minifier-terser@^6.0.0":
|
||||
version "6.1.0"
|
||||
@ -1943,7 +1943,7 @@ case-sensitive-paths-webpack-plugin@^2.3.0:
|
||||
integrity sha512-roIFONhcxog0JSSWbvVAh3OocukmSgpqOH6YpMkCvav/ySIV3JKg4Dc8vYtQjYi/UxpNE36r/9v+VqTQqgkYmw==
|
||||
|
||||
"cc-plugin@file:.yalc/cc-plugin":
|
||||
version "2.1.60"
|
||||
version "2.1.65"
|
||||
dependencies:
|
||||
"@babel/generator" "^7.16.8"
|
||||
"@popperjs/core" "^2.11.6"
|
||||
|
Loading…
x
Reference in New Issue
Block a user