mirror of
https://github.com/woodpecker-ci/woodpecker.git
synced 2024-12-16 13:36:33 +00:00
67b7de5cc2
I'm not sure if this is an ideal fix for this, but it seems to work for me. If you have another idea just let me know. Closes #1798 Closes #1773
59 lines
1.6 KiB
TypeScript
59 lines
1.6 KiB
TypeScript
import { computed, ref, watch } from 'vue';
|
|
|
|
import useConfig from '~/compositions/useConfig';
|
|
import { useDarkMode } from '~/compositions/useDarkMode';
|
|
import { PipelineStatus } from '~/lib/api/types';
|
|
|
|
const darkMode = computed(() => (useDarkMode().darkMode.value ? 'dark' : 'light'));
|
|
|
|
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 (['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 {
|
|
updateStatus(status?: PipelineStatus | 'default') {
|
|
if (status === undefined || status === 'default') {
|
|
faviconStatus.value = 'default';
|
|
} else {
|
|
faviconStatus.value = convertStatus(status);
|
|
}
|
|
},
|
|
};
|
|
}
|