mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-10-22 20:35:24 +00:00
显示Engine版本号
This commit is contained in:
@@ -19,7 +19,7 @@ export class PortDevtools extends PortMan {
|
||||
if (port) {
|
||||
port.send(data);
|
||||
} 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);
|
||||
}
|
||||
}
|
||||
|
@@ -7,4 +7,5 @@ export enum DocumentEvent {
|
||||
* 从content到inject的事件
|
||||
*/
|
||||
Content2Inject = "content2inject",
|
||||
EngineVersion = "engineVersion",
|
||||
}
|
||||
|
@@ -1,7 +1,9 @@
|
||||
// content.js 和原始界面共享DOM,具有操作dom的能力
|
||||
// 但是不共享js,要想访问页面js,只能通过注入的方式
|
||||
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 { 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通讯
|
||||
document.addEventListener(DocumentEvent.Inject2Content, (event: CustomEvent) => {
|
||||
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}`);
|
||||
}
|
||||
});
|
||||
|
||||
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);
|
||||
// checkGame();
|
||||
|
@@ -18,4 +18,9 @@ export class InjectEvent {
|
||||
const event = new CustomEvent(DocumentEvent.Inject2Content, { detail });
|
||||
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() {
|
||||
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) {
|
||||
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() {
|
||||
let isCocosCreatorGame = this._isCocosGame();
|
||||
if (isCocosCreatorGame) {
|
||||
//@ts-ignore
|
||||
let scene = cc.director.getScene();
|
||||
if (scene) {
|
||||
let treeData = new TreeData();
|
||||
@@ -617,8 +648,8 @@ export class Inspector extends InjectEvent {
|
||||
const data: NodeInfoData = new NodeInfoData(uuid, groupData);
|
||||
this.sendMsgToContent(Msg.ResponseNodeInfo, data as ResponseNodeInfoData);
|
||||
} else {
|
||||
// 未获取到节点数据
|
||||
console.log("未获取到节点数据");
|
||||
const data: NodeInfoData = new NodeInfoData(uuid, []);
|
||||
this.sendMsgToContent(Msg.ResponseNodeInfo, data as ResponseNodeInfoData);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user