2025-01-12 17:57:02 +08:00

30 lines
1.2 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import { Msg, Page, PluginEvent, RequestUseFrameData, ResponseSupportData } from "../../core/types";
import { PortMan } from "./portMan";
import { portMgr } from "./portMgr";
export class PortDevtools extends PortMan {
init(): void {
this.onDisconnect = () => {
portMgr.removePort(this);
};
this.onMessage = (data: PluginEvent) => {
if (data.msg === Msg.RequestUseFrame) {
// 因为devtool是定时器驱动这里改变了content后续就会将数据派发到对应的content中去
portMgr.useFrame((data.data as RequestUseFrameData).id, this.tabID);
} else {
// 从devtools过来的消息统一派发到目标content中
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", version: "" } as ResponseSupportData);
this.send(e);
}
}
}
};
}
}