mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-20 00:48:43 +00:00
代码梳理
This commit is contained in:
parent
05a2483a4b
commit
326d02cfdc
@ -26,8 +26,14 @@ export class PluginEvent {
|
|||||||
msg: Msg | null = null;
|
msg: Msg | null = null;
|
||||||
data: any = null;
|
data: any = null;
|
||||||
|
|
||||||
source: Page | null = null; // 事件发送的源头
|
/**
|
||||||
target: Page | null = null; // 事件要发送的目标
|
* 事件发送的源头
|
||||||
|
*/
|
||||||
|
source: Page | null = null;
|
||||||
|
/**
|
||||||
|
* 事件要发送的目标
|
||||||
|
*/
|
||||||
|
target: Page | null = null;
|
||||||
|
|
||||||
static check(event: PluginEvent, source: Page, target: Page) {
|
static check(event: PluginEvent, source: Page, target: Page) {
|
||||||
return event && source && target && event.source === source && event.target === target;
|
return event && source && target && event.source === source && event.target === target;
|
||||||
@ -40,6 +46,9 @@ export class PluginEvent {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
*
|
||||||
|
*/
|
||||||
static finish(event: PluginEvent) {
|
static finish(event: PluginEvent) {
|
||||||
event.source = event.target = null;
|
event.source = event.target = null;
|
||||||
}
|
}
|
||||||
|
@ -41,7 +41,7 @@ class CCInspector {
|
|||||||
clearInterval(timer);
|
clearInterval(timer);
|
||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, () => {
|
cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, () => {
|
||||||
let isCocosGame = this._isCocosGame();
|
const isCocosGame = this._isCocosGame();
|
||||||
this.notifySupportGame(isCocosGame);
|
this.notifySupportGame(isCocosGame);
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -126,10 +126,7 @@ class CCInspector {
|
|||||||
|
|
||||||
sendMsgToContent(msg: Msg, data: any) {
|
sendMsgToContent(msg: Msg, data: any) {
|
||||||
// 发送给content.js处理,也会导致发送给了自身,死循环
|
// 发送给content.js处理,也会导致发送给了自身,死循环
|
||||||
window.postMessage(
|
window.postMessage(new PluginEvent(Page.Inject, Page.Content, msg, data), "*");
|
||||||
new PluginEvent(Page.Inject, Page.Content, msg, data),
|
|
||||||
"*"
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
notifySupportGame(b: boolean) {
|
notifySupportGame(b: boolean) {
|
||||||
@ -536,7 +533,7 @@ class CCInspector {
|
|||||||
let keyDesc = "";
|
let keyDesc = "";
|
||||||
if (Array.isArray(propValue)) {
|
if (Array.isArray(propValue)) {
|
||||||
// 只收集一级key
|
// 只收集一级key
|
||||||
propValue.forEach((item) => {});
|
propValue.forEach((item) => { });
|
||||||
keyDesc = `(${propValue.length}) [...]`;
|
keyDesc = `(${propValue.length}) [...]`;
|
||||||
} else if (this._isInvalidValue(propValue)) {
|
} else if (this._isInvalidValue(propValue)) {
|
||||||
// 不能改变顺序
|
// 不能改变顺序
|
||||||
@ -581,7 +578,7 @@ class CCInspector {
|
|||||||
const name = this.getCompName(node);
|
const name = this.getCompName(node);
|
||||||
let nodeGroup = new Group(name, node.uuid);
|
let nodeGroup = new Group(name, node.uuid);
|
||||||
let keys = this._getNodeKeys(node);
|
let keys = this._getNodeKeys(node);
|
||||||
for (let i = 0; i < keys.length; ) {
|
for (let i = 0; i < keys.length;) {
|
||||||
let key = keys[i];
|
let key = keys[i];
|
||||||
let pair = this._getPairProperty(key);
|
let pair = this._getPairProperty(key);
|
||||||
if (pair && this._checkKeysValid(node, pair.values)) {
|
if (pair && this._checkKeysValid(node, pair.values)) {
|
||||||
@ -730,7 +727,7 @@ class CCInspector {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
let inspector = new CCInspector();
|
const inspector = new CCInspector();
|
||||||
inspector.init();
|
inspector.init();
|
||||||
//@ts-ignore
|
//@ts-ignore
|
||||||
window.CCInspector = inspector;
|
window.CCInspector = inspector;
|
||||||
|
@ -24,7 +24,13 @@ class ConnectBackground {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sendMsgToContentScript(msg: Msg, data?: any) {
|
||||||
|
if (!chrome || !chrome.devtools) {
|
||||||
|
console.log("环境异常,无法执行函数");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this.postMessageToBackground(msg, data);
|
||||||
|
}
|
||||||
postMessageToBackground(msg: Msg, data?: any) {
|
postMessageToBackground(msg: Msg, data?: any) {
|
||||||
if (this.connect) {
|
if (this.connect) {
|
||||||
let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data)
|
let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data)
|
||||||
|
@ -1,5 +1,4 @@
|
|||||||
import { createApp } from "vue";
|
import { createApp } from "vue";
|
||||||
// 用的是ui/index.vue
|
|
||||||
import App from "./index.vue";
|
import App from "./index.vue";
|
||||||
import CCP from "cc-plugin/src/ccp/entry-render";
|
import CCP from "cc-plugin/src/ccp/entry-render";
|
||||||
import pluginConfig from "../../../cc-plugin.config";
|
import pluginConfig from "../../../cc-plugin.config";
|
||||||
|
@ -7,7 +7,7 @@
|
|||||||
</el-drawer> -->
|
</el-drawer> -->
|
||||||
<div class="head" v-show="iframes.length > 1">
|
<div class="head" v-show="iframes.length > 1">
|
||||||
<div class="label">inspect target:</div>
|
<div class="label">inspect target:</div>
|
||||||
<CCSelect v-model="frameID" placeholder="please select ..." @change="onChangeFrame" :data="getFramesData()" style="flex: 1"> </CCSelect>
|
<CCSelect v-model:value="frameID" placeholder="please select ..." @change="onChangeFrame" :data="getFramesData()"> </CCSelect>
|
||||||
</div>
|
</div>
|
||||||
<div v-show="isShowDebug" class="find">
|
<div v-show="isShowDebug" class="find">
|
||||||
<div v-if="false">
|
<div v-if="false">
|
||||||
@ -27,6 +27,7 @@
|
|||||||
</slot>
|
</slot>
|
||||||
</CCInput>
|
</CCInput>
|
||||||
<div class="treeList">
|
<div class="treeList">
|
||||||
|
<CCTree></CCTree>
|
||||||
<!-- <el-tree
|
<!-- <el-tree
|
||||||
:data="treeData"
|
:data="treeData"
|
||||||
ref="tree"
|
ref="tree"
|
||||||
@ -71,7 +72,7 @@ import { defineComponent, reactive, PropType, ref, onMounted, watch, toRaw, next
|
|||||||
import properties from "./ui/propertys.vue";
|
import properties from "./ui/propertys.vue";
|
||||||
import { Option } from "@xuyanfeng/cc-ui/types/cc-select/const";
|
import { Option } from "@xuyanfeng/cc-ui/types/cc-select/const";
|
||||||
import ccui from "@xuyanfeng/cc-ui";
|
import ccui from "@xuyanfeng/cc-ui";
|
||||||
const { CCInput, CCButton, CCInputNumber, CCSelect, CCButtonGroup, CCCheckBox, CCColor, CCDivider } = ccui.components;
|
const { CCTree, CCInput, CCButton, CCInputNumber, CCSelect, CCButtonGroup, CCCheckBox, CCColor, CCDivider } = ccui.components;
|
||||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||||
import { connectBackground } from "./connectBackground";
|
import { connectBackground } from "./connectBackground";
|
||||||
import { EngineData, FrameDetails, Info, NodeInfoData, ObjectData, ObjectItemRequestData, TreeData } from "./data";
|
import { EngineData, FrameDetails, Info, NodeInfoData, ObjectData, ObjectItemRequestData, TreeData } from "./data";
|
||||||
@ -79,13 +80,14 @@ import Bus, { BusMsg } from "./bus";
|
|||||||
import SettingsVue from "./ui/settings.vue";
|
import SettingsVue from "./ui/settings.vue";
|
||||||
import { RefreshType, settings } from "./settings";
|
import { RefreshType, settings } from "./settings";
|
||||||
import { ButtonGroupItem } from "@xuyanfeng/cc-ui/types/cc-button-group/const";
|
import { ButtonGroupItem } from "@xuyanfeng/cc-ui/types/cc-button-group/const";
|
||||||
|
import { ITreeData } from "@xuyanfeng/cc-ui/types/cc-tree/const";
|
||||||
interface FrameInfo {
|
interface FrameInfo {
|
||||||
label: string;
|
label: string;
|
||||||
value: number;
|
value: number;
|
||||||
}
|
}
|
||||||
|
|
||||||
export default defineComponent({
|
export default defineComponent({
|
||||||
components: { CCDivider, CCButtonGroup, properties, SettingsVue, CCInput, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor },
|
components: { CCTree, CCDivider, CCButtonGroup, properties, SettingsVue, CCInput, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor },
|
||||||
name: "devtools",
|
name: "devtools",
|
||||||
props: {},
|
props: {},
|
||||||
setup(props, ctx) {
|
setup(props, ctx) {
|
||||||
@ -94,7 +96,6 @@ export default defineComponent({
|
|||||||
const isShowDebug = ref<boolean>(true);
|
const isShowDebug = ref<boolean>(true);
|
||||||
const frameID = ref<number>(0);
|
const frameID = ref<number>(0);
|
||||||
const iframes = ref<Array<FrameInfo>>([]);
|
const iframes = ref<Array<FrameInfo>>([]);
|
||||||
|
|
||||||
const btnRefresh: ButtonGroupItem = reactive<ButtonGroupItem>({
|
const btnRefresh: ButtonGroupItem = reactive<ButtonGroupItem>({
|
||||||
icon: "icon_refresh",
|
icon: "icon_refresh",
|
||||||
click: () => {
|
click: () => {
|
||||||
@ -140,13 +141,6 @@ export default defineComponent({
|
|||||||
return circle(data);
|
return circle(data);
|
||||||
}
|
}
|
||||||
|
|
||||||
function sendMsgToContentScript(msg: Msg, data?: any) {
|
|
||||||
if (!chrome || !chrome.devtools) {
|
|
||||||
console.log("环境异常,无法执行函数");
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
connectBackground.postMessageToBackground(msg, data);
|
|
||||||
}
|
|
||||||
const requestList: Array<{ id: string; cb: Function }> = [];
|
const requestList: Array<{ id: string; cb: Function }> = [];
|
||||||
|
|
||||||
function _expand(uuid: string) {
|
function _expand(uuid: string) {
|
||||||
@ -262,12 +256,9 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
// 问题:没有上下文的权限,只能操作DOM
|
// 问题:没有上下文的权限,只能操作DOM
|
||||||
function _executeScript(para: Object) {
|
function _executeScript(para: Object) {
|
||||||
let tabID = chrome.devtools.inspectedWindow.tabId;
|
// chrome.tabs.executeScript()//v2版本使用的函数
|
||||||
//@ts-ignore
|
const tabID = chrome.devtools.inspectedWindow.tabId;
|
||||||
chrome.tabs.executeScript(tabID, { code: `var CCInspectorPara='${JSON.stringify(para)}';` }, () => {
|
chrome.scripting.executeScript({ files: ["js/execute.js"], target: { tabId: tabID } }, (results: chrome.scripting.InjectionResult[]) => {});
|
||||||
//@ts-ignore
|
|
||||||
chrome.tabs.executeScript(tabID, { file: "js/execute.js" });
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function _inspectedCode() {
|
function _inspectedCode() {
|
||||||
@ -282,6 +273,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
const elTree = ref<HTMLElement>();
|
const elTree = ref<HTMLElement>();
|
||||||
function _onMsgTreeInfo(treeData: Array<TreeData>) {
|
function _onMsgTreeInfo(treeData: Array<TreeData>) {
|
||||||
|
console.log("treeData");
|
||||||
isShowDebug.value = true;
|
isShowDebug.value = true;
|
||||||
if (!Array.isArray(treeData)) {
|
if (!Array.isArray(treeData)) {
|
||||||
treeData = [treeData];
|
treeData = [treeData];
|
||||||
@ -332,7 +324,7 @@ export default defineComponent({
|
|||||||
|
|
||||||
window.addEventListener(
|
window.addEventListener(
|
||||||
"message",
|
"message",
|
||||||
function (event) {
|
(event) => {
|
||||||
console.log("on vue:" + JSON.stringify(event));
|
console.log("on vue:" + JSON.stringify(event));
|
||||||
},
|
},
|
||||||
false
|
false
|
||||||
@ -346,10 +338,10 @@ export default defineComponent({
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
requestList.push({ id: data.id, cb });
|
requestList.push({ id: data.id, cb });
|
||||||
sendMsgToContentScript(Msg.GetObjectItemData, data);
|
connectBackground.sendMsgToContentScript(Msg.GetObjectItemData, data);
|
||||||
});
|
});
|
||||||
Bus.on(BusMsg.LogData, (data: string[]) => {
|
Bus.on(BusMsg.LogData, (data: string[]) => {
|
||||||
sendMsgToContentScript(Msg.LogData, data);
|
connectBackground.sendMsgToContentScript(Msg.LogData, data);
|
||||||
});
|
});
|
||||||
onMounted(() => {
|
onMounted(() => {
|
||||||
syncSettings();
|
syncSettings();
|
||||||
@ -416,7 +408,7 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
function updateNodeInfo() {
|
function updateNodeInfo() {
|
||||||
if (selectedUUID) {
|
if (selectedUUID) {
|
||||||
sendMsgToContentScript(Msg.NodeInfo, selectedUUID);
|
connectBackground.sendMsgToContentScript(Msg.NodeInfo, selectedUUID);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let selectedUUID: string | null = null;
|
let selectedUUID: string | null = null;
|
||||||
@ -424,10 +416,10 @@ export default defineComponent({
|
|||||||
(elTree.value as any)?.filter(val);
|
(elTree.value as any)?.filter(val);
|
||||||
}
|
}
|
||||||
function onBtnClickUpdateTree() {
|
function onBtnClickUpdateTree() {
|
||||||
sendMsgToContentScript(Msg.TreeInfo, frameID);
|
connectBackground.sendMsgToContentScript(Msg.TreeInfo, frameID);
|
||||||
}
|
}
|
||||||
function onChangeFrame() {
|
function onChangeFrame() {
|
||||||
sendMsgToContentScript(Msg.UseFrame, frameID);
|
connectBackground.sendMsgToContentScript(Msg.UseFrame, frameID);
|
||||||
}
|
}
|
||||||
const elLeft = ref<HTMLDivElement>();
|
const elLeft = ref<HTMLDivElement>();
|
||||||
return {
|
return {
|
||||||
@ -476,17 +468,15 @@ export default defineComponent({
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
||||||
onBtnClickUpdateTree,
|
|
||||||
|
|
||||||
onBtnClickUpdatePage() {
|
onBtnClickUpdatePage() {
|
||||||
sendMsgToContentScript(Msg.Support);
|
connectBackground.sendMsgToContentScript(Msg.Support);
|
||||||
},
|
},
|
||||||
onCloseSettings() {
|
onCloseSettings() {
|
||||||
syncSettings();
|
syncSettings();
|
||||||
},
|
},
|
||||||
|
|
||||||
onMemoryTest() {
|
onMemoryTest() {
|
||||||
sendMsgToContentScript(Msg.MemoryInfo);
|
connectBackground.sendMsgToContentScript(Msg.MemoryInfo);
|
||||||
},
|
},
|
||||||
|
|
||||||
onChangeFrame,
|
onChangeFrame,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user