mirror of
https://github.com/tidys/cc-inspector-chrome
synced 2025-04-18 07:58:40 +00:00
之前的逻辑优化
This commit is contained in:
parent
8debbe8974
commit
e5e38d92b9
@ -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);
|
||||
}
|
||||
}
|
||||
})
|
||||
|
||||
|
@ -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:
|
||||
|
@ -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(() => {
|
||||
// 面板隐藏
|
||||
|
Loading…
x
Reference in New Issue
Block a user