diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index da5114048..b9d55a7e4 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -12,7 +12,7 @@ import { ClientHook, ClientHookName, clientHookObject } from '@shared/models/plu import { PluginClientScope } from '@shared/models/plugins/plugin-client-scope.type' import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' import { HttpClient } from '@angular/common/http' -import { AuthService } from '@app/core/auth' +import { AuthService, Notifier } from '@app/core' import { RestExtractor } from '@app/shared/rest' import { PluginType } from '@shared/models/plugins/plugin.type' import { PublicServerSetting } from '@shared/models/plugins/public-server.setting' @@ -60,6 +60,7 @@ export class PluginService implements ClientHook { constructor ( private router: Router, private authService: AuthService, + private notifier: Notifier, private server: ServerService, private zone: NgZone, private authHttp: HttpClient, @@ -272,6 +273,8 @@ export class PluginService implements ClientHook { return this.authService.isLoggedIn() }, + notifier: this.notifier, + translate: (value: string) => { return this.translationsObservable .pipe(map(allTranslations => allTranslations[npmName])) diff --git a/client/src/types/register-client-option.model.ts b/client/src/types/register-client-option.model.ts index 638b08653..1faf13c42 100644 --- a/client/src/types/register-client-option.model.ts +++ b/client/src/types/register-client-option.model.ts @@ -1,4 +1,5 @@ import { RegisterClientHookOptions } from '@shared/models/plugins/register-client-hook.model' +import { Notifier } from '@app/core' export type RegisterClientOptions = { registerHook: (options: RegisterClientHookOptions) => void @@ -13,5 +14,7 @@ export type RegisterClientHelpers = { getSettings: () => Promise<{ [ name: string ]: string }> + notifier: Notifier + translate: (toTranslate: string) => Promise } diff --git a/support/doc/plugins/guide.md b/support/doc/plugins/guide.md index bdc9d2ad8..5251ce48a 100644 --- a/support/doc/plugins/guide.md +++ b/support/doc/plugins/guide.md @@ -197,7 +197,7 @@ The `ping` route can be accessed using: ### Client helpers (themes & plugins) -### Plugin static route +#### Plugin static route To get your plugin static route: @@ -206,6 +206,16 @@ const baseStaticUrl = peertubeHelpers.getBaseStaticRoute() const imageUrl = baseStaticUrl + '/images/chocobo.png' ``` +#### Notifier + +To notify the user with the PeerTube ToastModule: + +```js +const { notifier } = peertubeHelpers +notifier.success('Success message content.') +notifier.error('Error message content.') +``` + #### Translate You can translate some strings of your plugin (PeerTube will use your `translations` object of your `package.json` file):