X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=client%2Fsrc%2Fapp%2Fcore%2Fplugins%2Fplugin.service.ts;h=3ed23160dfb5d9366108ed263f5fe85a22e25b3c;hb=8c7725dc3c01a73bf56a48c8b192d144bfdc3ffe;hp=52ba4215ab380bfd39444ebc45c1b338d773c950;hpb=f92bb405d48af737636fec1025e19f27d7044158;p=github%2FChocobozzz%2FPeerTube.git diff --git a/client/src/app/core/plugins/plugin.service.ts b/client/src/app/core/plugins/plugin.service.ts index 52ba4215a..3ed23160d 100644 --- a/client/src/app/core/plugins/plugin.service.ts +++ b/client/src/app/core/plugins/plugin.service.ts @@ -12,13 +12,17 @@ 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 { Notifier } from '@app/core/notification' import { RestExtractor } from '@app/shared/rest' +import { MarkdownService } from '@app/shared/renderer' import { PluginType } from '@shared/models/plugins/plugin.type' import { PublicServerSetting } from '@shared/models/plugins/public-server.setting' import { getDevLocale, isOnDevLocale } from '@app/shared/i18n/i18n-utils' import { RegisterClientHelpers } from '../../../types/register-client-option.model' import { PluginTranslation } from '@shared/models/plugins/plugin-translation.model' import { importModule } from '@app/shared/misc/utils' +import { CustomModalComponent } from '@app/modal/custom-modal.component' interface HookStructValue extends RegisterClientHookOptions { plugin: ServerConfigPlugin @@ -48,6 +52,8 @@ export class PluginService implements ClientHook { translationsObservable: Observable + customModal: CustomModalComponent + private plugins: ServerConfigPlugin[] = [] private scopes: { [ scopeName: string ]: PluginInfo[] } = {} private loadedScripts: { [ script: string ]: boolean } = {} @@ -58,6 +64,9 @@ export class PluginService implements ClientHook { constructor ( private router: Router, + private authService: AuthService, + private notifier: Notifier, + private markdownRenderer: MarkdownService, private server: ServerService, private zone: NgZone, private authHttp: HttpClient, @@ -68,9 +77,9 @@ export class PluginService implements ClientHook { } initializePlugins () { - this.server.configLoaded - .subscribe(() => { - this.plugins = this.server.getConfig().plugin.registered + this.server.getConfig() + .subscribe(config => { + this.plugins = config.plugin.registered this.buildScopeStruct() @@ -78,6 +87,10 @@ export class PluginService implements ClientHook { }) } + initializeCustomModal (customModal: CustomModalComponent) { + this.customModal = customModal + } + ensurePluginsAreBuilt () { return this.pluginsBuilt.asObservable() .pipe(first(), shareReplay()) @@ -266,6 +279,36 @@ export class PluginService implements ClientHook { .toPromise() }, + isLoggedIn: () => { + return this.authService.isLoggedIn() + }, + + notifier: { + info: (text: string, title?: string, timeout?: number) => this.notifier.info(text, title, timeout), + error: (text: string, title?: string, timeout?: number) => this.notifier.error(text, title, timeout), + success: (text: string, title?: string, timeout?: number) => this.notifier.success(text, title, timeout) + }, + + showModal: (input: { + title: string, + content: string, + close?: boolean, + cancel?: { value: string, action?: () => void }, + confirm?: { value: string, action?: () => void } + }) => { + this.customModal.show(input) + }, + + markdownRenderer: { + textMarkdownToHTML: (textMarkdown: string) => { + return this.markdownRenderer.textMarkdownToHTML(textMarkdown) + }, + + enhancedMarkdownToHTML: (enhancedMarkdown: string) => { + return this.markdownRenderer.enhancedMarkdownToHTML(enhancedMarkdown) + } + }, + translate: (value: string) => { return this.translationsObservable .pipe(map(allTranslations => allTranslations[npmName]))