2024-06-26 10:42:50 +00:00
|
|
|
import { usePermission } from "@/utils/permission";
|
2022-11-02 06:40:16 +00:00
|
|
|
import type { Theme } from "@halo-dev/api-client";
|
2024-06-26 10:42:50 +00:00
|
|
|
import { consoleApiClient } from "@halo-dev/api-client";
|
2022-11-02 06:40:16 +00:00
|
|
|
import { defineStore } from "pinia";
|
2022-12-07 02:50:53 +00:00
|
|
|
import { ref } from "vue";
|
2022-11-02 06:40:16 +00:00
|
|
|
|
2022-12-07 02:50:53 +00:00
|
|
|
export const useThemeStore = defineStore("theme", () => {
|
|
|
|
const activatedTheme = ref<Theme>();
|
2022-11-02 06:40:16 +00:00
|
|
|
|
2023-01-30 06:36:10 +00:00
|
|
|
const { currentUserHasPermission } = usePermission();
|
2022-11-02 06:40:16 +00:00
|
|
|
|
2023-01-30 06:36:10 +00:00
|
|
|
async function fetchActivatedTheme() {
|
|
|
|
if (!currentUserHasPermission(["system:themes:view"])) {
|
|
|
|
return;
|
|
|
|
}
|
2022-11-02 06:40:16 +00:00
|
|
|
|
2023-01-30 06:36:10 +00:00
|
|
|
try {
|
2024-06-25 04:31:44 +00:00
|
|
|
const { data } = await consoleApiClient.theme.theme.fetchActivatedTheme({
|
2023-01-30 06:36:10 +00:00
|
|
|
mute: true,
|
|
|
|
});
|
2022-11-02 06:40:16 +00:00
|
|
|
|
2023-02-01 02:48:10 +00:00
|
|
|
if (data) {
|
|
|
|
activatedTheme.value = data;
|
|
|
|
}
|
2022-12-07 02:50:53 +00:00
|
|
|
} catch (e) {
|
|
|
|
console.error("Failed to fetch active theme", e);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return { activatedTheme, fetchActivatedTheme };
|
2022-11-02 06:40:16 +00:00
|
|
|
});
|