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";
|
2025-01-15 14:38:53 +08:00
|
|
|
|
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;
|
2024-12-25 17:16:11 +08:00
|
|
|
|
/**
|
|
|
|
|
* 展开测试的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());
|
2024-12-27 21:08:26 +08:00
|
|
|
|
const frameID = ref<number>(0);
|
2025-01-15 14:38:53 +08:00
|
|
|
|
const pageShow = ref<boolean>(false);
|
2024-12-09 19:25:06 +08:00
|
|
|
|
return {
|
2024-12-27 21:08:26 +08:00
|
|
|
|
frameID,
|
2025-01-15 14:38:53 +08:00
|
|
|
|
pageShow,
|
2024-12-09 19:25:06 +08:00
|
|
|
|
config,
|
|
|
|
|
init() {
|
2025-01-15 14:38:53 +08:00
|
|
|
|
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;
|
2024-12-25 17:16:11 +08:00
|
|
|
|
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
|
|
|
|
};
|
|
|
|
|
});
|