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

Fix theme crash in embed

This commit is contained in:
Chocobozzz 2025-05-30 14:58:37 +02:00
parent f85e1a57d4
commit d1bb28374b
No known key found for this signature in database
GPG key ID: 583A612D890159BE
4 changed files with 31 additions and 14 deletions

View file

@ -54,7 +54,9 @@ export class ThemeManager {
injectCoreColorPalette (iteration = 0) { injectCoreColorPalette (iteration = 0) {
if (iteration > 100) { if (iteration > 100) {
logger.error('Cannot inject core color palette: too many iterations') logger.error('Too many iteration when checking color palette injection. The theme may be missing the --is-dark CSS variable')
this.injectColorPalette()
return return
} }

View file

@ -104,7 +104,7 @@ export class PeerTubeEmbed {
.then(res => res.json()) .then(res => res.json())
} }
this.peertubeTheme.loadTheme(this.config) this.peertubeTheme.loadThemeStyle(this.config)
const videoId = this.isPlaylistEmbed() const videoId = this.isPlaylistEmbed()
? await this.initPlaylist() ? await this.initPlaylist()
@ -441,7 +441,14 @@ export class PeerTubeEmbed {
const [ { PeerTubePlayer, videojs } ] = await Promise.all([ const [ { PeerTubePlayer, videojs } ] = await Promise.all([
this.PeerTubePlayerManagerModulePromise, this.PeerTubePlayerManagerModulePromise,
this.peertubePlugin.loadPlugins(this.config, await this.translationsPromise)
this.translationsPromise.then(translations => {
this.peertubePlugin.init(translations)
this.peertubePlugin.loadPlugins(this.config)
this.peertubeTheme.loadThemePlugins(this.config)
return this.peertubePlugin.ensurePluginsAreLoaded()
})
]) ])
this.videojs = videojs this.videojs = videojs

View file

@ -7,24 +7,27 @@ import { Translations } from './translations'
import { getBackendUrl } from './url' import { getBackendUrl } from './url'
export class PeerTubePlugin { export class PeerTubePlugin {
private pluginsManager: PluginsManager private pluginsManager: PluginsManager
constructor (private readonly http: AuthHTTP) { constructor (private readonly http: AuthHTTP) {
} }
loadPlugins (config: HTMLServerConfig, translations?: Translations) { init (translations?: Translations) {
this.pluginsManager = new PluginsManager({ this.pluginsManager = new PluginsManager({
peertubeHelpersFactory: pluginInfo => this.buildPeerTubeHelpers({ peertubeHelpersFactory: pluginInfo =>
this.buildPeerTubeHelpers({
pluginInfo, pluginInfo,
translations translations
}), }),
backendUrl: getBackendUrl() backendUrl: getBackendUrl()
}) })
}
loadPlugins (config: HTMLServerConfig) {
this.pluginsManager.loadPluginsList(config) this.pluginsManager.loadPluginsList(config)
}
ensurePluginsAreLoaded () {
return this.pluginsManager.ensurePluginsAreLoaded('embed') return this.pluginsManager.ensurePluginsAreLoaded('embed')
} }

View file

@ -9,16 +9,23 @@ export class PeerTubeTheme {
constructor (private readonly pluginPlugin: PeerTubePlugin) { constructor (private readonly pluginPlugin: PeerTubePlugin) {
} }
loadTheme (config: HTMLServerConfig) { loadThemeStyle (config: HTMLServerConfig) {
for (const theme of config.theme.registered) { for (const theme of config.theme.registered) {
this.themeManager.injectTheme(theme, getBackendUrl()) this.themeManager.injectTheme(theme, getBackendUrl())
} }
const themeName = this.getCurrentThemeName(config) const themeName = this.getCurrentThemeName(config)
logger.info(`Enabling ${themeName} theme.`) logger.info(`Enabling ${themeName} theme style.`)
this.themeManager.loadThemeStyle(themeName) this.themeManager.loadThemeStyle(themeName)
this.themeManager.injectCoreColorPalette()
}
loadThemePlugins (config: HTMLServerConfig) {
const themeName = this.getCurrentThemeName(config)
logger.info(`Loading ${themeName} theme plugins.`)
const theme = config.theme.registered.find(t => t.name === themeName) const theme = config.theme.registered.find(t => t.name === themeName)
const isInternalTheme = config.theme.builtIn.map(t => t.name as string).includes(themeName) const isInternalTheme = config.theme.builtIn.map(t => t.name as string).includes(themeName)
@ -31,8 +38,6 @@ export class PeerTubeTheme {
pluginManager.addPlugin(theme, true) pluginManager.addPlugin(theme, true)
pluginManager.reloadLoadedScopes() pluginManager.reloadLoadedScopes()
} }
this.themeManager.injectCoreColorPalette()
} }
private getCurrentThemeName (config: HTMLServerConfig) { private getCurrentThemeName (config: HTMLServerConfig) {