之前的逻辑优化

This commit is contained in:
xuyanfeng 2021-05-08 22:05:59 +08:00
parent 8debbe8974
commit e5e38d92b9
3 changed files with 24 additions and 13 deletions

View File

@ -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 Devtools: chrome.runtime.Port | null = null;
let Content: 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) { chrome.tabs.onUpdated.addListener(function (tabId, changeInfo, tab) {
console.warn(changeInfo.status)
if (changeInfo.status === "complete") { if (changeInfo.status === "complete") {
// 加载新的url // 加载新的url
// if (Content) { if (Content) {
// Content.postMessage(new PluginEvent(Msg.UrlChange, {url: tab.favIconUrl})); let data = new PluginEvent(
// } Page.Background,
Page.Content,
Msg.UrlChange,
{url: tab.favIconUrl}
);
Content.postMessage(data);
}
} }
}) })

View File

@ -19,13 +19,17 @@ class CCInspector {
init() { init() {
console.log('cc-inspector init ~~~'); console.log('cc-inspector init ~~~');
setInterval(() => {
// this.checkIsGamePage(true);
// if (this.stop) {
// } else {
// }
}, 1000);
// 注册cc_after_render事件 // 注册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) => { window.addEventListener("message", (event) => {
// 接受来自content的事件有可能也会受到其他插件的 // 接受来自content的事件有可能也会受到其他插件的
if (!event || !event.data) { if (!event || !event.data) {
@ -33,7 +37,7 @@ class CCInspector {
} }
let pluginEvent: PluginEvent = event.data; let pluginEvent: PluginEvent = event.data;
if (PluginEvent.check(pluginEvent, Page.Content, Page.Inject)) { 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) PluginEvent.finish(pluginEvent)
switch (pluginEvent.msg) { switch (pluginEvent.msg) {
case Msg.UrlChange: case Msg.UrlChange:

View File

@ -1,5 +1,6 @@
import Manifest from '../manifest.json' import Manifest from '../manifest.json'
import {connectBackground} from "@/devtools/connectBackground"; import {connectBackground} from "@/devtools/connectBackground";
import {PluginEvent, Msg, Page} from "@/core/types";
export function init() { export function init() {
if (chrome && chrome.devtools) { if (chrome && chrome.devtools) {
@ -14,8 +15,7 @@ export function init() {
panel.onShown.addListener((window) => { panel.onShown.addListener((window) => {
// 面板显示查询是否是cocos游戏 // 面板显示查询是否是cocos游戏
console.log("panel show"); console.log("panel show");
// let sendData = new PluginEvent(PluginMsg.Msg.Support); connectBackground.postMessageToBackground(Msg.Support, null)
// connectBackground.postMessage(sendData)
}); });
panel.onHidden.addListener(() => { panel.onHidden.addListener(() => {
// 面板隐藏 // 面板隐藏