修复另外一个devtools定时器会干扰刷新逻辑的bug

This commit is contained in:
xu_yanfeng 2025-01-15 14:38:53 +08:00
parent 12ddbf8ac9
commit 36a380695a
9 changed files with 45 additions and 45 deletions

View File

@ -0,0 +1,4 @@
export const PanelMsg = {
Show: "Show",
Hide: "Hide",
};

View File

@ -39,14 +39,15 @@ export default defineComponent({
}; };
const funcEnableSchedule = (b: boolean) => { const funcEnableSchedule = (b: boolean) => {
if (b) { if (b) {
timer_hierarchy.create(); timer.create();
} else { } else {
timer_hierarchy.clean(); timer.clean();
} }
}; };
const timer_hierarchy: Timer = new Timer(() => { const timer: Timer = new Timer(() => {
updateTree(); updateTree();
}); });
timer.name = "hierarchy";
let ins: MousetrapInstance | null = null; let ins: MousetrapInstance | null = null;
function onQuickVisible() { function onQuickVisible() {
ga.fireEvent(GA_EventName.SpaceVisible); ga.fireEvent(GA_EventName.SpaceVisible);
@ -68,7 +69,7 @@ export default defineComponent({
Bus.on(BusMsg.ChangeContent, changeContent); Bus.on(BusMsg.ChangeContent, changeContent);
Bus.on(BusMsg.ShowPlace, funcShowPlace); Bus.on(BusMsg.ShowPlace, funcShowPlace);
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule); Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
timer_hierarchy.create(); timer.create(true);
}); });
onUnmounted(() => { onUnmounted(() => {
if (ins) { if (ins) {
@ -77,7 +78,7 @@ export default defineComponent({
Bus.off(BusMsg.ChangeContent, changeContent); Bus.off(BusMsg.ChangeContent, changeContent);
Bus.off(BusMsg.ShowPlace, funcShowPlace); Bus.off(BusMsg.ShowPlace, funcShowPlace);
Bus.off(BusMsg.EnableSchedule, funcEnableSchedule); Bus.off(BusMsg.EnableSchedule, funcEnableSchedule);
timer_hierarchy.clean(); timer.clean();
}); });
function _expand(uuid: string) { function _expand(uuid: string) {
if (elTree.value) { if (elTree.value) {
@ -218,13 +219,13 @@ export default defineComponent({
menus.push({ menus.push({
name: "fresh auto", name: "fresh auto",
callback: () => { callback: () => {
timer_hierarchy.create(); timer.create();
}, },
}); });
menus.push({ menus.push({
name: "fresh manual", name: "fresh manual",
callback: () => { callback: () => {
timer_hierarchy.clean(); timer.clean();
}, },
}); });
menus.push({ menus.push({

View File

@ -7,10 +7,14 @@ import { createApp } from "vue";
import pluginConfig from "../../../cc-plugin.config"; import pluginConfig from "../../../cc-plugin.config";
import "../global.less"; import "../global.less";
import App from "./index.vue"; import App from "./index.vue";
import { init } from "./register-panel";
export default CCP.init(pluginConfig, { export default CCP.init(pluginConfig, {
ready: function (rootElement: any, args: any) { ready: function (rootElement: any, args: any) {
init(); if (args && args.body) {
ccui.uiElement.setBody(args.body);
}
if (args && args.doc) {
ccui.uiElement.setDoc(args.doc);
}
const app = createApp(App); const app = createApp(App);
app.use(ccui); app.use(ccui);
app.use(createPinia()); app.use(createPinia());

View File

@ -63,6 +63,7 @@ export default defineComponent({
const timer = new Timer(() => { const timer = new Timer(() => {
checkSupport(); checkSupport();
}); });
timer.name = "devtools";
onMounted(() => { onMounted(() => {
ccui.footbar.showTipsArray({ ccui.footbar.showTipsArray({
tips: [ tips: [
@ -92,7 +93,7 @@ export default defineComponent({
}, },
}); });
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule); Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
timer.create(); timer.create(true);
}); });
onUnmounted(() => { onUnmounted(() => {
Bus.off(BusMsg.EnableSchedule, funcEnableSchedule); Bus.off(BusMsg.EnableSchedule, funcEnableSchedule);

View File

@ -12,13 +12,13 @@ import ccui from "@xuyanfeng/cc-ui";
import { IUiMenuItem } from "@xuyanfeng/cc-ui/types/cc-menu/const"; import { IUiMenuItem } from "@xuyanfeng/cc-ui/types/cc-menu/const";
import { defineComponent, onMounted, onUnmounted, ref } from "vue"; import { defineComponent, onMounted, onUnmounted, ref } from "vue";
import { Msg, PluginEvent, RequestNodeInfoData, ResponseSupportData } from "../../core/types"; import { Msg, PluginEvent, RequestNodeInfoData, ResponseSupportData } from "../../core/types";
import { ga } from "../../ga";
import { GA_EventName } from "../../ga/type";
import { bridge } from "./bridge"; import { bridge } from "./bridge";
import { Bus, BusMsg } from "./bus"; import { Bus, BusMsg } from "./bus";
import { NodeInfoData } from "./data"; import { NodeInfoData } from "./data";
import { Timer } from "./timer"; import { Timer } from "./timer";
import Properties from "./ui/propertys.vue"; import Properties from "./ui/propertys.vue";
import { ga } from "../../ga";
import { GA_EventName } from "../../ga/type";
const { CCDock } = ccui.components; const { CCDock } = ccui.components;
export default defineComponent({ export default defineComponent({
components: { Properties, CCDock }, components: { Properties, CCDock },
@ -32,6 +32,7 @@ export default defineComponent({
} }
} }
const timer = new Timer(updateNodeInfo); const timer = new Timer(updateNodeInfo);
timer.name = "inspector";
const treeItemData = ref<NodeInfoData | null>(null); const treeItemData = ref<NodeInfoData | null>(null);
const funcEnableSchedule = (b: boolean) => { const funcEnableSchedule = (b: boolean) => {
if (b) { if (b) {
@ -54,7 +55,7 @@ export default defineComponent({
Bus.on(BusMsg.ChangeContent, changeContent); Bus.on(BusMsg.ChangeContent, changeContent);
Bus.on(BusMsg.SelectNode, funSelectNode); Bus.on(BusMsg.SelectNode, funSelectNode);
Bus.on(BusMsg.EnableSchedule, funcEnableSchedule); Bus.on(BusMsg.EnableSchedule, funcEnableSchedule);
timer.create(); timer.create(true);
}); });
onUnmounted(() => { onUnmounted(() => {
Bus.off(BusMsg.ChangeContent, changeContent); Bus.off(BusMsg.ChangeContent, changeContent);

View File

@ -1,34 +1,10 @@
import CCP from "cc-plugin/src/ccp/entry-render"; import CCP from "cc-plugin/src/ccp/entry-render";
import { ChromeConst } from "cc-plugin/src/chrome/const";
import { Msg, RequestSupportData } from "../../core/types";
import { bridge } from "./bridge";
export function init() { export function init() {
if (chrome && chrome.devtools) { if (chrome && chrome.devtools) {
// 对应的是Elements面板的边栏 // 对应的是Elements面板的边栏
chrome.devtools.panels.elements.createSidebarPane(CCP.manifest.name, function (sidebar) { chrome.devtools.panels.elements.createSidebarPane(CCP.manifest.name, function (sidebar) {
sidebar.setObject({ some_data: "some data to show!" }); sidebar.setObject({ some_data: "some data to show!" });
}); });
// 创建devtools-panel
let iconPath = "";
const { icon } = CCP.manifest;
if (icon && icon["48"]) {
iconPath = icon["48"];
}
chrome.devtools.panels.create(CCP.manifest.name, iconPath, ChromeConst.html.devtools, (panel: chrome.devtools.panels.ExtensionPanel) => {
console.log("[CC-Inspector] Dev Panel Created!");
panel.onShown.addListener((window) => {
// 面板显示查询是否是cocos游戏
bridge.send(Msg.RequestSupport, {} as RequestSupportData);
});
panel.onHidden.addListener(() => {
// 面板隐藏
console.log("panel hide");
});
panel.onSearch.addListener(function (action, query) {
// ctrl+f 查找触发
console.log("panel search!");
});
});
} }
} }

View File

@ -1,5 +0,0 @@

View File

@ -2,6 +2,7 @@ import profile from "cc-plugin/src/ccp/profile";
import { defineStore } from "pinia"; import { defineStore } from "pinia";
import { ref, toRaw } from "vue"; import { ref, toRaw } from "vue";
import pluginConfig from "../../../cc-plugin.config"; import pluginConfig from "../../../cc-plugin.config";
import { PanelMsg } from "./const";
export const enum RefreshType { export const enum RefreshType {
Auto = "auto", Auto = "auto",
Manual = "manual", Manual = "manual",
@ -24,10 +25,19 @@ export class ConfigData {
export const appStore = defineStore("app", () => { export const appStore = defineStore("app", () => {
const config = ref<ConfigData>(new ConfigData()); const config = ref<ConfigData>(new ConfigData());
const frameID = ref<number>(0); const frameID = ref<number>(0);
const pageShow = ref<boolean>(false);
return { return {
frameID, frameID,
pageShow,
config, config,
init() { init() {
if (chrome.devtools) {
window.addEventListener(PanelMsg.Show, () => {
pageShow.value = true;
});
} else {
pageShow.value = true;
}
profile.init(new ConfigData(), pluginConfig); profile.init(new ConfigData(), pluginConfig);
const data = profile.load(`${pluginConfig.manifest.name}.json`) as ConfigData; const data = profile.load(`${pluginConfig.manifest.name}.json`) as ConfigData;
config.value.refreshType = data.refreshType || RefreshType.Manual; config.value.refreshType = data.refreshType || RefreshType.Manual;

View File

@ -1,16 +1,24 @@
export class Timer { export class Timer {
private timer: number = 0; private timer: number | null = null;
private callback: Function | null = null; private callback: Function | null = null;
private duration: number = 0; private duration: number = 0;
public name: string = "";
constructor(cb: Function = null, duration: number = 300) { constructor(cb: Function = null, duration: number = 300) {
this.callback = cb; this.callback = cb;
this.duration = duration; this.duration = duration;
} }
create() { create(rightNow: boolean = false) {
this.clean(); this.clean();
this.timer = setInterval(this.callback, this.duration); this.timer = setInterval(this.callback, this.duration);
if (rightNow) {
this.callback && this.callback();
}
} }
clean() { clean() {
if (this.timer === null) {
return;
}
clearInterval(this.timer); clearInterval(this.timer);
this.timer = null;
} }
} }