1
0
Fork 0
mirror of https://github.com/Chocobozzz/PeerTube.git synced 2025-10-03 17:59:37 +02:00

Wait CSS variables to be ready

This commit is contained in:
Chocobozzz 2025-04-10 09:16:58 +02:00
parent 334ad174a9
commit a496da3780
No known key found for this signature in database
GPG key ID: 583A612D890159BE

View file

@ -170,12 +170,33 @@ export class ThemeService {
this.localStorageService.removeItem(UserLocalStorageKeys.LAST_ACTIVE_THEME, false)
}
setTimeout(() => this.injectColorPalette(), 0)
this.injectCoreColorPalette()
this.oldThemeName = currentTheme
}
private injectCoreColorPalette (iteration = 0) {
if (iteration > 10) {
logger.error('Cannot inject core color palette: too many iterations')
return
}
if (!this.canInjectColorPalette()) {
return setTimeout(() => this.injectCoreColorPalette(iteration + 1))
}
return this.injectColorPalette()
}
private canInjectColorPalette () {
const computedStyle = getComputedStyle(document.body)
return !!computedStyle.getPropertyValue('--fg')
}
private injectColorPalette () {
debugLogger(`Injecting color palette`)
const rootStyle = document.body.style
const computedStyle = getComputedStyle(document.body)