30 lines
1.2 KiB
TypeScript
Raw Normal View History

import { Msg, Page, PluginEvent, RequestUseFrameData, ResponseSupportData } 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 {
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) {
// 因为devtool是定时器驱动这里改变了content后续就会将数据派发到对应的content中去
portMgr.useFrame((data.data as RequestUseFrameData).id, this.tabID);
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)) {
data.reset(Page.Background, Page.Content);
const port = portMgr.getCurrentUsePort(this.tabID);
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);
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
}