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';
|
2022-10-18 01:24:12 +00:00
|
|
|
import { 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 {
|
2021-12-08 12:58:00 +00:00
|
|
|
if (['blocked', 'declined', 'error', 'failure', 'killed'].includes(status)) {
|
|
|
|
return 'error';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (['started', 'running', 'pending'].includes(status)) {
|
|
|
|
return 'pending';
|
|
|
|
}
|
|
|
|
|
|
|
|
if (['success', 'declined', 'error', 'failure', 'killed'].includes(status)) {
|
|
|
|
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);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
};
|
|
|
|
}
|