-import { Injectable } from '@angular/core'
+import { Injectable, NgZone } from '@angular/core'
import { Router } from '@angular/router'
import { ServerConfigPlugin } from '@shared/models'
import { ServerService } from '@app/core/server/server.service'
import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model'
import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type'
import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
-import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
import { HttpClient } from '@angular/common/http'
import { RestExtractor } from '@app/shared/rest'
import { PluginType } from '@shared/models/plugins/plugin.type'
constructor (
private router: Router,
private server: ServerService,
+ private zone: NgZone,
private authHttp: HttpClient,
private restExtractor: RestExtractor
) {
}
}
- async runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> {
- if (!this.hooks[hookName]) return Promise.resolve(result)
+ runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> {
+ return this.zone.runOutsideAngular(async () => {
+ if (!this.hooks[ hookName ]) return result
- const hookType = getHookType(hookName)
+ const hookType = getHookType(hookName)
- for (const hook of this.hooks[hookName]) {
- console.log('Running hook %s of plugin %s.', hookName, hook.plugin.name)
+ for (const hook of this.hooks[ hookName ]) {
+ console.log('Running hook %s of plugin %s.', hookName, hook.plugin.name)
- result = await internalRunHook(hook.handler, hookType, result, params, err => {
- console.error('Cannot run hook %s of script %s of plugin %s.', hookName, hook.clientScript.script, hook.plugin.name, err)
- })
- }
+ result = await internalRunHook(hook.handler, hookType, result, params, err => {
+ console.error('Cannot run hook %s of script %s of plugin %s.', hookName, hook.clientScript.script, hook.plugin.name, err)
+ })
+ }
- return result
+ return result
+ })
}
nameToNpmName (name: string, type: PluginType) {
console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name)
- return import(/* webpackIgnore: true */ clientScript.script)
- .then((script: ClientScriptModule) => script.register({ registerHook, peertubeHelpers }))
- .then(() => this.sortHooksByPriority())
- .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err))
+ return this.zone.runOutsideAngular(() => {
+ return import(/* webpackIgnore: true */ clientScript.script)
+ .then((script: ClientScriptModule) => script.register({ registerHook, peertubeHelpers }))
+ .then(() => this.sortHooksByPriority())
+ .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err))
+ })
}
private buildScopeStruct () {