diff --git a/cc-inspector/src/core/types.ts b/cc-inspector/src/core/types.ts index c35a9a7..2e8e54c 100644 --- a/cc-inspector/src/core/types.ts +++ b/cc-inspector/src/core/types.ts @@ -26,8 +26,14 @@ export class PluginEvent { msg: Msg | null = null; data: any = null; - source: Page | null = null; // 事件发送的源头 - target: Page | null = null; // 事件要发送的目标 + /** + * 事件发送的源头 + */ + source: Page | null = null; + /** + * 事件要发送的目标 + */ + target: Page | null = null; static check(event: PluginEvent, source: Page, target: Page) { return event && source && target && event.source === source && event.target === target; @@ -40,6 +46,9 @@ export class PluginEvent { } } + /** + * + */ static finish(event: PluginEvent) { event.source = event.target = null; } diff --git a/cc-inspector/src/scripts/inject/index.ts b/cc-inspector/src/scripts/inject/index.ts index bd1d71a..79664e0 100644 --- a/cc-inspector/src/scripts/inject/index.ts +++ b/cc-inspector/src/scripts/inject/index.ts @@ -41,7 +41,7 @@ class CCInspector { clearInterval(timer); // @ts-ignore cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, () => { - let isCocosGame = this._isCocosGame(); + const isCocosGame = this._isCocosGame(); this.notifySupportGame(isCocosGame); }); } @@ -126,10 +126,7 @@ class CCInspector { sendMsgToContent(msg: Msg, data: any) { // 发送给content.js处理,也会导致发送给了自身,死循环 - window.postMessage( - new PluginEvent(Page.Inject, Page.Content, msg, data), - "*" - ); + window.postMessage(new PluginEvent(Page.Inject, Page.Content, msg, data), "*"); } notifySupportGame(b: boolean) { @@ -536,7 +533,7 @@ class CCInspector { let keyDesc = ""; if (Array.isArray(propValue)) { // 只收集一级key - propValue.forEach((item) => {}); + propValue.forEach((item) => { }); keyDesc = `(${propValue.length}) [...]`; } else if (this._isInvalidValue(propValue)) { // 不能改变顺序 @@ -581,7 +578,7 @@ class CCInspector { const name = this.getCompName(node); let nodeGroup = new Group(name, node.uuid); let keys = this._getNodeKeys(node); - for (let i = 0; i < keys.length; ) { + for (let i = 0; i < keys.length;) { let key = keys[i]; let pair = this._getPairProperty(key); if (pair && this._checkKeysValid(node, pair.values)) { @@ -730,7 +727,7 @@ class CCInspector { } } -let inspector = new CCInspector(); +const inspector = new CCInspector(); inspector.init(); //@ts-ignore window.CCInspector = inspector; diff --git a/cc-inspector/src/views/devtools/connectBackground.ts b/cc-inspector/src/views/devtools/connectBackground.ts index da81f60..c170bc8 100644 --- a/cc-inspector/src/views/devtools/connectBackground.ts +++ b/cc-inspector/src/views/devtools/connectBackground.ts @@ -24,7 +24,13 @@ class ConnectBackground { }); } } - + sendMsgToContentScript(msg: Msg, data?: any) { + if (!chrome || !chrome.devtools) { + console.log("环境异常,无法执行函数"); + return; + } + this.postMessageToBackground(msg, data); + } postMessageToBackground(msg: Msg, data?: any) { if (this.connect) { let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data) diff --git a/cc-inspector/src/views/devtools/index.ts b/cc-inspector/src/views/devtools/index.ts index da0bf7c..ce2b421 100644 --- a/cc-inspector/src/views/devtools/index.ts +++ b/cc-inspector/src/views/devtools/index.ts @@ -1,5 +1,4 @@ import { createApp } from "vue"; -// 用的是ui/index.vue import App from "./index.vue"; import CCP from "cc-plugin/src/ccp/entry-render"; import pluginConfig from "../../../cc-plugin.config"; diff --git a/cc-inspector/src/views/devtools/index.vue b/cc-inspector/src/views/devtools/index.vue index 14beaa2..5575f4a 100644 --- a/cc-inspector/src/views/devtools/index.vue +++ b/cc-inspector/src/views/devtools/index.vue @@ -7,7 +7,7 @@ -->
inspect target:
- +
@@ -27,6 +27,7 @@
+