diff options
Diffstat (limited to 'client')
-rw-r--r-- | client/src/app/core/plugins/hooks.service.ts | 18 | ||||
-rw-r--r-- | client/src/app/core/plugins/plugin.service.ts | 6 | ||||
-rw-r--r-- | client/src/types/register-client-option.model.ts | 3 |
3 files changed, 26 insertions, 1 deletions
diff --git a/client/src/app/core/plugins/hooks.service.ts b/client/src/app/core/plugins/hooks.service.ts index ec47aa48c..ddde198d2 100644 --- a/client/src/app/core/plugins/hooks.service.ts +++ b/client/src/app/core/plugins/hooks.service.ts | |||
@@ -3,13 +3,29 @@ import { mergeMap, switchMap } from 'rxjs/operators' | |||
3 | import { Injectable } from '@angular/core' | 3 | import { Injectable } from '@angular/core' |
4 | import { PluginService } from '@app/core/plugins/plugin.service' | 4 | import { PluginService } from '@app/core/plugins/plugin.service' |
5 | import { ClientActionHookName, ClientFilterHookName, PluginClientScope } from '@shared/models' | 5 | import { ClientActionHookName, ClientFilterHookName, PluginClientScope } from '@shared/models' |
6 | import { AuthService, AuthStatus } from '../auth' | ||
6 | 7 | ||
7 | type RawFunction<U, T> = (params: U) => T | 8 | type RawFunction<U, T> = (params: U) => T |
8 | type ObservableFunction<U, T> = RawFunction<U, Observable<T>> | 9 | type ObservableFunction<U, T> = RawFunction<U, Observable<T>> |
9 | 10 | ||
10 | @Injectable() | 11 | @Injectable() |
11 | export class HooksService { | 12 | export class HooksService { |
12 | constructor (private pluginService: PluginService) { } | 13 | constructor ( |
14 | private authService: AuthService, | ||
15 | private pluginService: PluginService | ||
16 | ) { | ||
17 | // Run auth hooks | ||
18 | this.authService.userInformationLoaded | ||
19 | .subscribe(() => this.runAction('action:auth-user.information-loaded', 'common', { user: this.authService.getUser() })) | ||
20 | |||
21 | this.authService.loginChangedSource.subscribe(obj => { | ||
22 | if (obj === AuthStatus.LoggedIn) { | ||
23 | this.runAction('action:auth-user.logged-in', 'common') | ||
24 | } else if (obj === AuthStatus.LoggedOut) { | ||
25 | this.runAction('action:auth-user.logged-out', 'common') | ||
26 | } | ||
27 | }) | ||
28 | } | ||
13 | 29 | ||
14 | wrapObsFun | 30 | wrapObsFun |
15 | <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName> | 31 | <P, R, H1 extends ClientFilterHookName, H2 extends ClientFilterHookName> |
diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index b755fda2c..54dba5e17 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts | |||
@@ -235,6 +235,12 @@ export class PluginService implements ClientHook { | |||
235 | .toPromise() | 235 | .toPromise() |
236 | }, | 236 | }, |
237 | 237 | ||
238 | getServerConfig: () => { | ||
239 | return this.server.getConfig() | ||
240 | .pipe(catchError(res => this.restExtractor.handleError(res))) | ||
241 | .toPromise() | ||
242 | }, | ||
243 | |||
238 | isLoggedIn: () => { | 244 | isLoggedIn: () => { |
239 | return this.authService.isLoggedIn() | 245 | return this.authService.isLoggedIn() |
240 | }, | 246 | }, |
diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts index e3c6d803d..7e5356a2b 100644 --- a/client/src/types/register-client-option.model.ts +++ b/client/src/types/register-client-option.model.ts | |||
@@ -1,5 +1,6 @@ | |||
1 | import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model' | 1 | import { RegisterClientFormFieldOptions, RegisterClientVideoFieldOptions } from '@shared/models/plugins/register-client-form-field.model' |
2 | import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' | 2 | import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' |
3 | import { ServerConfig } from '@shared/models/server' | ||
3 | 4 | ||
4 | export type RegisterClientOptions = { | 5 | export type RegisterClientOptions = { |
5 | registerHook: (options: RegisterClientHookOptions) => void | 6 | registerHook: (options: RegisterClientHookOptions) => void |
@@ -16,6 +17,8 @@ export type RegisterClientHelpers = { | |||
16 | 17 | ||
17 | getSettings: () => Promise<{ [ name: string ]: string }> | 18 | getSettings: () => Promise<{ [ name: string ]: string }> |
18 | 19 | ||
20 | getServerConfig: () => Promise<ServerConfig> | ||
21 | |||
19 | notifier: { | 22 | notifier: { |
20 | info: (text: string, title?: string, timeout?: number) => void, | 23 | info: (text: string, title?: string, timeout?: number) => void, |
21 | error: (text: string, title?: string, timeout?: number) => void, | 24 | error: (text: string, title?: string, timeout?: number) => void, |