mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-16 05:26:31 +00:00
e2513fa4c8
Co-authored-by: qwerty287 <80460567+qwerty287@users.noreply.github.com>
60 lines
1.5 KiB
TypeScript
60 lines
1.5 KiB
TypeScript
import { computed, ref, watch } from 'vue';
|
|
|
|
import useConfig from '~/compositions/useConfig';
|
|
import { useTheme } from '~/compositions/useTheme';
|
|
import type { PipelineStatus } from '~/lib/api/types';
|
|
|
|
const { theme } = useTheme();
|
|
const darkMode = computed(() => theme.value);
|
|
|
|
type Status = 'default' | 'success' | 'pending' | 'error';
|
|
const faviconStatus = ref<Status>('default');
|
|
|
|
watch(
|
|
[darkMode, faviconStatus],
|
|
() => {
|
|
const faviconPNG = document.getElementById('favicon-png');
|
|
if (faviconPNG) {
|
|
(faviconPNG as HTMLLinkElement).href = `${useConfig().rootPath}/favicons/favicon-${darkMode.value}-${
|
|
faviconStatus.value
|
|
}.png`;
|
|
}
|
|
|
|
const faviconSVG = document.getElementById('favicon-svg');
|
|
if (faviconSVG) {
|
|
(faviconSVG as HTMLLinkElement).href = `${useConfig().rootPath}/favicons/favicon-${darkMode.value}-${
|
|
faviconStatus.value
|
|
}.svg`;
|
|
}
|
|
},
|
|
{ immediate: true },
|
|
);
|
|
|
|
function convertStatus(status: PipelineStatus): Status {
|
|
if (['declined', 'error', 'failure', 'killed'].includes(status)) {
|
|
return 'error';
|
|
}
|
|
|
|
if (['blocked', 'started', 'running', 'pending'].includes(status)) {
|
|
return 'pending';
|
|
}
|
|
|
|
if (status === 'success') {
|
|
return 'success';
|
|
}
|
|
|
|
// skipped
|
|
return 'default';
|
|
}
|
|
|
|
export function useFavicon() {
|
|
return {
|
|
updateStatus(status?: PipelineStatus | 'default') {
|
|
if (status === undefined || status === 'default') {
|
|
faviconStatus.value = 'default';
|
|
} else {
|
|
faviconStatus.value = convertStatus(status);
|
|
}
|
|
},
|
|
};
|
|
}
|