diff options
Diffstat (limited to 'client/src/root-helpers/plugins.ts')
-rw-r--r-- | client/src/root-helpers/plugins.ts | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/client/src/root-helpers/plugins.ts b/client/src/root-helpers/plugins.ts index 4bc2c8eb2..5344c0468 100644 --- a/client/src/root-helpers/plugins.ts +++ b/client/src/root-helpers/plugins.ts | |||
@@ -7,7 +7,8 @@ import { | |||
7 | ClientScript, | 7 | ClientScript, |
8 | PluginType, | 8 | PluginType, |
9 | RegisterClientHookOptions, | 9 | RegisterClientHookOptions, |
10 | ServerConfigPlugin | 10 | ServerConfigPlugin, |
11 | RegisterClientSettingsScript | ||
11 | } from '../../../shared/models' | 12 | } from '../../../shared/models' |
12 | import { ClientScript as ClientScriptModule } from '../types/client-script.model' | 13 | import { ClientScript as ClientScriptModule } from '../types/client-script.model' |
13 | import { importModule } from './utils' | 14 | import { importModule } from './utils' |
@@ -54,8 +55,9 @@ function loadPlugin (options: { | |||
54 | pluginInfo: PluginInfo | 55 | pluginInfo: PluginInfo |
55 | peertubeHelpersFactory: (pluginInfo: PluginInfo) => RegisterClientHelpers | 56 | peertubeHelpersFactory: (pluginInfo: PluginInfo) => RegisterClientHelpers |
56 | formFields?: FormFields | 57 | formFields?: FormFields |
58 | onSettingsScripts?: (options: RegisterClientSettingsScript) => void | ||
57 | }) { | 59 | }) { |
58 | const { hooks, pluginInfo, peertubeHelpersFactory, formFields } = options | 60 | const { hooks, pluginInfo, peertubeHelpersFactory, formFields, onSettingsScripts } = options |
59 | const { plugin, clientScript } = pluginInfo | 61 | const { plugin, clientScript } = pluginInfo |
60 | 62 | ||
61 | const registerHook = (options: RegisterClientHookOptions) => { | 63 | const registerHook = (options: RegisterClientHookOptions) => { |
@@ -86,12 +88,20 @@ function loadPlugin (options: { | |||
86 | }) | 88 | }) |
87 | } | 89 | } |
88 | 90 | ||
91 | const registerSettingsScript = (options: RegisterClientSettingsScript) => { | ||
92 | if (!onSettingsScripts) { | ||
93 | throw new Error('Registering settings script is not supported') | ||
94 | } | ||
95 | |||
96 | return onSettingsScripts(options) | ||
97 | } | ||
98 | |||
89 | const peertubeHelpers = peertubeHelpersFactory(pluginInfo) | 99 | const peertubeHelpers = peertubeHelpersFactory(pluginInfo) |
90 | 100 | ||
91 | console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name) | 101 | console.log('Loading script %s of plugin %s.', clientScript.script, plugin.name) |
92 | 102 | ||
93 | return importModule(clientScript.script) | 103 | return importModule(clientScript.script) |
94 | .then((script: ClientScriptModule) => script.register({ registerHook, registerVideoField, peertubeHelpers })) | 104 | .then((script: ClientScriptModule) => script.register({ registerHook, registerVideoField, registerSettingsScript, peertubeHelpers })) |
95 | .then(() => sortHooksByPriority(hooks)) | 105 | .then(() => sortHooksByPriority(hooks)) |
96 | .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err)) | 106 | .catch(err => console.error('Cannot import or register plugin %s.', pluginInfo.plugin.name, err)) |
97 | } | 107 | } |