mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-10-22 20:35:24 +00:00
优化多个frame的inspect target的逻辑
This commit is contained in:
@@ -16,24 +16,10 @@ export class PortContent extends PortMan {
|
||||
};
|
||||
}
|
||||
init(): void {
|
||||
// 使用新连上来的content
|
||||
const { frameId } = this.port.sender;
|
||||
if (frameId !== undefined) {
|
||||
portMgr.useFrame(frameId);
|
||||
}
|
||||
// 新的content连上来,需要更新devtools
|
||||
portMgr.updateFrames();
|
||||
this.onDisconnect = (disPort: chrome.runtime.Port) => {
|
||||
/**
|
||||
* const index = this.content.findIndex((el) =>
|
||||
disPort.sender?.frameId !== undefined &&
|
||||
el.sender?.frameId !== undefined &&
|
||||
el.sender?.frameId === disPort.sender?.frameId
|
||||
);
|
||||
*/
|
||||
// content失去链接需要更新Devtools
|
||||
portMgr.removePort(this);
|
||||
portMgr.updateFrames();
|
||||
};
|
||||
this.onMessage = (data: PluginEvent) => {
|
||||
// content的数据一般都是要同步到devtools
|
||||
|
@@ -1,38 +1,27 @@
|
||||
import { Msg, Page, PluginEvent, RequestTreeInfoData, RequestUseFrameData, ResponseSupportData } from "../../core/types";
|
||||
import { Msg, Page, PluginEvent, RequestUseFrameData, ResponseSupportData } from "../../core/types";
|
||||
import { PortMan } from "./portMan";
|
||||
import { portMgr } from "./portMgr";
|
||||
|
||||
export class PortDevtools extends PortMan {
|
||||
init(): void {
|
||||
// 当devtools链接后,主动同步frames数据
|
||||
portMgr.updateFrames();
|
||||
this.onDisconnect = () => {
|
||||
portMgr.removePort(this);
|
||||
};
|
||||
this.onMessage = (data: PluginEvent) => {
|
||||
if (data.msg === Msg.RequestUseFrame) {
|
||||
// 因为devtool是定时器驱动,这里改变了content,后续就会将数据派发到对应的content中去
|
||||
portMgr.useFrame((data.data as RequestUseFrameData).id);
|
||||
} else {
|
||||
// 从devtools过来的消息统一派发到Content中
|
||||
// 从devtools过来的消息统一派发到目标content中
|
||||
if (data.check(Page.Devtools, Page.Background)) {
|
||||
if (data.msg === Msg.RequstTreeInfo) {
|
||||
const d = data.data as RequestTreeInfoData;
|
||||
if (!portMgr.isCurrentFrme(d.frameID)) {
|
||||
console.log(`frameID[${data.data}]不一致`);
|
||||
debugger;
|
||||
}
|
||||
}
|
||||
data.reset(Page.Background, Page.Content);
|
||||
const port = portMgr.getCurrentUsePort();
|
||||
if (!port) {
|
||||
console.warn(`not find any port`);
|
||||
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);
|
||||
this.send(e);
|
||||
return;
|
||||
}
|
||||
port.send(data);
|
||||
} else {
|
||||
debugger;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
@@ -56,6 +56,7 @@ export class PortMgr {
|
||||
}
|
||||
if (portMan) {
|
||||
this.portArray.push(portMan);
|
||||
this.updateFrames();
|
||||
this.logState();
|
||||
return portMan;
|
||||
}
|
||||
@@ -85,6 +86,7 @@ export class PortMgr {
|
||||
let index = this.portArray.findIndex((el) => el === item);
|
||||
if (index > -1) {
|
||||
this.portArray.splice(index, 1);
|
||||
this.updateFrames();
|
||||
this.logState();
|
||||
}
|
||||
}
|
||||
@@ -110,15 +112,6 @@ export class PortMgr {
|
||||
}
|
||||
useFrame(id: number) {
|
||||
this.currentUseContentFrameID = id;
|
||||
// 更新这个frame的tree
|
||||
const sendData = new PluginEvent(Page.Background, Page.Content, Msg.RequestSupport, {} as RequestSupportData);
|
||||
this.getCurrentUsePort()?.send(sendData);
|
||||
}
|
||||
isCurrentFrme(id: number) {
|
||||
if (typeof id !== "number") {
|
||||
throw new Error("id must be number");
|
||||
}
|
||||
return this.currentUseContentFrameID === id;
|
||||
}
|
||||
}
|
||||
export const portMgr = new PortMgr();
|
||||
|
@@ -201,6 +201,9 @@ export class Inspector extends InjectEvent {
|
||||
"quat",
|
||||
"node",
|
||||
"components",
|
||||
"enabledInHierarchy",
|
||||
"hideFlags",
|
||||
"isValid",
|
||||
"parent",
|
||||
// 生命周期函数
|
||||
"onFocusInEditor",
|
||||
@@ -214,6 +217,14 @@ export class Inspector extends InjectEvent {
|
||||
"onDisable",
|
||||
"onDestroy",
|
||||
"onLoad",
|
||||
"internalLateUpdate",
|
||||
"internalOnDestroy",
|
||||
"internalOnEnable",
|
||||
"internalOnDisable",
|
||||
"internalUpdate",
|
||||
"internalPreload",
|
||||
"internalOnLoad",
|
||||
"internalStart",
|
||||
];
|
||||
const keyHidden = this.getAllPropertyDescriptors(node);
|
||||
const keyVisible1 = Object.keys(node); // Object不走原型链
|
||||
|
Reference in New Issue
Block a user