2021-12-08 12:58:00 +00:00
|
|
|
import { computed, ref, watch } from 'vue';
|
|
|
|
|
2023-08-07 14:05:18 +00:00
|
|
|
import useConfig from '~/compositions/useConfig';
|
2023-11-01 09:30:40 +00:00
|
|
|
import { useTheme } from '~/compositions/useTheme';
|
2024-06-06 13:16:59 +00:00
|
|
|
import type { PipelineStatus } from '~/lib/api/types';
|
2021-12-08 12:58:00 +00:00
|
|
|
|
2023-11-01 09:30:40 +00:00
|
|
|
const { theme } = useTheme();
|
|
|
|
const darkMode = computed(() => theme.value);
|
2021-12-08 12:58:00 +00:00
|
|
|
|
|
|
|
type Status = 'default' | 'success' | 'pending' | 'error';
|
|
|
|
const faviconStatus = ref<Status>('default');
|
|
|
|
|
|
|
|
watch(
|
|
|
|
[darkMode, faviconStatus],
|
|
|
|
() => {
|
|
|
|
const faviconPNG = document.getElementById('favicon-png');
|
|
|
|
if (faviconPNG) {
|
2023-08-07 14:05:18 +00:00
|
|
|
(faviconPNG as HTMLLinkElement).href = `${useConfig().rootPath}/favicons/favicon-${darkMode.value}-${
|
|
|
|
faviconStatus.value
|
|
|
|
}.png`;
|
2021-12-08 12:58:00 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
const faviconSVG = document.getElementById('favicon-svg');
|
|
|
|
if (faviconSVG) {
|
2023-08-07 14:05:18 +00:00
|
|
|
(faviconSVG as HTMLLinkElement).href = `${useConfig().rootPath}/favicons/favicon-${darkMode.value}-${
|
|
|
|
faviconStatus.value
|
|
|
|
}.svg`;
|
2021-12-08 12:58:00 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
{ immediate: true },
|
|
|
|
);
|
|
|
|
|
2022-10-18 01:24:12 +00:00
|
|
|
function convertStatus(status: PipelineStatus): Status {
|
2024-06-25 06:09:29 +00:00
|
|
|
if (['declined', 'error', 'failure', 'killed'].includes(status)) {
|
2021-12-08 12:58:00 +00:00
|
|
|
return 'error';
|
|
|
|
}
|
|
|
|
|
2024-06-25 06:09:29 +00:00
|
|
|
if (['blocked', 'started', 'running', 'pending'].includes(status)) {
|
2021-12-08 12:58:00 +00:00
|
|
|
return 'pending';
|
|
|
|
}
|
|
|
|
|
2024-06-25 06:09:29 +00:00
|
|
|
if (status === 'success') {
|
2021-12-08 12:58:00 +00:00
|
|
|
return 'success';
|
|
|
|
}
|
|
|
|
|
|
|
|
// skipped
|
|
|
|
return 'default';
|
|
|
|
}
|
|
|
|
|
|
|
|
export function useFavicon() {
|
|
|
|
return {
|
2022-10-18 01:24:12 +00:00
|
|
|
updateStatus(status?: PipelineStatus | 'default') {
|
2021-12-08 12:58:00 +00:00
|
|
|
if (status === undefined || status === 'default') {
|
|
|
|
faviconStatus.value = 'default';
|
|
|
|
} else {
|
|
|
|
faviconStatus.value = convertStatus(status);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|