214 lines
6.3 KiB
Vue
Raw Normal View History

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>
<Hierarchy></Hierarchy>
2024-01-23 22:25:32 +08:00
<CCDivider></CCDivider>
<Inspector></Inspector>
2024-01-09 12:02:47 +08:00
</div>
<Find v-if="!isShowDebug"></Find>
2024-12-09 19:25:06 +08:00
<CCDialog></CCDialog>
2024-12-28 16:24:16 +08:00
<CCMenu></CCMenu>
2024-12-09 19:25:06 +08:00
<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";
import { Bus, BusMsg } from "./bus";
import { FrameDetails, NodeInfoData, TreeData } from "./data";
import Find from "./find.vue";
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-28 16:24:16 +08:00
const { CCTree, CCFootBar, CCMenu, 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-28 16:24:16 +08:00
components: { Find, Inspector, CCMenu, 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>>([]);
const { config, frameID } = storeToRefs(appStore());
2024-12-28 14:25:23 +08:00
const timer = new Timer(() => {
checkSupport();
});
onMounted(() => {
2024-12-28 15:05:05 +08:00
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
2024-12-28 14:25:23 +08:00
timer.create();
});
onUnmounted(() => {
2024-12-28 15:05:05 +08:00
Bus.off(BusMsg.EnableSchedule, funcEnableSchedule);
2024-12-28 14:25:23 +08:00
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 15:05:05 +08:00
const funcEnableSchedule = (b: boolean) => {
2024-12-28 14:25:23 +08:00
if (b) {
timer.create();
} else {
timer.clean();
}
2024-12-28 15:05:05 +08:00
};
2024-12-28 14:25:23 +08:00
bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => {
let data: Array<TreeData> = event.data;
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;
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;
isShowDebug.value = true;
2024-12-10 10:34:27 +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;
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-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));
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,
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;
2024-12-28 16:24:16 +08:00
overflow: hidden;
2024-01-09 12:02:47 +08:00
}
}
</style>