diff --git a/ui/src/utils/guiTheme.js b/ui/src/utils/guiTheme.js index dab82287d111..b3b0766634f2 100644 --- a/ui/src/utils/guiTheme.js +++ b/ui/src/utils/guiTheme.js @@ -19,28 +19,41 @@ import { vueProps } from '@/vue-app' import { getAPI } from '@/api' import { loadLanguageAsync } from '../locales' +const LOOKUP_FAILED = Symbol('lookupFailed') +let currentGuiTheme + export async function applyCustomGuiTheme (accountid, domainid) { await fetch('config.json').then(response => response.json()).then(config => { vueProps.$config = config }) - let guiTheme - + const lookups = [] if (accountid != null) { - guiTheme = await fetchGuiTheme({ accountid: accountid }) + lookups.push({ accountid: accountid }) } - - if (guiTheme === undefined && domainid != null) { - guiTheme = await fetchGuiTheme({ domainid: domainid }) + if (domainid != null) { + lookups.push({ domainid: domainid }) } + lookups.push({ commonname: window.location.hostname }) + lookups.push({ listonlydefaulttheme: true }) - if (guiTheme === undefined) { - guiTheme = await fetchGuiTheme({ commonname: window.location.hostname }) + let guiTheme + let lookupFailed = false + for (const params of lookups) { + const result = await fetchGuiTheme(params) + if (result === LOOKUP_FAILED) { + lookupFailed = true + } else if (result !== undefined) { + guiTheme = result + break + } } - if (guiTheme === undefined) { - guiTheme = await fetchGuiTheme({ listonlydefaulttheme: true }) + // A failed lookup does not mean there is no theme, so keep the one already shown + if (guiTheme === undefined && lookupFailed) { + guiTheme = currentGuiTheme } + currentGuiTheme = guiTheme await applyDynamicCustomization(guiTheme) } @@ -52,7 +65,7 @@ async function fetchGuiTheme (params) { } }).catch(error => { console.error('Error fetching GUI theme:', error) - return null + return LOOKUP_FAILED }) }