mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-10-23 00:35:23 +00:00
格式化代码
This commit is contained in:
@@ -1,9 +1,8 @@
|
||||
import { ChromeConst } from "cc-plugin/src/chrome/const";
|
||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||
import { FrameDetails } from "../../views/devtools/data";
|
||||
import { PortMan } from "./portMan";
|
||||
import { PortMgr, portMgr } from "./portMgr";
|
||||
import { Terminal } from "../terminal";
|
||||
import { PortMan } from "./portMan";
|
||||
import { portMgr } from "./portMgr";
|
||||
const terminal = new Terminal(Page.Background);
|
||||
console.log(...terminal.init());
|
||||
function isDevtools(port: chrome.runtime.Port) {
|
||||
@@ -16,7 +15,7 @@ function onTabConnect(tab: chrome.tabs.Tab, port: chrome.runtime.Port) {
|
||||
debugger;
|
||||
return;
|
||||
}
|
||||
let portMan = portMgr.findPort(tab.id)
|
||||
let portMan = portMgr.findPort(tab.id);
|
||||
if (portMan) {
|
||||
// 一个port发起多次发起链接,以最后一次的为数据通讯基准
|
||||
// portMgr.removePort(portMan);
|
||||
@@ -30,7 +29,7 @@ chrome.runtime.onConnect.addListener((port: chrome.runtime.Port) => {
|
||||
chrome.tabs.query({ active: true }, (tabs: chrome.tabs.Tab[]) => {
|
||||
tabs.forEach((tab) => {
|
||||
onTabConnect(tab, port);
|
||||
})
|
||||
});
|
||||
});
|
||||
} else {
|
||||
const tab: chrome.tabs.Tab | undefined = port.sender?.tab;
|
||||
@@ -52,7 +51,7 @@ chrome.runtime.onMessage.addListener((request: PluginEvent, sender: any, sendRes
|
||||
}
|
||||
}
|
||||
});
|
||||
chrome.tabs.onActivated.addListener(({ tabId, windowId }) => { });
|
||||
chrome.tabs.onActivated.addListener(({ tabId, windowId }) => {});
|
||||
chrome.tabs.onUpdated.addListener((tabId, changeInfo, tab) => {
|
||||
// 页面发生刷新,通知重新生成数据
|
||||
if (changeInfo.status === "complete") {
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||
import { PluginEvent } from "../../core/types";
|
||||
import { PortMan } from "./portMan";
|
||||
import { portMgr } from "./portMgr";
|
||||
import { FrameDetails } from "views/devtools/data";
|
||||
|
||||
export class PortContent extends PortMan {
|
||||
init(): void {
|
||||
@@ -28,4 +27,4 @@ export class PortContent extends PortMan {
|
||||
}
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -8,7 +8,7 @@ export class PortDevtools extends PortMan {
|
||||
portMgr._updateFrames();
|
||||
this.onDisconnect = () => {
|
||||
portMgr.removePort(this);
|
||||
}
|
||||
};
|
||||
this.onMessage = (data: PluginEvent) => {
|
||||
if (data.msg === Msg.UseFrame) {
|
||||
portMgr.useFrame(data.data);
|
||||
@@ -29,8 +29,6 @@ export class PortDevtools extends PortMan {
|
||||
port.postMessage(data);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
@@ -1,8 +1,5 @@
|
||||
import { ChromeConst } from "cc-plugin/src/chrome/const";
|
||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||
import { FrameDetails } from "../../views/devtools/data";
|
||||
import { Page, PluginEvent } from "../../core/types";
|
||||
import { Terminal } from "../terminal";
|
||||
import { portMgr } from "./portMgr";
|
||||
|
||||
export abstract class PortMan {
|
||||
/**
|
||||
@@ -32,13 +29,13 @@ export abstract class PortMan {
|
||||
this.terminal = new Terminal(`Port-${this.name}`);
|
||||
port.onMessage.addListener((data: any, port: chrome.runtime.Port) => {
|
||||
const event = PluginEvent.create(data);
|
||||
console.log(... this.terminal.chunkMessage(event.toChunk()));
|
||||
console.log(...this.terminal.chunkMessage(event.toChunk()));
|
||||
// 如果多个页面都监听 onMessage 事件,对于某一次事件只有第一次调用 sendResponse() 能成功发出回应,所有其他回应将被忽略。
|
||||
// port.postMessage(data);
|
||||
if (event.valid && this.onMessage) {
|
||||
this.onMessage(event);
|
||||
} else {
|
||||
console.log(... this.terminal.log(JSON.stringify(data)));
|
||||
console.log(...this.terminal.log(JSON.stringify(data)));
|
||||
}
|
||||
});
|
||||
port.onDisconnect.addListener((port: chrome.runtime.Port) => {
|
||||
@@ -56,4 +53,4 @@ export abstract class PortMan {
|
||||
isDevtoolsPort() {
|
||||
return this.name === Page.Devtools;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -1,9 +1,9 @@
|
||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||
import { PortMan } from "./portMan";
|
||||
import { PortDevtools } from "./portDevtools";
|
||||
import { PortContent } from "./portContent";
|
||||
import { FrameDetails } from "views/devtools/data";
|
||||
import { Msg, Page, PluginEvent } from "../../core/types";
|
||||
import { Terminal } from "../terminal";
|
||||
import { PortContent } from "./portContent";
|
||||
import { PortDevtools } from "./portDevtools";
|
||||
import { PortMan } from "./portMan";
|
||||
|
||||
export class PortMgr {
|
||||
/**
|
||||
@@ -15,7 +15,7 @@ export class PortMgr {
|
||||
* 当前正在通讯的frameID,因为游戏可能被好几个iframe嵌套
|
||||
*/
|
||||
private currentUseContentFrameID = 0;
|
||||
private terminal = new Terminal('PortMgr');
|
||||
private terminal = new Terminal("PortMgr");
|
||||
public findDevtoolsPort() {
|
||||
return this.portArray.find((el) => el.name === Page.Devtools);
|
||||
}
|
||||
@@ -25,14 +25,14 @@ export class PortMgr {
|
||||
public _updateFrames() {
|
||||
// 将content类型的port收集起来,同步到devtools
|
||||
const data: FrameDetails[] = [];
|
||||
this.portArray.forEach(item => {
|
||||
this.portArray.forEach((item) => {
|
||||
if (item.isConnectPort()) {
|
||||
data.push({
|
||||
url: item.port.sender?.url || "",
|
||||
frameID: item.port.sender?.frameId || 0,
|
||||
})
|
||||
});
|
||||
}
|
||||
})
|
||||
});
|
||||
const event = new PluginEvent(Page.Background, Page.Devtools, Msg.UpdateFrames, data);
|
||||
this.sendDevtoolMsg(event);
|
||||
}
|
||||
@@ -49,7 +49,7 @@ export class PortMgr {
|
||||
break;
|
||||
}
|
||||
default: {
|
||||
debugger
|
||||
debugger;
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -61,23 +61,23 @@ export class PortMgr {
|
||||
return null;
|
||||
}
|
||||
public logState() {
|
||||
let arr: Array<{ name: string, id: number, url: string }> = [];
|
||||
let arr: Array<{ name: string; id: number; url: string }> = [];
|
||||
let str: string[] = [];
|
||||
for (let i = 0; i < this.portArray.length; i++) {
|
||||
const port = this.portArray[i];
|
||||
arr.push({
|
||||
name: port.name,
|
||||
id: port.id,
|
||||
url: port.url
|
||||
url: port.url,
|
||||
});
|
||||
str.push(`[${i + 1}] time:${new Date(port.timestamp).toLocaleString()}, name:${port.name}, id:${port.id}, url:${port.url}`);
|
||||
}
|
||||
|
||||
if (arr.length) {
|
||||
// console.table(arr)
|
||||
console.log(... this.terminal.log(str.join('\n'), true));
|
||||
console.log(...this.terminal.log(str.join("\n"), true));
|
||||
} else {
|
||||
console.log(... this.terminal.log("no port connected"));
|
||||
console.log(...this.terminal.log("no port connected"));
|
||||
}
|
||||
}
|
||||
public removePort(item: PortMan) {
|
||||
@@ -92,22 +92,22 @@ export class PortMgr {
|
||||
this.getCurrentUseContent()?.postMessage(data);
|
||||
}
|
||||
sendDevtoolMsg(data: PluginEvent) {
|
||||
const portManArray = this.portArray.filter(el => el.isDevtoolsPort());
|
||||
const portManArray = this.portArray.filter((el) => el.isDevtoolsPort());
|
||||
if (portManArray.length) {
|
||||
portManArray.forEach(portMan => {
|
||||
portManArray.forEach((portMan) => {
|
||||
portMan.port.postMessage(data);
|
||||
})
|
||||
});
|
||||
} else {
|
||||
console.log('not find devtools port');
|
||||
console.log("not find devtools port");
|
||||
}
|
||||
}
|
||||
getCurrentUseContent(): chrome.runtime.Port | null {
|
||||
const portMan = this.portArray.find((portMan: PortMan) => {
|
||||
const el = portMan.port;
|
||||
const b1 = el.sender?.frameId !== undefined;
|
||||
const b2 = el.sender.frameId === this.currentUseContentFrameID
|
||||
return b1 && b2
|
||||
})
|
||||
const b2 = el.sender.frameId === this.currentUseContentFrameID;
|
||||
return b1 && b2;
|
||||
});
|
||||
if (portMan) {
|
||||
return portMan.port;
|
||||
} else {
|
||||
@@ -121,7 +121,7 @@ export class PortMgr {
|
||||
this.getCurrentUseContent()?.postMessage(sendData);
|
||||
}
|
||||
isCurrentFrme(id: number) {
|
||||
return this.currentUseContentFrameID === id
|
||||
return this.currentUseContentFrameID === id;
|
||||
}
|
||||
}
|
||||
export const portMgr = new PortMgr();
|
||||
export const portMgr = new PortMgr();
|
||||
|
@@ -7,4 +7,4 @@ export enum DocumentEvent {
|
||||
* 从content到inject的事件
|
||||
*/
|
||||
Content2Inject = "content2inject",
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user