打通流程

This commit is contained in:
xuyanfeng
2021-04-28 19:49:26 +08:00
parent c4fb53646f
commit 9ec28b510b
7 changed files with 55 additions and 56 deletions

View File

@@ -16,7 +16,6 @@ class ConnectBackground {
onBackgroundMessage(cb: Function) {
if (this.connect) {
this.connect.onMessage.addListener((event, sender) => {
console.log(`[Message] ${JSON.stringify(event)}`);
cb && cb(event, sender)
});
}

View File

@@ -45,8 +45,8 @@
import Vue from "vue";
import {Component} from "vue-property-decorator";
import properties from "./propertys.vue";
import {DataSupport, NodeData} from "@/devtools/type";
import {PluginEvent, Page, Msg} from '@/core/types'
import { NodeData} from "@/devtools/type";
import {Msg, Page, PluginEvent} from '@/core/types'
import {connectBackground} from "@/devtools/connectBackground";
@Component({
@@ -80,7 +80,6 @@ export default class Index extends Vue {
}
window.addEventListener("message", function (event) {
console.log("on vue:" + JSON.stringify(event.data));
console.log("on vue:" + JSON.stringify(event));
}, false);
}
@@ -112,9 +111,9 @@ export default class Index extends Vue {
this.memory = eventData;
}
_onMsgSupport(data: DataSupport) {
this.isShowDebug = data.support;
if (data.support) {
_onMsgSupport(data:boolean) {
this.isShowDebug = data;
if (data) {
// 如果节点树为空,就刷新一次
if (this.treeData.length === 0) {
// this.onBtnClickUpdateTree();
@@ -135,9 +134,10 @@ export default class Index extends Vue {
if (!data) {
return;
}
if (data.target === Page.Background) {
if (PluginEvent.check(data, Page.Background, Page.Devtools)) {
console.log(`[Devtools] ${JSON.stringify(data)}`);
PluginEvent.finish(data);
let eventData: any = data.data;
console.log(data)
switch (data.msg) {
case Msg.UrlChange: {
break;
@@ -147,7 +147,7 @@ export default class Index extends Vue {
break;
}
case Msg.Support: {
this._onMsgSupport(eventData as DataSupport)
this._onMsgSupport(!!eventData)
break;
}
case Msg.NodeInfo: {
@@ -194,8 +194,7 @@ export default class Index extends Vue {
console.log("环境异常,无法执行函数");
return;
}
debugger
let sendData = new PluginEvent(Page.Background, msg, data)
let sendData = new PluginEvent(Page.Devtools, Page.Background, msg, data)
connectBackground.postMessageToBackground(sendData);
}

View File

@@ -32,21 +32,25 @@ class CCInspector {
return
}
let pluginEvent: PluginEvent = event.data;
if (pluginEvent.target === Page.Inject) {
if (PluginEvent.check(pluginEvent, Page.Content, Page.Inject)) {
console.log(`[Inject] ${JSON.stringify(pluginEvent)}`, 'color:green;');
PluginEvent.finish(pluginEvent)
switch (pluginEvent.msg) {
case Msg.UrlChange:
case Msg.Support: {
let isCocosGame = this._isCocosGame();
this.sendMsgToContent(Msg.Support, {support: isCocosGame});
this.notifySupportGame(isCocosGame)
break;
}
case Msg.TreeInfo: {
debugger
this.updateTreeInfo();
break;
}
case Msg.NodeInfo: {
debugger
let nodeUUID = pluginEvent.data;
this.getNodeInfo(nodeUUID);
break;
}
case Msg.SetProperty: {
@@ -60,31 +64,11 @@ class CCInspector {
sendMsgToContent(msg: Msg, data: any) {
// 发送给content.js处理也会导致发送给了自身死循环
window.postMessage(new PluginEvent(Page.Inject, msg, data), "*");
window.postMessage(new PluginEvent(Page.Inject, Page.Content, msg, data), "*");
}
devPageCallEntry(str: string) {
let para: PluginEvent = JSON.parse(str);
debugger
if (this._isCocosGame()) {
switch (para.msg) {
case Msg.TreeInfo:
this.updateTreeInfo();
break;
case Msg.Support:
break;
case Msg.MemoryInfo:
break;
case Msg.SetProperty:
break;
case Msg.NodeInfo:
this.getNodeInfo(para.data as string);
break;
}
} else {
this.sendMsgToContent(Msg.Support, {support: false});
}
notifySupportGame(b: boolean) {
this.sendMsgToContent(Msg.Support, b);
}
updateTreeInfo() {
@@ -108,6 +92,8 @@ class CCInspector {
} else {
this.sendMsgToContent(Msg.Support, {support: false, msg: "未发现游戏场景,不支持调试游戏!"});
}
} else {
this.notifySupportGame(false)
}
}

View File

@@ -4,10 +4,7 @@ export class NodeData {
children: Array<NodeData> = []
}
export class DataSupport {
support: boolean = false;
msg?: string;
}