2024-12-27 19:20:22 +08:00
|
|
|
|
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数据
|
2024-12-27 19:20:22 +08:00
|
|
|
|
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) => {
|
2024-12-27 19:20:22 +08:00
|
|
|
|
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)) {
|
2024-12-27 19:20:22 +08:00
|
|
|
|
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}]不一致`);
|
2024-12-27 19:20:22 +08:00
|
|
|
|
debugger;
|
2024-12-24 17:31:26 +08:00
|
|
|
|
}
|
|
|
|
|
}
|
2024-12-27 14:14:38 +08:00
|
|
|
|
data.reset(Page.Background, Page.Content);
|
2024-12-27 19:20:22 +08:00
|
|
|
|
const port = portMgr.getCurrentUsePort();
|
2024-12-24 17:31:26 +08:00
|
|
|
|
if (!port) {
|
|
|
|
|
console.warn(`not find andy port`);
|
|
|
|
|
return;
|
|
|
|
|
}
|
2024-12-27 19:20:22 +08:00
|
|
|
|
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
|
|
|
|
}
|