mirror of
https://github.com/zhw2590582/ArtPlayer.git
synced 2026-10-16 09:36:16 -08:00
Update version to 5.1.1 and add support for synchronous and asynchronous plugin functions
This commit is contained in:
1 parent
a1063c20ed
commit
3aa30de771
11 files changed
+44
-24
No files matched your search
@@ -37,9 +37,17 @@ export default class Plugins {
|
||||
}
|
||||
}
|
||||
|
||||
async add(plugin) {
|
||||
add(plugin) {
|
||||
this.id += 1;
|
||||
const result = await plugin.call(this.art, this.art);
|
||||
const result = plugin.call(this.art, this.art);
|
||||
if (result instanceof Promise) {
|
||||
return result.then((res) => this.next(plugin, res));
|
||||
} else {
|
||||
return this.next(plugin, result);
|
||||
}
|
||||
}
|
||||
|
||||
next(plugin, result) {
|
||||
const pluginName = (result && result.name) || plugin.name || `plugin${this.id}`;
|
||||
errorHandle(!has(this, pluginName), `Cannot add a plugin that already has the same name: ${pluginName}`);
|
||||
def(this, pluginName, {
|
||||
|
||||
Reference in new issue
Block a user