mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-16 07:01:03 +00:00
显示Engine版本号
This commit is contained in:
parent
aba21c6f89
commit
8bff11cc10
@ -1,5 +1,5 @@
|
|||||||
import { Chunk } from "../scripts/terminal";
|
import { Chunk } from "../scripts/terminal";
|
||||||
import { FrameDetails, Info, NodeInfoData, ObjectData, ObjectItemRequestData, TreeData } from "../views/devtools/data";
|
import { FrameDetails, Info, NodeInfoData, TreeData } from "../views/devtools/data";
|
||||||
|
|
||||||
export enum Page {
|
export enum Page {
|
||||||
None = "None",
|
None = "None",
|
||||||
@ -38,6 +38,10 @@ export interface ResponseSupportData {
|
|||||||
* 消息
|
* 消息
|
||||||
*/
|
*/
|
||||||
msg: string;
|
msg: string;
|
||||||
|
/**
|
||||||
|
* engine版本
|
||||||
|
*/
|
||||||
|
version: string;
|
||||||
}
|
}
|
||||||
|
|
||||||
export type ResponseUpdateFramesData = FrameDetails[];
|
export type ResponseUpdateFramesData = FrameDetails[];
|
||||||
|
@ -14,7 +14,13 @@ export class GoogleAnalytics {
|
|||||||
}
|
}
|
||||||
return clientId;
|
return clientId;
|
||||||
}
|
}
|
||||||
|
private isChromeEnv() {
|
||||||
|
return !!chrome?.storage?.local?.get;
|
||||||
|
}
|
||||||
public async fireEventWithParam(name: GA_EventName, param: string) {
|
public async fireEventWithParam(name: GA_EventName, param: string) {
|
||||||
|
if (!this.isChromeEnv()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const time = Date.now();
|
const time = Date.now();
|
||||||
const id = await this.getOrCreateSessionId();
|
const id = await this.getOrCreateSessionId();
|
||||||
fetch(`${GA_ENDPOINT}?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`, {
|
fetch(`${GA_ENDPOINT}?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`, {
|
||||||
@ -35,6 +41,9 @@ export class GoogleAnalytics {
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
public async fireEvent(name: string) {
|
public async fireEvent(name: string) {
|
||||||
|
if (!this.isChromeEnv()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
const time = Date.now();
|
const time = Date.now();
|
||||||
const id = await this.getOrCreateSessionId();
|
const id = await this.getOrCreateSessionId();
|
||||||
fetch(`${GA_ENDPOINT}?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`, {
|
fetch(`${GA_ENDPOINT}?measurement_id=${MEASUREMENT_ID}&api_secret=${API_SECRET}`, {
|
||||||
|
@ -77,6 +77,7 @@ export enum GA_EventName {
|
|||||||
MouseMenu = "mouse_menu",
|
MouseMenu = "mouse_menu",
|
||||||
Hierarchy = "hierarchy",
|
Hierarchy = "hierarchy",
|
||||||
Inspector = "Inspector",
|
Inspector = "Inspector",
|
||||||
|
EngineVersion = "engine_version",
|
||||||
}
|
}
|
||||||
export enum GA_Button {
|
export enum GA_Button {
|
||||||
Github = "github",
|
Github = "github",
|
||||||
|
@ -19,7 +19,7 @@ export class PortDevtools extends PortMan {
|
|||||||
if (port) {
|
if (port) {
|
||||||
port.send(data);
|
port.send(data);
|
||||||
} else {
|
} else {
|
||||||
const e = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseSupport, { support: false, msg: "disconnect with game, please refresh page" } as ResponseSupportData);
|
const e = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseSupport, { support: false, msg: "disconnect with game, please refresh page", version: "" } as ResponseSupportData);
|
||||||
this.send(e);
|
this.send(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,4 +7,5 @@ export enum DocumentEvent {
|
|||||||
* 从content到inject的事件
|
* 从content到inject的事件
|
||||||
*/
|
*/
|
||||||
Content2Inject = "content2inject",
|
Content2Inject = "content2inject",
|
||||||
|
EngineVersion = "engineVersion",
|
||||||
}
|
}
|
||||||
|
@ -1,7 +1,9 @@
|
|||||||
// content.js 和原始界面共享DOM,具有操作dom的能力
|
// content.js 和原始界面共享DOM,具有操作dom的能力
|
||||||
// 但是不共享js,要想访问页面js,只能通过注入的方式
|
// 但是不共享js,要想访问页面js,只能通过注入的方式
|
||||||
import { ChromeConst } from "cc-plugin/src/chrome/const";
|
import { ChromeConst } from "cc-plugin/src/chrome/const";
|
||||||
import { debugLog, Msg, Page, PluginEvent, ResponseSupportData } from "../../core/types";
|
import { debugLog, Page, PluginEvent } from "../../core/types";
|
||||||
|
import { ga } from "../../ga";
|
||||||
|
import { GA_EventName } from "../../ga/type";
|
||||||
import { DocumentEvent } from "../const";
|
import { DocumentEvent } from "../const";
|
||||||
import { Terminal } from "../terminal";
|
import { Terminal } from "../terminal";
|
||||||
|
|
||||||
@ -25,6 +27,12 @@ export function injectScript(url: string) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
document.addEventListener(DocumentEvent.EngineVersion, async (event: CustomEvent) => {
|
||||||
|
const version: string = event.detail;
|
||||||
|
if (version) {
|
||||||
|
ga.fireEventWithParam(GA_EventName.EngineVersion, version);
|
||||||
|
}
|
||||||
|
});
|
||||||
// #region 和Inject通讯
|
// #region 和Inject通讯
|
||||||
document.addEventListener(DocumentEvent.Inject2Content, (event: CustomEvent) => {
|
document.addEventListener(DocumentEvent.Inject2Content, (event: CustomEvent) => {
|
||||||
let data: PluginEvent = PluginEvent.create(event.detail);
|
let data: PluginEvent = PluginEvent.create(event.detail);
|
||||||
@ -60,20 +68,4 @@ connect.onMessage.addListener((data: PluginEvent, sender: chrome.runtime.Port) =
|
|||||||
throw new Error(`invalid data: ${data}`);
|
throw new Error(`invalid data: ${data}`);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
function checkGame() {
|
|
||||||
let gameCanvas = document.querySelector("#GameCanvas");
|
|
||||||
const sendData = new PluginEvent(Page.Content, Page.Devtools, Msg.ResponseSupport, {
|
|
||||||
support: !!gameCanvas,
|
|
||||||
msg: "",
|
|
||||||
} as ResponseSupportData);
|
|
||||||
if (connect) {
|
|
||||||
connect.postMessage(sendData);
|
|
||||||
} else {
|
|
||||||
debugLog && console.log(...terminal.log(`connect is null`));
|
|
||||||
throw new Error("connect is null");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
injectScript(ChromeConst.script.inject);
|
injectScript(ChromeConst.script.inject);
|
||||||
// checkGame();
|
|
||||||
|
@ -18,4 +18,9 @@ export class InjectEvent {
|
|||||||
const event = new CustomEvent(DocumentEvent.Inject2Content, { detail });
|
const event = new CustomEvent(DocumentEvent.Inject2Content, { detail });
|
||||||
document.dispatchEvent(event);
|
document.dispatchEvent(event);
|
||||||
}
|
}
|
||||||
|
sendEngineVersion(version: string) {
|
||||||
|
const detail = version;
|
||||||
|
const event = new CustomEvent(DocumentEvent.EngineVersion, { detail });
|
||||||
|
document.dispatchEvent(event);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -70,16 +70,47 @@ export class Inspector extends InjectEvent {
|
|||||||
}
|
}
|
||||||
init() {
|
init() {
|
||||||
console.log(...this.terminal.init());
|
console.log(...this.terminal.init());
|
||||||
|
this.watchIsCocosGame();
|
||||||
|
}
|
||||||
|
private watchIsCocosGame() {
|
||||||
|
const timer = setInterval(() => {
|
||||||
|
const b = this._isCocosGame();
|
||||||
|
if (b) {
|
||||||
|
clearInterval(timer);
|
||||||
|
const version = this.getEngineVersion();
|
||||||
|
if (b && version) {
|
||||||
|
this.uploadEngineVersion(version);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}, 300);
|
||||||
|
}
|
||||||
|
private getEngineVersion() {
|
||||||
|
if (this._isCocosGame()) {
|
||||||
|
return cc.ENGINE_VERSION || "";
|
||||||
|
} else {
|
||||||
|
return "";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
notifySupportGame(b: boolean) {
|
notifySupportGame(b: boolean) {
|
||||||
this.sendMsgToContent(Msg.ResponseSupport, { support: b, msg: "" } as ResponseSupportData);
|
const version = this.getEngineVersion();
|
||||||
|
this.sendMsgToContent(Msg.ResponseSupport, { support: b, msg: "", version } as ResponseSupportData);
|
||||||
|
}
|
||||||
|
/**
|
||||||
|
* 防止后台收到大量的Engine版本数据,每次调试只上传一次
|
||||||
|
*/
|
||||||
|
private hasUploadEngineVersion = false;
|
||||||
|
private uploadEngineVersion(version: string) {
|
||||||
|
if (this.hasUploadEngineVersion) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if (version) {
|
||||||
|
this.hasUploadEngineVersion = true;
|
||||||
|
this.sendEngineVersion(version);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
updateTreeInfo() {
|
updateTreeInfo() {
|
||||||
let isCocosCreatorGame = this._isCocosGame();
|
let isCocosCreatorGame = this._isCocosGame();
|
||||||
if (isCocosCreatorGame) {
|
if (isCocosCreatorGame) {
|
||||||
//@ts-ignore
|
|
||||||
let scene = cc.director.getScene();
|
let scene = cc.director.getScene();
|
||||||
if (scene) {
|
if (scene) {
|
||||||
let treeData = new TreeData();
|
let treeData = new TreeData();
|
||||||
@ -617,8 +648,8 @@ export class Inspector extends InjectEvent {
|
|||||||
const data: NodeInfoData = new NodeInfoData(uuid, groupData);
|
const data: NodeInfoData = new NodeInfoData(uuid, groupData);
|
||||||
this.sendMsgToContent(Msg.ResponseNodeInfo, data as ResponseNodeInfoData);
|
this.sendMsgToContent(Msg.ResponseNodeInfo, data as ResponseNodeInfoData);
|
||||||
} else {
|
} else {
|
||||||
// 未获取到节点数据
|
const data: NodeInfoData = new NodeInfoData(uuid, []);
|
||||||
console.log("未获取到节点数据");
|
this.sendMsgToContent(Msg.ResponseNodeInfo, data as ResponseNodeInfoData);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -1,6 +1,9 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="left">
|
<div class="left">
|
||||||
<CCDock name="Hierarchy">
|
<CCDock name="Hierarchy">
|
||||||
|
<template v-slot:title>
|
||||||
|
<div class="engine-version" v-if="engineVersion">Cocos Creator V{{ engineVersion }}</div>
|
||||||
|
</template>
|
||||||
<CCInput style="flex: none" placeholder="enter keywords to filter" :data="filterText" v-if="false">
|
<CCInput style="flex: none" placeholder="enter keywords to filter" :data="filterText" v-if="false">
|
||||||
<slot>
|
<slot>
|
||||||
<i class="matchCase iconfont icon_font_size" @click.stop="onChangeCase" title="match case" :style="{ color: matchCase ? 'red' : '' }"></i>
|
<i class="matchCase iconfont icon_font_size" @click.stop="onChangeCase" title="match case" :style="{ color: matchCase ? 'red' : '' }"></i>
|
||||||
@ -16,7 +19,7 @@ import { IUiMenuItem } from "@xuyanfeng/cc-ui/types/cc-menu/const";
|
|||||||
import Mousetrap, { MousetrapInstance } from "mousetrap";
|
import Mousetrap, { MousetrapInstance } from "mousetrap";
|
||||||
import { storeToRefs } from "pinia";
|
import { storeToRefs } from "pinia";
|
||||||
import { defineComponent, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from "vue";
|
import { defineComponent, nextTick, onMounted, onUnmounted, ref, toRaw, watch } from "vue";
|
||||||
import { Msg, PluginEvent, RequestTreeInfoData, RequestUseFrameData, ResponseSetPropertyData } from "../../core/types";
|
import { Msg, PluginEvent, RequestTreeInfoData, RequestUseFrameData, ResponseSetPropertyData, ResponseSupportData } from "../../core/types";
|
||||||
import { ga } from "../../ga";
|
import { ga } from "../../ga";
|
||||||
import { GA_EventName } from "../../ga/type";
|
import { GA_EventName } from "../../ga/type";
|
||||||
import { bridge } from "./bridge";
|
import { bridge } from "./bridge";
|
||||||
@ -99,6 +102,16 @@ export default defineComponent({
|
|||||||
const elTree = ref<typeof CCTree>(null);
|
const elTree = ref<typeof CCTree>(null);
|
||||||
const treeData = ref<TreeData[]>([]);
|
const treeData = ref<TreeData[]>([]);
|
||||||
let selectedUUID: string | null = null;
|
let selectedUUID: string | null = null;
|
||||||
|
const engineVersion = ref("");
|
||||||
|
bridge.on(Msg.ResponseSupport, (event: PluginEvent) => {
|
||||||
|
let data: ResponseSupportData = event.data;
|
||||||
|
const isCocosGame: boolean = data.support;
|
||||||
|
if (isCocosGame) {
|
||||||
|
engineVersion.value = data.version;
|
||||||
|
} else {
|
||||||
|
engineVersion.value = "";
|
||||||
|
}
|
||||||
|
});
|
||||||
bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => {
|
bridge.on(Msg.ResponseTreeInfo, (event: PluginEvent) => {
|
||||||
let data: Array<TreeData> = event.data;
|
let data: Array<TreeData> = event.data;
|
||||||
if (!Array.isArray(data)) {
|
if (!Array.isArray(data)) {
|
||||||
@ -144,6 +157,7 @@ export default defineComponent({
|
|||||||
Bus.emit(BusMsg.SelectNode, uuid);
|
Bus.emit(BusMsg.SelectNode, uuid);
|
||||||
}
|
}
|
||||||
return {
|
return {
|
||||||
|
engineVersion,
|
||||||
expandedKeys,
|
expandedKeys,
|
||||||
elTree,
|
elTree,
|
||||||
filterText,
|
filterText,
|
||||||
@ -234,7 +248,13 @@ export default defineComponent({
|
|||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
min-width: 200px;
|
min-width: 200px;
|
||||||
width: 300px;
|
width: 300px;
|
||||||
|
.engine-version {
|
||||||
|
flex: 1;
|
||||||
|
text-align: right;
|
||||||
|
padding-right: 5px;
|
||||||
|
font-size: 10px;
|
||||||
|
user-select: none;
|
||||||
|
}
|
||||||
.matchCase {
|
.matchCase {
|
||||||
width: 30px;
|
width: 30px;
|
||||||
height: 26px;
|
height: 26px;
|
||||||
|
@ -163,6 +163,7 @@ export class TestServer {
|
|||||||
const e = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseSupport, {
|
const e = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseSupport, {
|
||||||
support: this.support,
|
support: this.support,
|
||||||
msg: "",
|
msg: "",
|
||||||
|
version: "0.0.0",
|
||||||
} as ResponseSupportData);
|
} as ResponseSupportData);
|
||||||
this.send(e);
|
this.send(e);
|
||||||
break;
|
break;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user