重构background对port的管理,彻底修复多标签页面数据相互串的bug

This commit is contained in:
xu_yanfeng
2025-01-27 13:07:35 +08:00
parent f7bd7790e1
commit 63e842deb3
10 changed files with 239 additions and 243 deletions

View File

@@ -1,3 +1,4 @@
import { Page } from "./types";
interface LogOptions {
data: any;
@@ -7,12 +8,12 @@ interface LogOptions {
export function log(options: LogOptions) {
const data: any = options.data;
const time = new Date().toLocaleString()
let log = ""
const time = new Date().toLocaleString();
let log = "";
if (typeof data === "string") {
log = data;
} else if (typeof data === "object") {
log = JSON.stringify(data)
log = JSON.stringify(data);
}
let str = "";
@@ -22,8 +23,16 @@ export function log(options: LogOptions) {
str = `[${time}]: ${log} `;
}
if (options.color) {
console.log(`%c${str}`, `color:${options.color};`)
console.log(`%c${str}`, `color:${options.color};`);
} else {
console.log(str);
}
}
export function assembleDevToolsName(id: number) {
return `${Page.Devtools}-${id}`;
}
export function getDevToolsInspectorId(name: string) {
const id = name.split("-")[1];
return id ? Number(id) : 0;
}