39 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Msg, Page, PluginEvent, RequestTreeInfoData, RequestUseFrameData } from "../../core/types";
2024-12-24 17:31:26 +08:00
import { PortMan } from "./portMan";
import { portMgr } from "./portMgr";
export class PortDevtools extends PortMan {
init(): void {
// 当devtools链接后主动同步frames数据
portMgr.updateFrames();
2024-12-24 17:31:26 +08:00
this.onDisconnect = () => {
portMgr.removePort(this);
2024-12-27 14:23:27 +08:00
};
2024-12-24 17:31:26 +08:00
this.onMessage = (data: PluginEvent) => {
if (data.msg === Msg.RequestUseFrame) {
portMgr.useFrame((data.data as RequestUseFrameData).id);
2024-12-24 17:31:26 +08:00
} else {
// 从devtools过来的消息统一派发到Content中
2024-12-27 14:14:38 +08:00
if (data.check(Page.Devtools, Page.Background)) {
if (data.msg === Msg.RequstTreeInfo) {
const d = data.data as RequestTreeInfoData;
if (!portMgr.isCurrentFrme(d.frameID)) {
2024-12-24 17:31:26 +08:00
console.log(`frameID[${data.data}]不一致`);
debugger;
2024-12-24 17:31:26 +08:00
}
}
2024-12-27 14:14:38 +08:00
data.reset(Page.Background, Page.Content);
const port = portMgr.getCurrentUsePort();
2024-12-24 17:31:26 +08:00
if (!port) {
console.warn(`not find andy port`);
return;
}
port.send(data);
} else {
debugger;
2024-12-24 17:31:26 +08:00
}
}
2024-12-27 14:23:27 +08:00
};
2024-12-24 17:31:26 +08:00
}
2024-12-27 14:23:27 +08:00
}