2025-02-03 13:22:09 +08:00

85 lines
2.3 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

import profile from "cc-plugin/src/ccp/profile";
import { defineStore } from "pinia";
import { ref, toRaw } from "vue";
import pluginConfig from "../../../cc-plugin.config";
import { PanelMsg } from "./const";
export const enum RefreshType {
Auto = "auto",
Manual = "manual",
}
export class ConfigData {
/**
* 刷新类型
*/
refreshType: string = RefreshType.Manual;
/**
* 刷新间隔时间单位ms
*/
refreshTime: number = 500;
/**
* 展开测试的section
*/
expandTest: boolean = false;
/**
* 是否自动刷新inspector
*/
refreshInspector: boolean = true;
/**
* 是否自动刷新hierarchy
*/
refreshHirarchy: boolean = true;
/**
* 当鼠标滑过节点树时游戏是否同步Inspect
*/
hoverInspect: boolean = true;
/**
* 当节点树点击时游戏是否同步Inspect
*/
clickInspect: boolean = true;
/**
* 显示节点树的icon
*/
showTreeIcon: boolean = true;
}
export const appStore = defineStore("app", () => {
const config = ref<ConfigData>(new ConfigData());
const frameID = ref<number>(0);
const pageShow = ref<boolean>(false);
function readConfigFile(file: string) {
const data = profile.load(file) as ConfigData;
config.value.refreshType = data.refreshType || RefreshType.Manual;
config.value.refreshTime = data.refreshTime || 500;
config.value.expandTest = !!data.expandTest;
config.value.refreshHirarchy = !!data.refreshHirarchy;
config.value.refreshInspector = !!data.refreshInspector;
config.value.hoverInspect = !!data.hoverInspect;
config.value.clickInspect = !!data.clickInspect;
config.value.showTreeIcon = !!data.showTreeIcon;
}
return {
frameID,
pageShow,
config,
init() {
profile.init(new ConfigData(), pluginConfig);
if (chrome.devtools) {
window.addEventListener(PanelMsg.Show, () => {
pageShow.value = true;
});
chrome.devtools.inspectedWindow.eval("window.location.href", (url: string, ex: chrome.devtools.inspectedWindow.EvaluationExceptionInfo) => {
readConfigFile(url);
});
} else {
pageShow.value = true;
readConfigFile(`${pluginConfig.manifest.name}.json`);
}
},
save() {
const cfg = toRaw(config.value);
profile.save(cfg);
},
};
});