2020-11-21 15:41:08 +00:00
|
|
|
|
|
|
|
export function DependencyLoad(dep: string): (...args: any[]) => void {
|
|
|
|
return (
|
|
|
|
target: any,
|
|
|
|
propertyKey: string,
|
|
|
|
descriptor: PropertyDescriptor,
|
|
|
|
) => {
|
|
|
|
const originalMethod = descriptor.value;
|
|
|
|
descriptor.value = function(...args: any[]): void {
|
|
|
|
const self = this as any;
|
|
|
|
self.stream.on(self.name, 'pluginLoaded', (plugin: any) => {
|
2020-11-28 13:34:34 +00:00
|
|
|
if (typeof plugin === 'string') {
|
|
|
|
return;
|
2020-11-21 15:41:08 +00:00
|
|
|
}
|
2020-11-28 13:34:34 +00:00
|
|
|
const nameof = plugin.manifest.name;
|
|
|
|
if (nameof !== dep) {
|
2020-11-21 15:41:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-28 13:34:34 +00:00
|
|
|
originalMethod.call(self, plugin);
|
2020-11-21 15:41:08 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
// Set the function to be autoexecuted when the plugin is initialized.
|
|
|
|
descriptor.value.prototype.__autoexec = 1;
|
|
|
|
return descriptor;
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function DependencyUnload(dep: string): (...args: any[]) => void {
|
|
|
|
return (
|
|
|
|
target: any,
|
|
|
|
propertyKey: string,
|
|
|
|
descriptor: PropertyDescriptor,
|
|
|
|
) => {
|
|
|
|
const originalMethod = descriptor.value;
|
|
|
|
descriptor.value = function(...args: any[]): void {
|
|
|
|
const self = this as any;
|
|
|
|
self.stream.on(self.name, 'pluginUnloaded', (plugin: any) => {
|
2020-11-28 13:34:34 +00:00
|
|
|
let nameof = plugin;
|
2020-11-21 15:41:08 +00:00
|
|
|
if (typeof plugin !== 'string') {
|
2020-11-28 13:34:34 +00:00
|
|
|
nameof = plugin.manifest.name;
|
2020-11-21 15:41:08 +00:00
|
|
|
}
|
2020-11-28 13:34:34 +00:00
|
|
|
if (nameof !== dep) {
|
2020-11-21 15:41:08 +00:00
|
|
|
return;
|
|
|
|
}
|
2020-11-28 13:34:34 +00:00
|
|
|
originalMethod.call(self, plugin);
|
2020-11-21 15:41:08 +00:00
|
|
|
});
|
|
|
|
};
|
|
|
|
descriptor.value.prototype.__autoexec = 1;
|
|
|
|
return descriptor;
|
|
|
|
};
|
|
|
|
}
|