2024-01-05 16:45:23 +08:00
|
|
|
|
<template>
|
2024-01-09 12:02:47 +08:00
|
|
|
|
<div id="devtools">
|
2024-12-28 14:25:23 +08:00
|
|
|
|
<Test> </Test>
|
2024-01-09 12:02:47 +08:00
|
|
|
|
<div class="head" v-show="iframes.length > 1">
|
|
|
|
|
<div class="label">inspect target:</div>
|
2024-12-12 20:13:50 +08:00
|
|
|
|
<CCSelect v-model:value="frameID" @change="onChangeFrame" :data="getFramesData()"> </CCSelect>
|
2024-01-09 12:02:47 +08:00
|
|
|
|
</div>
|
2024-12-28 14:25:23 +08:00
|
|
|
|
<div v-if="isShowDebug" class="find">
|
2024-01-09 12:02:47 +08:00
|
|
|
|
<div v-if="false">
|
2024-01-09 15:33:34 +08:00
|
|
|
|
<CCButton type="success" @click="onMemoryTest">内存测试</CCButton>
|
2024-01-09 12:02:47 +08:00
|
|
|
|
<span>JS堆栈限制: {{ memory.performance.jsHeapSizeLimit }}</span>
|
|
|
|
|
<span>JS堆栈大小: {{ memory.performance.totalJSHeapSize }}</span>
|
|
|
|
|
<span>JS堆栈使用: {{ memory.performance.usedJSHeapSize }}</span>
|
|
|
|
|
</div>
|
2024-12-27 21:08:26 +08:00
|
|
|
|
<Hierarchy></Hierarchy>
|
2024-01-23 22:25:32 +08:00
|
|
|
|
<CCDivider></CCDivider>
|
2024-12-27 21:08:26 +08:00
|
|
|
|
<Inspector></Inspector>
|
2024-01-09 12:02:47 +08:00
|
|
|
|
</div>
|
2024-12-27 19:51:51 +08:00
|
|
|
|
<Find v-if="!isShowDebug"></Find>
|
2024-12-09 19:25:06 +08:00
|
|
|
|
<CCDialog></CCDialog>
|
|
|
|
|
<CCFootBar :version="version"></CCFootBar>
|
2024-01-09 12:02:47 +08:00
|
|
|
|
</div>
|
|
|
|
|
</template>
|
|
|
|
|
|
|
|
|
|
<script lang="ts">
|
2024-01-09 15:33:34 +08:00
|
|
|
|
import ccui from "@xuyanfeng/cc-ui";
|
2024-12-09 16:23:58 +08:00
|
|
|
|
import { Option } from "@xuyanfeng/cc-ui/types/cc-select/const";
|
2024-12-27 14:23:27 +08:00
|
|
|
|
import { storeToRefs } from "pinia";
|
2024-12-28 14:25:23 +08:00
|
|
|
|
import { defineComponent, onMounted, onUnmounted, ref, toRaw } from "vue";
|
2024-12-09 19:25:06 +08:00
|
|
|
|
import PluginConfig from "../../../cc-plugin.config";
|
2024-12-28 14:25:23 +08:00
|
|
|
|
import { Msg, PluginEvent, RequestUseFrameData, ResponseSupportData } from "../../core/types";
|
2024-12-24 21:09:13 +08:00
|
|
|
|
import { bridge } from "./bridge";
|
2024-12-27 21:08:26 +08:00
|
|
|
|
import { Bus, BusMsg } from "./bus";
|
|
|
|
|
import { FrameDetails, NodeInfoData, TreeData } from "./data";
|
2024-12-27 19:51:51 +08:00
|
|
|
|
import Find from "./find.vue";
|
2024-12-27 21:08:26 +08:00
|
|
|
|
import Hierarchy from "./hierarchy.vue";
|
|
|
|
|
import Inspector from "./inspector.vue";
|
|
|
|
|
import { appStore } from "./store";
|
2024-12-09 21:37:07 +08:00
|
|
|
|
import Test from "./test/test.vue";
|
2024-12-28 14:25:23 +08:00
|
|
|
|
import { Timer } from "./timer";
|
2024-12-10 10:34:27 +08:00
|
|
|
|
import Properties from "./ui/propertys.vue";
|
2024-12-09 16:23:58 +08:00
|
|
|
|
import SettingsVue from "./ui/settings.vue";
|
2024-12-28 14:25:23 +08:00
|
|
|
|
import { checkSupport } from "./util";
|
2024-12-09 19:25:06 +08:00
|
|
|
|
const { CCTree, CCFootBar, CCDialog, CCInput, CCButton, CCInputNumber, CCSelect, CCButtonGroup, CCCheckBox, CCColor, CCDivider } = ccui.components;
|
2024-01-09 15:33:34 +08:00
|
|
|
|
interface FrameInfo {
|
|
|
|
|
label: string;
|
|
|
|
|
value: number;
|
|
|
|
|
}
|
|
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
|
export default defineComponent({
|
2024-12-27 21:08:26 +08:00
|
|
|
|
components: { Find, Inspector, Hierarchy, Test, CCFootBar, CCDialog, CCTree, CCDivider, CCButtonGroup, Properties, SettingsVue, CCInput, CCButton, CCInputNumber, CCSelect, CCCheckBox, CCColor },
|
2024-01-09 15:33:34 +08:00
|
|
|
|
name: "devtools",
|
|
|
|
|
props: {},
|
2024-01-09 12:02:47 +08:00
|
|
|
|
setup(props, ctx) {
|
2024-12-09 19:25:06 +08:00
|
|
|
|
appStore().init();
|
2024-12-15 19:59:51 +08:00
|
|
|
|
const isShowDebug = ref<boolean>(false);
|
2024-01-09 15:33:34 +08:00
|
|
|
|
const iframes = ref<Array<FrameInfo>>([]);
|
2024-12-27 21:08:26 +08:00
|
|
|
|
const { config, frameID } = storeToRefs(appStore());
|
2024-12-28 14:25:23 +08:00
|
|
|
|
const timer = new Timer(() => {
|
|
|
|
|
checkSupport();
|
|
|
|
|
});
|
|
|
|
|
onMounted(() => {
|
|
|
|
|
timer.create();
|
|
|
|
|
});
|
|
|
|
|
onUnmounted(() => {
|
|
|
|
|
timer.clean();
|
|
|
|
|
});
|
2024-01-09 12:02:47 +08:00
|
|
|
|
// 问题:没有上下文的权限,只能操作DOM
|
|
|
|
|
function _executeScript(para: Object) {
|
2024-02-26 09:07:01 +08:00
|
|
|
|
// chrome.tabs.executeScript()//v2版本使用的函数
|
|
|
|
|
const tabID = chrome.devtools.inspectedWindow.tabId;
|
|
|
|
|
chrome.scripting.executeScript({ files: ["js/execute.js"], target: { tabId: tabID } }, (results: chrome.scripting.InjectionResult[]) => {});
|
2024-01-09 12:02:47 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function _inspectedCode() {
|
|
|
|
|
let injectCode = "";
|
2024-01-23 22:25:32 +08:00
|
|
|
|
chrome.devtools.inspectedWindow.eval(injectCode, (result, isException) => {
|
|
|
|
|
if (isException) {
|
|
|
|
|
console.error(isException);
|
|
|
|
|
} else {
|
|
|
|
|
console.log(`执行结果:${result}`);
|
2024-01-09 12:02:47 +08:00
|
|
|
|
}
|
2024-01-23 22:25:32 +08:00
|
|
|
|
});
|
2024-01-09 12:02:47 +08:00
|
|
|
|
}
|
2024-12-28 14:25:23 +08:00
|
|
|
|
Bus.on(BusMsg.EnableSchedule, (b: boolean) => {
|
|
|
|
|
if (b) {
|
|
|
|
|
timer.create();
|
|
|
|
|
} else {
|
|
|
|
|
timer.clean();
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => {
|
|
|
|
|
let data: Array<TreeData> = event.data;
|
2024-12-27 21:08:26 +08:00
|
|
|
|
isShowDebug.value = true;
|
2024-01-09 12:02:47 +08:00
|
|
|
|
});
|
2024-12-28 14:25:23 +08:00
|
|
|
|
bridge.on(Msg.ResponseSupport, (event: PluginEvent) => {
|
|
|
|
|
let data: ResponseSupportData = event.data;
|
2024-12-27 21:08:26 +08:00
|
|
|
|
const isCocosGame: boolean = data.support;
|
|
|
|
|
isShowDebug.value = isCocosGame;
|
2024-01-09 12:02:47 +08:00
|
|
|
|
});
|
2024-12-28 14:25:23 +08:00
|
|
|
|
bridge.on(Msg.ResponseNodeInfo, (event: PluginEvent) => {
|
|
|
|
|
let eventData: NodeInfoData = event.data;
|
2024-12-27 21:08:26 +08:00
|
|
|
|
isShowDebug.value = true;
|
2024-12-10 10:34:27 +08:00
|
|
|
|
});
|
2024-12-27 21:08:26 +08:00
|
|
|
|
bridge.on(Msg.MemoryInfo, (eventData: any) => {
|
|
|
|
|
memory.value = eventData;
|
2024-01-09 12:02:47 +08:00
|
|
|
|
});
|
2024-12-28 14:25:23 +08:00
|
|
|
|
bridge.on(Msg.ResponseUpdateFrames, (event: PluginEvent) => {
|
|
|
|
|
let resFrames: FrameDetails[] = event.data;
|
2024-12-27 21:08:26 +08:00
|
|
|
|
iframes.value = resFrames.map((item) => {
|
|
|
|
|
return {
|
|
|
|
|
label: item.url,
|
|
|
|
|
value: item.frameID,
|
|
|
|
|
};
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
// 第一次获取到frame配置后,自动获取frame数据
|
|
|
|
|
if (frameID === null && iframes.value.length > 0 && !iframes.value.find((el) => el.value === frameID.value)) {
|
|
|
|
|
frameID.value = iframes[0].value;
|
|
|
|
|
onChangeFrame();
|
|
|
|
|
}
|
2024-01-09 12:02:47 +08:00
|
|
|
|
});
|
2024-12-27 21:08:26 +08:00
|
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
|
const memory = ref<{
|
|
|
|
|
performance: {
|
|
|
|
|
jsHeapSizeLimit?: number;
|
|
|
|
|
totalJSHeapSize?: number;
|
|
|
|
|
usedJSHeapSize?: number;
|
|
|
|
|
};
|
|
|
|
|
console: Object;
|
|
|
|
|
}>({
|
|
|
|
|
performance: {},
|
|
|
|
|
console: {},
|
|
|
|
|
});
|
|
|
|
|
// el-tree的渲染key
|
|
|
|
|
const defaultProps = ref<{ children: string; label: string }>({
|
|
|
|
|
children: "children",
|
|
|
|
|
label: "name",
|
|
|
|
|
});
|
|
|
|
|
|
2024-01-09 15:33:34 +08:00
|
|
|
|
function onChangeFrame() {
|
2024-12-27 14:14:38 +08:00
|
|
|
|
const id = Number(toRaw(frameID.value));
|
2024-12-27 19:20:22 +08:00
|
|
|
|
bridge.send(Msg.RequestUseFrame, { id } as RequestUseFrameData);
|
2024-01-09 15:33:34 +08:00
|
|
|
|
}
|
|
|
|
|
const elLeft = ref<HTMLDivElement>();
|
2024-12-09 19:25:06 +08:00
|
|
|
|
const version = ref(PluginConfig.manifest.version);
|
2024-01-09 12:02:47 +08:00
|
|
|
|
return {
|
2024-12-09 19:25:06 +08:00
|
|
|
|
version,
|
2024-01-09 12:02:47 +08:00
|
|
|
|
memory,
|
|
|
|
|
defaultProps,
|
2024-12-27 21:08:26 +08:00
|
|
|
|
frameID,
|
2024-01-09 15:33:34 +08:00
|
|
|
|
iframes,
|
|
|
|
|
isShowDebug,
|
2024-12-28 14:25:23 +08:00
|
|
|
|
|
2024-01-09 15:33:34 +08:00
|
|
|
|
getFramesData(): Option[] {
|
|
|
|
|
const frames: FrameInfo[] = toRaw(iframes.value);
|
|
|
|
|
const options: Option[] = [];
|
|
|
|
|
frames.forEach((frame) => {
|
|
|
|
|
options.push({
|
|
|
|
|
label: frame.label,
|
|
|
|
|
value: frame.value,
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
return options;
|
|
|
|
|
},
|
2024-01-23 22:25:32 +08:00
|
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
|
onMemoryTest() {
|
2024-12-24 21:09:13 +08:00
|
|
|
|
bridge.send(Msg.MemoryInfo);
|
2024-01-09 12:02:47 +08:00
|
|
|
|
},
|
2024-01-23 22:25:32 +08:00
|
|
|
|
|
2024-01-09 15:33:34 +08:00
|
|
|
|
onChangeFrame,
|
2024-01-09 12:02:47 +08:00
|
|
|
|
};
|
|
|
|
|
},
|
|
|
|
|
});
|
|
|
|
|
</script>
|
|
|
|
|
|
|
|
|
|
<style scoped lang="less">
|
|
|
|
|
#devtools {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: column;
|
|
|
|
|
width: 100%;
|
|
|
|
|
height: 100%;
|
|
|
|
|
overflow: hidden;
|
2024-12-10 10:34:27 +08:00
|
|
|
|
background-color: #5c5c5c;
|
|
|
|
|
color: white;
|
2024-12-12 20:13:50 +08:00
|
|
|
|
|
2024-01-09 12:02:47 +08:00
|
|
|
|
.head {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
align-items: center;
|
2024-12-12 20:13:50 +08:00
|
|
|
|
padding: 2px 0;
|
2024-01-09 12:02:47 +08:00
|
|
|
|
border-bottom: solid 1px grey;
|
|
|
|
|
|
|
|
|
|
.label {
|
2024-12-12 20:13:50 +08:00
|
|
|
|
color: white;
|
|
|
|
|
font-size: 12px;
|
2024-01-09 12:02:47 +08:00
|
|
|
|
margin: 0 3px;
|
2024-12-12 20:13:50 +08:00
|
|
|
|
margin-right: 5px;
|
|
|
|
|
user-select: none;
|
2024-01-09 12:02:47 +08:00
|
|
|
|
}
|
2024-01-05 16:45:23 +08:00
|
|
|
|
}
|
2024-01-09 12:02:47 +08:00
|
|
|
|
|
|
|
|
|
.find {
|
|
|
|
|
display: flex;
|
|
|
|
|
flex: 1;
|
|
|
|
|
flex-direction: row;
|
|
|
|
|
overflow: auto;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
</style>
|