mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-11-01 05:55:25 +00:00
优化输出日志的颜色
This commit is contained in:
@@ -20,19 +20,20 @@ export abstract class PortMan {
|
||||
public onDisconnect: (port: chrome.runtime.Port) => void | null = null;
|
||||
public onMessage: (data: PluginEvent) => void | null = null;
|
||||
public terminal: Terminal = null;
|
||||
public timestamp: number = 0;
|
||||
constructor(tab: chrome.tabs.Tab, port: chrome.runtime.Port) {
|
||||
this.timestamp = Date.now();
|
||||
this.port = port;
|
||||
this.tab = tab;
|
||||
this.name = port.name;
|
||||
this.id = tab.id;
|
||||
this.url = tab.url;
|
||||
this.title = tab.title;
|
||||
this.terminal = new Terminal(`Port-${this.name}/ID-${this.id}`);
|
||||
port.onMessage.addListener((data: any, sender: any) => {
|
||||
const str = `${sender.name}\n${JSON.stringify(data)}`
|
||||
console.log(... this.terminal.green(str));
|
||||
this.terminal = new Terminal(`Port-${this.name}`);
|
||||
port.onMessage.addListener((data: any, port: chrome.runtime.Port) => {
|
||||
console.log(... this.terminal.message(JSON.stringify(data)));
|
||||
// 如果多个页面都监听 onMessage 事件,对于某一次事件只有第一次调用 sendResponse() 能成功发出回应,所有其他回应将被忽略。
|
||||
// sender.postMessage(data);
|
||||
// port.postMessage(data);
|
||||
const cls = PluginEvent.create(data);
|
||||
if (this.onMessage) {
|
||||
this.onMessage(cls);
|
||||
|
||||
@@ -70,7 +70,7 @@ export class PortMgr {
|
||||
id: port.id,
|
||||
url: port.url
|
||||
});
|
||||
str.push(`[${i + 1}] name:${port.name}, id:${port.id}, 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) {
|
||||
@@ -92,9 +92,11 @@ export class PortMgr {
|
||||
this.getCurrentUseContent()?.postMessage(data);
|
||||
}
|
||||
sendDevtoolMsg(data: PluginEvent) {
|
||||
const portMan = this.portArray.find(el => el.isDevtoolsPort());
|
||||
if (portMan) {
|
||||
portMan.port.postMessage(data);
|
||||
const portManArray = this.portArray.filter(el => el.isDevtoolsPort());
|
||||
if (portManArray.length) {
|
||||
portManArray.forEach(portMan => {
|
||||
portMan.port.postMessage(data);
|
||||
})
|
||||
} else {
|
||||
console.log('not find devtools port');
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user