80 lines
2.2 KiB
TypeScript
Raw Normal View History

2024-12-09 19:25:06 +08:00
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";
2024-12-09 19:25:06 +08:00
export const enum RefreshType {
Auto = "auto",
Manual = "manual",
}
export class ConfigData {
/**
*
*/
refreshType: string = RefreshType.Manual;
/**
* ms
*/
refreshTime: number = 500;
/**
* section
*/
expandTest: boolean = false;
2025-01-17 10:18:26 +08:00
/**
* inspector
*/
refreshInspector: boolean = true;
/**
* hierarchy
*/
refreshHirarchy: boolean = true;
2025-01-27 21:35:10 +08:00
/**
* Inspect
*/
hoverInspect: boolean = true;
/**
* Inspect
*/
clickInspect: boolean = true;
2024-12-09 19:25:06 +08:00
}
export const appStore = defineStore("app", () => {
const config = ref<ConfigData>(new ConfigData());
const frameID = ref<number>(0);
const pageShow = ref<boolean>(false);
2025-01-27 21:00:51 +08:00
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;
2025-01-27 21:35:10 +08:00
config.value.hoverInspect = !!data.hoverInspect;
config.value.clickInspect = !!data.clickInspect;
2025-01-27 21:00:51 +08:00
}
2024-12-09 19:25:06 +08:00
return {
frameID,
pageShow,
2024-12-09 19:25:06 +08:00
config,
init() {
2025-01-27 21:00:51 +08:00
profile.init(new ConfigData(), pluginConfig);
if (chrome.devtools) {
window.addEventListener(PanelMsg.Show, () => {
pageShow.value = true;
});
2025-01-27 21:00:51 +08:00
chrome.devtools.inspectedWindow.eval("window.location.href", (url: string, ex: chrome.devtools.inspectedWindow.EvaluationExceptionInfo) => {
readConfigFile(url);
});
} else {
pageShow.value = true;
2025-01-27 21:00:51 +08:00
readConfigFile(`${pluginConfig.manifest.name}.json`);
}
2024-12-09 19:25:06 +08:00
},
save() {
const cfg = toRaw(config.value);
profile.save(cfg);
},
2024-12-27 14:23:27 +08:00
};
});