aboutsummaryrefslogtreecommitdiffhomepage
path: root/client/src
diff options
context:
space:
mode:
Diffstat (limited to 'client/src')
-rw-r--r--client/src/app/core/plugins/plugin.service.ts36
1 files changed, 20 insertions, 16 deletions
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts
index 714abd82d..cca779177 100644
--- a/client/src/app/core/plugins/plugin.service.ts
+++ b/client/src/app/core/plugins/plugin.service.ts
@@ -1,4 +1,4 @@
1import { Injectable } from '@angular/core' 1import { Injectable, NgZone } from '@angular/core'
2import { Router } from '@angular/router' 2import { Router } from '@angular/router'
3import { ServerConfigPlugin } from '@shared/models' 3import { ServerConfigPlugin } from '@shared/models'
4import { ServerService } from '@app/core/server/server.service' 4import { ServerService } from '@app/core/server/server.service'
@@ -11,7 +11,6 @@ import { getHookType, internalRunHook } from '@shared/core-utils/plugins/hooks'
11import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model' 11import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plugins/client-hook.model'
12import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' 12import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type'
13import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' 13import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model'
14import { PeerTubePlugin } from '@shared/models/plugins/peertube-plugin.model'
15import { HttpClient } from '@angular/common/http' 14import { HttpClient } from '@angular/common/http'
16import { RestExtractor } from '@app/shared/rest' 15import { RestExtractor } from '@app/shared/rest'
17import { PluginType } from '@shared/models/plugins/plugin.type' 16import { PluginType } from '@shared/models/plugins/plugin.type'
@@ -52,6 +51,7 @@ export class PluginService implements ClientHook {
52 constructor ( 51 constructor (
53 private router: Router, 52 private router: Router,
54 private server: ServerService, 53 private server: ServerService,
54 private zone: NgZone,
55 private authHttp: HttpClient, 55 private authHttp: HttpClient,
56 private restExtractor: RestExtractor 56 private restExtractor: RestExtractor
57 ) { 57 ) {
@@ -157,20 +157,22 @@ export class PluginService implements ClientHook {
157 } 157 }
158 } 158 }
159 159
160 async runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> { 160 runHook <T> (hookName: ClientHookName, result?: T, params?: any): Promise<T> {
161 if (!this.hooks[hookName]) return Promise.resolve(result) 161 return this.zone.runOutsideAngular(async () => {
162 if (!this.hooks[ hookName ]) return result
162 163
163 const hookType = getHookType(hookName) 164 const hookType = getHookType(hookName)
164 165
165 for (const hook of this.hooks[hookName]) { 166 for (const hook of this.hooks[ hookName ]) {
166 console.log('Running hook %s of plugin %s.', hookName, hook.plugin.name) 167 console.log('Running hook %s of plugin %s.', hookName, hook.plugin.name)
167 168
168 result = await internalRunHook(hook.handler, hookType, result, params, err => { 169 result = await internalRunHook(hook.handler, hookType, result, params, err => {
169 console.error('Cannot run hook %s of script %s of plugin %s.', hookName, hook.clientScript.script, hook.plugin.name, err) 170 console.error('Cannot run hook %s of script %s of plugin %s.', hookName, hook.clientScript.script, hook.plugin.name, err)
170 }) 171 })
171 } 172 }
172 173
173 return result 174 return result
175 })
174 } 176 }
175 177
176 nameToNpmName (name: string, type: PluginType) { 178 nameToNpmName (name: string, type: PluginType) {
@@ -211,10 +213,12 @@ export class PluginService implements ClientHook {
211 213
212 console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name) 214 console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name)
213 215
214 return import(/* webpackIgnore: true */ clientScript.script) 216 return this.zone.runOutsideAngular(() => {
215 .then((script: ClientScriptModule) => script.register({ registerHook, peertubeHelpers })) 217 return import(/* webpackIgnore: true */ clientScript.script)
216 .then(() => this.sortHooksByPriority()) 218 .then((script: ClientScriptModule) => script.register({ registerHook, peertubeHelpers }))
217 .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err)) 219 .then(() => this.sortHooksByPriority())
220 .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err))
221 })
218 } 222 }
219 223
220 private buildScopeStruct () { 224 private buildScopeStruct () {