mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-21 09:28:40 +00:00
修复devtool链接2次的问题
This commit is contained in:
parent
36a380695a
commit
e6f7425883
@ -14,11 +14,13 @@ class Bridge implements TestClient {
|
|||||||
*/
|
*/
|
||||||
private connect: chrome.runtime.Port | null = null;
|
private connect: chrome.runtime.Port | null = null;
|
||||||
private terminal = new Terminal(Page.Devtools);
|
private terminal = new Terminal(Page.Devtools);
|
||||||
constructor() {
|
|
||||||
this.init();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
private _inited = false;
|
||||||
private init() {
|
private init() {
|
||||||
|
if (this._inited) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
this._inited = true;
|
||||||
if (CCP.Adaptation.Env.isChromeRuntime) {
|
if (CCP.Adaptation.Env.isChromeRuntime) {
|
||||||
this.connect = chrome.runtime.connect({ name: Page.Devtools });
|
this.connect = chrome.runtime.connect({ name: Page.Devtools });
|
||||||
this.connect.onDisconnect.addListener(() => {
|
this.connect.onDisconnect.addListener(() => {
|
||||||
@ -53,12 +55,14 @@ class Bridge implements TestClient {
|
|||||||
this.emitter.emit(data.msg, data);
|
this.emitter.emit(data.msg, data);
|
||||||
}
|
}
|
||||||
send(msg: Msg, data?: any) {
|
send(msg: Msg, data?: any) {
|
||||||
|
this.init();
|
||||||
if (CCP.Adaptation.Env.isChromeDevtools) {
|
if (CCP.Adaptation.Env.isChromeDevtools) {
|
||||||
if (this.connect) {
|
if (this.connect) {
|
||||||
let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data);
|
let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data);
|
||||||
this.connect.postMessage(sendData);
|
this.connect.postMessage(sendData);
|
||||||
} else {
|
} else {
|
||||||
console.warn(...this.terminal.log("重新和background建立链接"));
|
console.warn(...this.terminal.log("重新和background建立链接"));
|
||||||
|
this._inited = false;
|
||||||
this.init();
|
this.init();
|
||||||
this.send(msg, data);
|
this.send(msg, data);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user