private async loadPlugins () {
this.pluginService.initializePlugins()
- await this.pluginService.loadPluginsByScope('common')
-
- this.hooks.runAction('action:application.init')
+ this.hooks.runAction('action:application.init', 'common')
}
private initHotkeys () {
return this.pluginService.runHook(hookName, result, params)
}
- runAction<T, U extends ClientActionHookName> (hookName: U, params?: T) {
- this.pluginService.runHook(hookName, params)
- .catch((err: any) => console.error('Fatal hook error.', { err }))
+ runAction<T, U extends ClientActionHookName> (hookName: U, scope: PluginClientScope, params?: T) {
+ this.pluginService.ensurePluginsAreLoaded(scope)
+ .then(() => this.pluginService.runHook(hookName, params))
+ .catch((err: any) => console.error('Fatal hook error.', { err }))
}
}
private scopes: { [ scopeName: string ]: PluginInfo[] } = {}
private loadedScripts: { [ script: string ]: boolean } = {}
private loadedScopes: PluginClientScope[] = []
+ private loadingScopes: { [id in PluginClientScope]?: boolean } = {}
private hooks: { [ name: string ]: HookStructValue[] } = {}
}
ensurePluginsAreLoaded (scope: PluginClientScope) {
+ this.loadPluginsByScope(scope)
+
return this.pluginsLoaded[scope].asObservable()
.pipe(first(), shareReplay())
.toPromise()
}
async loadPluginsByScope (scope: PluginClientScope, isReload = false) {
+ if (this.loadingScopes[scope]) return
+ if (!isReload && this.loadedScopes.includes(scope)) return
+
+ this.loadingScopes[scope] = true
+
try {
await this.ensurePluginsAreBuilt()
const toLoad = this.scopes[ scope ]
if (!Array.isArray(toLoad)) {
+ this.loadingScopes[scope] = false
this.pluginsLoaded[scope].next(true)
return
await Promise.all(promises)
this.pluginsLoaded[scope].next(true)
+ this.loadingScopes[scope] = false
} catch (err) {
console.error('Cannot load plugins by scope %s.', scope, err)
}
}
ngOnInit () {
- this.pluginService.loadPluginsByScope('search')
-
this.subActivatedRoute = this.route.queryParams.subscribe(
queryParams => {
const querySearch = queryParams['search']
err => this.notifier.error(err.text)
)
- this.hooks.runAction('action:search.init')
+ this.hooks.runAction('action:search.init', 'search')
}
ngOnDestroy () {
}
async ngOnInit () {
- this.pluginService.loadPluginsByScope('video-watch')
-
this.configSub = this.serverService.configLoaded
.subscribe(() => {
if (
this.theaterEnabled = getStoredTheater()
- this.hooks.runAction('action:video-watch.init')
+ this.hooks.runAction('action:video-watch.init', 'video-watch')
}
ngOnDestroy () {
this.setOpenGraphTags()
this.checkUserRating()
- this.hooks.runAction('action:video-watch.video.loaded')
+ this.hooks.runAction('action:video-watch.video.loaded', 'video-watch')
}
private setRating (nextRating: UserVideoRateType) {