Skip to content

Commit

Permalink
✨ Feature: update picgo.use
Browse files Browse the repository at this point in the history
  • Loading branch information
Molunerfinn committed Nov 12, 2022
1 parent ffe914f commit e19bb6e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 4 deletions.
16 changes: 13 additions & 3 deletions src/core/PicGo.ts
Original file line number Diff line number Diff line change
Expand Up @@ -108,9 +108,19 @@ export class PicGo extends EventEmitter implements IPicGo {
}
}

use (plugin: IPicGoPlugin): IPicGoPluginInterface {
const pluginInstance = plugin(this)
return pluginInstance
/**
* easily mannually load a plugin
* if provide plugin name, will register plugin by name
* or just instantiate a plugin
*/
use (plugin: IPicGoPlugin, name?: string): IPicGoPluginInterface {
if (name) {
this.pluginLoader.registerPlugin(name, plugin)
return this.pluginLoader.getPlugin(name)!
} else {
const pluginInstance = plugin(this)
return pluginInstance
}
}

registerCommands (): void {
Expand Down
2 changes: 1 addition & 1 deletion src/lib/PluginLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ export class PluginLoader implements IPluginLoader {
setCurrentPluginName(name)
const pluginInterface = plugin(this.ctx)
this.pluginMap.set(name, pluginInterface)
plugin(this.ctx).register(this.ctx)
pluginInterface.register(this.ctx)
}
} catch (e) {
this.pluginMap.delete(name)
Expand Down

0 comments on commit e19bb6e

Please sign in to comment.