63 lines
1.6 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;
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);
2024-12-09 19:25:06 +08:00
return {
frameID,
pageShow,
2024-12-09 19:25:06 +08:00
config,
init() {
if (chrome.devtools) {
window.addEventListener(PanelMsg.Show, () => {
pageShow.value = true;
});
} else {
pageShow.value = true;
}
2024-12-09 19:25:06 +08:00
profile.init(new ConfigData(), pluginConfig);
const data = profile.load(`${pluginConfig.manifest.name}.json`) as ConfigData;
config.value.refreshType = data.refreshType || RefreshType.Manual;
config.value.refreshTime = data.refreshTime || 500;
config.value.expandTest = !!data.expandTest;
2025-01-17 10:18:26 +08:00
config.value.refreshHirarchy = !!data.refreshHirarchy;
config.value.refreshInspector = !!data.refreshInspector;
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
};
});