43 lines
1.1 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";
export const enum RefreshType {
Auto = "auto",
Manual = "manual",
}
export class ConfigData {
/**
*
*/
refreshType: string = RefreshType.Manual;
/**
* ms
*/
refreshTime: number = 500;
/**
* section
*/
expandTest: boolean = false;
2024-12-09 19:25:06 +08:00
}
export const appStore = defineStore("app", () => {
const config = ref<ConfigData>(new ConfigData());
const frameID = ref<number>(0);
2024-12-09 19:25:06 +08:00
return {
frameID,
2024-12-09 19:25:06 +08:00
config,
init() {
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;
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
};
});