逻辑优化

This commit is contained in:
xu_yanfeng
2025-01-06 19:46:38 +08:00
parent 250155cd35
commit 82215235d9
12 changed files with 150 additions and 53 deletions

View File

@@ -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) {

View File

@@ -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);
}

View File

@@ -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) {