2021-03-31 06:15:40 -04:00
|
|
|
/**
|
2024-05-10 09:09:14 -04:00
|
|
|
* SPDX-FileCopyrightText: 2019 Nextcloud GmbH and Nextcloud contributors
|
|
|
|
|
* SPDX-License-Identifier: AGPL-3.0-or-later
|
2019-01-31 12:30:52 -05:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
export default {
|
|
|
|
|
|
|
|
|
|
/**
|
2022-01-10 08:06:28 -05:00
|
|
|
* @type {Array.<OC.Plugin>}
|
2019-01-31 12:30:52 -05:00
|
|
|
*/
|
|
|
|
|
_plugins: {},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Register plugin
|
|
|
|
|
*
|
2021-12-02 12:32:57 -05:00
|
|
|
* @param {string} targetName app name / class name to hook into
|
2019-09-25 12:19:42 -04:00
|
|
|
* @param {OC.Plugin} plugin plugin
|
2019-01-31 12:30:52 -05:00
|
|
|
*/
|
2020-07-31 03:26:43 -04:00
|
|
|
register(targetName, plugin) {
|
2019-11-13 07:05:10 -05:00
|
|
|
let plugins = this._plugins[targetName]
|
2019-01-31 12:30:52 -05:00
|
|
|
if (!plugins) {
|
2019-09-25 12:19:42 -04:00
|
|
|
plugins = this._plugins[targetName] = []
|
2019-01-31 12:30:52 -05:00
|
|
|
}
|
2019-09-25 12:19:42 -04:00
|
|
|
plugins.push(plugin)
|
2019-01-31 12:30:52 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Returns all plugin registered to the given target
|
|
|
|
|
* name / app name / class name.
|
|
|
|
|
*
|
2021-12-02 12:32:57 -05:00
|
|
|
* @param {string} targetName app name / class name to hook into
|
|
|
|
|
* @return {Array.<OC.Plugin>} array of plugins
|
2019-01-31 12:30:52 -05:00
|
|
|
*/
|
2020-07-31 03:26:43 -04:00
|
|
|
getPlugins(targetName) {
|
2019-09-25 12:19:42 -04:00
|
|
|
return this._plugins[targetName] || []
|
2019-01-31 12:30:52 -05:00
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call attach() on all plugins registered to the given target name.
|
|
|
|
|
*
|
2021-12-02 12:32:57 -05:00
|
|
|
* @param {string} targetName app name / class name
|
|
|
|
|
* @param {object} targetObject to be extended
|
|
|
|
|
* @param {object} [options] options
|
2019-01-31 12:30:52 -05:00
|
|
|
*/
|
2020-07-31 03:26:43 -04:00
|
|
|
attach(targetName, targetObject, options) {
|
2019-11-13 07:05:10 -05:00
|
|
|
const plugins = this.getPlugins(targetName)
|
|
|
|
|
for (let i = 0; i < plugins.length; i++) {
|
2019-01-31 12:30:52 -05:00
|
|
|
if (plugins[i].attach) {
|
2019-09-25 12:19:42 -04:00
|
|
|
plugins[i].attach(targetObject, options)
|
2019-01-31 12:30:52 -05:00
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* Call detach() on all plugins registered to the given target name.
|
|
|
|
|
*
|
2021-12-02 12:32:57 -05:00
|
|
|
* @param {string} targetName app name / class name
|
|
|
|
|
* @param {object} targetObject to be extended
|
|
|
|
|
* @param {object} [options] options
|
2019-01-31 12:30:52 -05:00
|
|
|
*/
|
2020-07-31 03:26:43 -04:00
|
|
|
detach(targetName, targetObject, options) {
|
2019-11-13 07:05:10 -05:00
|
|
|
const plugins = this.getPlugins(targetName)
|
|
|
|
|
for (let i = 0; i < plugins.length; i++) {
|
2019-01-31 12:30:52 -05:00
|
|
|
if (plugins[i].detach) {
|
2019-09-25 12:19:42 -04:00
|
|
|
plugins[i].detach(targetObject, options)
|
2019-01-31 12:30:52 -05:00
|
|
|
}
|
|
|
|
|
}
|
2019-11-13 07:05:10 -05:00
|
|
|
},
|
2019-01-31 12:30:52 -05:00
|
|
|
|
2019-09-25 12:19:42 -04:00
|
|
|
}
|