Skip to content

Commit e19bb6e

Browse files
committed
✨ Feature: update picgo.use
1 parent ffe914f commit e19bb6e

File tree

2 files changed

+14
-4
lines changed

2 files changed

+14
-4
lines changed

src/core/PicGo.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,9 +108,19 @@ export class PicGo extends EventEmitter implements IPicGo {
108108
}
109109
}
110110

111-
use (plugin: IPicGoPlugin): IPicGoPluginInterface {
112-
const pluginInstance = plugin(this)
113-
return pluginInstance
111+
/**
112+
* easily mannually load a plugin
113+
* if provide plugin name, will register plugin by name
114+
* or just instantiate a plugin
115+
*/
116+
use (plugin: IPicGoPlugin, name?: string): IPicGoPluginInterface {
117+
if (name) {
118+
this.pluginLoader.registerPlugin(name, plugin)
119+
return this.pluginLoader.getPlugin(name)!
120+
} else {
121+
const pluginInstance = plugin(this)
122+
return pluginInstance
123+
}
114124
}
115125

116126
registerCommands (): void {

src/lib/PluginLoader.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ export class PluginLoader implements IPluginLoader {
9090
setCurrentPluginName(name)
9191
const pluginInterface = plugin(this.ctx)
9292
this.pluginMap.set(name, pluginInterface)
93-
plugin(this.ctx).register(this.ctx)
93+
pluginInterface.register(this.ctx)
9494
}
9595
} catch (e) {
9696
this.pluginMap.delete(name)

0 commit comments

Comments
 (0)