X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Fplugins%2Fhooks.service.ts;h=29db75d89bea8b7d24ddb073d517cdb4bee4fc6f;hb=2c8380a46f34631e705b1564938343cacfa4b0bc;hp=ddde198d2ffb0fe2c7ec7ab0fd7023259a6ba36c;hpb=a786d8a08bf99f339bf16808f46e160404497ae2;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts index ddde198d2..29db75d89 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts @@ -2,6 +2,7 @@ import { from, Observable } from 'rxjs' import { mergeMap, switchMap } from 'rxjs/operators' import { Injectable } from '@angular/core' import { PluginService } from '@app/core/plugins/plugin.service' +import { logger } from '@root-helpers/logger' import { ClientActionHookName, ClientFilterHookName, PluginClientScope } from '@shared/models' import { AuthService, AuthStatus } from '../auth' @@ -27,9 +28,8 @@ export class HooksService { }) } - wrapObsFun - - (fun: ObservableFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { + wrapObsFun + (fun: ObservableFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { return from(this.pluginService.ensurePluginsAreLoaded(scope)) .pipe( mergeMap(() => this.wrapObjectWithoutScopeLoad(params, hookParamName)), @@ -38,9 +38,8 @@ export class HooksService { ) } - async wrapFun - - (fun: RawFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { + async wrapFun + (fun: RawFunction, params: P, scope: PluginClientScope, hookParamName: H1, hookResultName: H2) { await this.pluginService.ensurePluginsAreLoaded(scope) const newParams = await this.wrapObjectWithoutScopeLoad(params, hookParamName) @@ -50,9 +49,12 @@ export class HooksService { } runAction (hookName: U, scope: PluginClientScope, params?: T) { - this.pluginService.ensurePluginsAreLoaded(scope) + // Use setTimeout to give priority to Angular change detector + setTimeout(() => { + this.pluginService.ensurePluginsAreLoaded(scope) .then(() => this.pluginService.runHook(hookName, undefined, params)) - .catch((err: any) => console.error('Fatal hook error.', { err })) + .catch((err: any) => logger.error('Fatal hook error.', err)) + }) } async wrapObject (result: T, scope: PluginClientScope, hookName: U) {