修复不同的tab,允许使用不同的frame content

This commit is contained in:
xu_yanfeng 2025-01-08 16:53:49 +08:00
parent 30e51657ae
commit 645605c60d
2 changed files with 6 additions and 4 deletions

View File

@ -21,7 +21,7 @@ export class PortContent extends PortMan {
this.onDisconnect = (disPort: chrome.runtime.Port) => { this.onDisconnect = (disPort: chrome.runtime.Port) => {
// content失去链接需要更新Devtools // content失去链接需要更新Devtools
portMgr.removePort(this); portMgr.removePort(this);
if (portMgr.currentUseContentFrameID === this.frameID) { if (portMgr.tabUseFrameID[this.tabID] === this.frameID) {
portMgr.useFrame(0, this.tabID); portMgr.useFrame(0, this.tabID);
} }
}; };

View File

@ -13,8 +13,10 @@ export class PortMgr {
public portArray: Array<PortMan> = []; public portArray: Array<PortMan> = [];
/** /**
* frameIDiframe嵌套 * frameIDiframe嵌套
*
* tab使frameID可以不一样
*/ */
public currentUseContentFrameID = 0; public tabUseFrameID: Record<number, number> = {};
private terminal = new Terminal("PortMgr"); private terminal = new Terminal("PortMgr");
public findPort(id: number): PortMan | null { public findPort(id: number): PortMan | null {
@ -101,12 +103,12 @@ export class PortMgr {
} }
getCurrentUsePort(tabID: number): PortMan | null { getCurrentUsePort(tabID: number): PortMan | null {
const portMan = this.portArray.find((portMan: PortMan) => { const portMan = this.portArray.find((portMan: PortMan) => {
return portMan.isContent() && portMan.tabID === tabID && portMan.isUseing(this.currentUseContentFrameID); return portMan.isContent() && portMan.tabID === tabID && portMan.isUseing(this.tabUseFrameID[tabID]);
}); });
return portMan || null; return portMan || null;
} }
useFrame(id: number, tabID: number) { useFrame(id: number, tabID: number) {
this.currentUseContentFrameID = id; this.tabUseFrameID[tabID] = id;
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseUpdateFrames, { id } as ResponseUseFrameData); const event = new PluginEvent(Page.Background, Page.Devtools, Msg.ResponseUpdateFrames, { id } as ResponseUseFrameData);
this.sendDevtoolMsg(event, tabID); this.sendDevtoolMsg(event, tabID);
} }