36 lines
1.0 KiB
TypeScript
Raw Normal View History

2024-12-24 17:31:26 +08:00
import { Msg, Page, PluginEvent } 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.UseFrame) {
portMgr.useFrame(data.data);
} else {
// 从devtools过来的消息统一派发到Content中
2024-12-27 14:14:38 +08:00
if (data.check(Page.Devtools, Page.Background)) {
2024-12-24 17:31:26 +08:00
if (data.msg === Msg.TreeInfo) {
if (portMgr.isCurrentFrme(data.data)) {
console.log(`frameID[${data.data}]不一致`);
}
}
2024-12-27 14:14:38 +08:00
data.reset(Page.Background, Page.Content);
2024-12-24 17:31:26 +08:00
const port = portMgr.getCurrentUseContent();
if (!port) {
console.warn(`not find andy port`);
return;
}
port.postMessage(data);
}
}
}
}
}