mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-11-01 05:55:25 +00:00
逻辑优化
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
import { ChromeConst } from "cc-plugin/src/chrome/const";
|
||||
import { Msg, Page, PluginEvent, RequestSupportData } from "../../core/types";
|
||||
import { debugLog, Msg, Page, PluginEvent, RequestSupportData } from "../../core/types";
|
||||
import { Terminal } from "../terminal";
|
||||
import { PortMan } from "./portMan";
|
||||
import { portMgr } from "./portMgr";
|
||||
const terminal = new Terminal(Page.Background);
|
||||
console.log(...terminal.init());
|
||||
debugLog && console.log(...terminal.init());
|
||||
function isDevtools(port: chrome.runtime.Port) {
|
||||
const devtoolsUrl = `chrome-extension://${port.sender?.id}/${ChromeConst.html.devtools}`;
|
||||
if (port.sender?.url === devtoolsUrl) {
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Page, PluginEvent } from "../../core/types";
|
||||
import { debugLog, Page, PluginEvent } from "../../core/types";
|
||||
import { Terminal } from "../terminal";
|
||||
|
||||
export abstract class PortMan {
|
||||
@@ -29,15 +29,15 @@ 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()));
|
||||
debugLog && console.log(...this.terminal.chunkMessage(event.toChunk()));
|
||||
if (event.valid && this.onMessage) {
|
||||
this.onMessage(event);
|
||||
} else {
|
||||
console.log(...this.terminal.log(JSON.stringify(data)));
|
||||
debugLog && console.log(...this.terminal.log(JSON.stringify(data)));
|
||||
}
|
||||
});
|
||||
port.onDisconnect.addListener((port: chrome.runtime.Port) => {
|
||||
console.log(...this.terminal.disconnect(""));
|
||||
debugLog && console.log(...this.terminal.disconnect(""));
|
||||
if (this.onDisconnect) {
|
||||
this.onDisconnect(port);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
import { Msg, Page, PluginEvent, RequestSupportData, ResponseUpdateFramesData } from "../../core/types";
|
||||
import { debugLog, Msg, Page, PluginEvent, RequestSupportData, ResponseUpdateFramesData } from "../../core/types";
|
||||
import { FrameDetails } from "../../views/devtools/data";
|
||||
import { Terminal } from "../terminal";
|
||||
import { PortContent } from "./portContent";
|
||||
@@ -76,9 +76,9 @@ export class PortMgr {
|
||||
|
||||
if (arr.length) {
|
||||
// console.table(arr)
|
||||
console.log(...this.terminal.log(str.join("\n"), true));
|
||||
debugLog && console.log(...this.terminal.log(str.join("\n"), true));
|
||||
} else {
|
||||
console.log(...this.terminal.log("no port connected"));
|
||||
debugLog && console.log(...this.terminal.log("no port connected"));
|
||||
}
|
||||
}
|
||||
public removePort(item: PortMan) {
|
||||
|
||||
Reference in New Issue
Block a user