From e5e38d92b9cbb39932856367dff9d6b458c39eeb Mon Sep 17 00:00:00 2001 From: xuyanfeng Date: Sat, 8 May 2021 22:05:59 +0800 Subject: [PATCH] =?UTF-8?q?=E4=B9=8B=E5=89=8D=E7=9A=84=E9=80=BB=E8=BE=91?= =?UTF-8?q?=E4=BC=98=E5=8C=96?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- source/src/background.ts | 15 +++++++++++---- source/src/devtools/inject.ts | 18 +++++++++++------- source/src/devtools/register-panel.ts | 4 ++-- 3 files changed, 24 insertions(+), 13 deletions(-) diff --git a/source/src/background.ts b/source/src/background.ts index 14431d9..cf8c534 100644 --- a/source/src/background.ts +++ b/source/src/background.ts @@ -1,4 +1,4 @@ -import {Page, PluginEvent} from "@/core/types"; +import {Page, PluginEvent, Msg} from "@/core/types"; let Devtools: chrome.runtime.Port | null = null; let Content: chrome.runtime.Port | null = null; @@ -64,11 +64,18 @@ chrome.runtime.onMessage.addListener((request: PluginEvent, sender: any, sendRes ); chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) { + console.warn(changeInfo.status) if (changeInfo.status === "complete") { // 加载新的url - // if (Content) { - // Content.postMessage(new PluginEvent(Msg.UrlChange, {url: tab.favIconUrl})); - // } + if (Content) { + let data = new PluginEvent( + Page.Background, + Page.Content, + Msg.UrlChange, + {url: tab.favIconUrl} + ); + Content.postMessage(data); + } } }) diff --git a/source/src/devtools/inject.ts b/source/src/devtools/inject.ts index b3f3fbe..aa4a8be 100644 --- a/source/src/devtools/inject.ts +++ b/source/src/devtools/inject.ts @@ -19,13 +19,17 @@ class CCInspector { init() { console.log('cc-inspector init ~~~'); - setInterval(() => { - // this.checkIsGamePage(true); - // if (this.stop) { - // } else { - // } - }, 1000); // 注册cc_after_render事件 + let timer = setInterval(() => { + if (this._isCocosGame()) { + clearInterval(timer) + // @ts-ignore + cc.director.on(cc.Director.EVENT_AFTER_SCENE_LAUNCH, () => { + console.log('scene launch') + }) + } + }, 300) + window.addEventListener("message", (event) => { // 接受来自content的事件,有可能也会受到其他插件的 if (!event || !event.data) { @@ -33,7 +37,7 @@ class CCInspector { } let pluginEvent: PluginEvent = event.data; if (PluginEvent.check(pluginEvent, Page.Content, Page.Inject)) { - console.log(`[Inject] ${JSON.stringify(pluginEvent)}`, 'color:green;'); + console.log(`%c[Inject] ${JSON.stringify(pluginEvent)}`, 'color:green;'); PluginEvent.finish(pluginEvent) switch (pluginEvent.msg) { case Msg.UrlChange: diff --git a/source/src/devtools/register-panel.ts b/source/src/devtools/register-panel.ts index 4db0613..3e80f53 100644 --- a/source/src/devtools/register-panel.ts +++ b/source/src/devtools/register-panel.ts @@ -1,5 +1,6 @@ import Manifest from '../manifest.json' import {connectBackground} from "@/devtools/connectBackground"; +import {PluginEvent, Msg, Page} from "@/core/types"; export function init() { if (chrome && chrome.devtools) { @@ -14,8 +15,7 @@ export function init() { panel.onShown.addListener((window) => { // 面板显示,查询是否是cocos游戏 console.log("panel show"); - // let sendData = new PluginEvent(PluginMsg.Msg.Support); - // connectBackground.postMessage(sendData) + connectBackground.postMessageToBackground(Msg.Support, null) }); panel.onHidden.addListener(() => { // 面板隐藏