Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 24 additions & 11 deletions ui/src/utils/guiTheme.js
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
Expand All @@ -52,7 +65,7 @@ async function fetchGuiTheme (params) {
}
}).catch(error => {
console.error('Error fetching GUI theme:', error)
return null
return LOOKUP_FAILED
})
}

Expand Down
Loading