2025-01-08 16:37:12 +08:00
|
|
|
|
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) => {
|
2024-12-27 19:20:22 +08:00
|
|
|
|
if (data.msg === Msg.RequestUseFrame) {
|
2025-01-08 16:37:12 +08:00
|
|
|
|
// 因为devtool是定时器驱动,这里改变了content,后续就会将数据派发到对应的content中去
|
2025-01-08 16:38:43 +08:00
|
|
|
|
portMgr.useFrame((data.data as RequestUseFrameData).id, this.tabID);
|
2024-12-24 17:31:26 +08:00
|
|
|
|
} else {
|
2025-01-08 16:37:12 +08:00
|
|
|
|
// 从devtools过来的消息统一派发到目标content中
|
2024-12-27 14:14:38 +08:00
|
|
|
|
if (data.check(Page.Devtools, Page.Background)) {
|
|
|
|
|
data.reset(Page.Background, Page.Content);
|
2025-01-08 16:38:43 +08:00
|
|
|
|
const port = portMgr.getCurrentUsePort(this.tabID);
|
2025-01-08 16:37:12 +08:00
|
|
|
|
if (port) {
|
|
|
|
|
port.send(data);
|
|
|
|
|
} else {
|
2025-01-07 19:44:05 +08:00
|
|
|
|
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
|
|
|
|
}
|