Skip to content

Commit

Permalink
🐛 Fix: pluginLoader can't get the full plugin list
Browse files Browse the repository at this point in the history
ISSUES CLOSED: #60
  • Loading branch information
Molunerfinn committed Dec 19, 2020
1 parent 233a6ca commit 83535b9
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 5 deletions.
21 changes: 18 additions & 3 deletions src/lib/PluginLoader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,15 @@ import fs from 'fs-extra'
import path from 'path'
import resolve from 'resolve'

/**
* Local plugin loader, file system is required
*/
class PluginLoader {
ctx: PicGo
list: string[]
private list: string[] = []
private readonly fullList: Set<string> = new Set()
constructor (ctx: PicGo) {
this.ctx = ctx
this.list = []
this.init()
}

Expand Down Expand Up @@ -57,6 +60,7 @@ class PluginLoader {
}

registerPlugin (name: string): void {
this.fullList.add(name)
if (this.ctx.getConfig(`picgoPlugins.${name}`) === true || (this.ctx.getConfig(`picgoPlugins.${name}`) === undefined)) {
try {
this.list.push(name)
Expand All @@ -70,6 +74,7 @@ class PluginLoader {
)
} catch (e) {
this.list = this.list.filter((item: string) => item !== name)
this.fullList.delete(name)
this.ctx.log.error(e)
this.ctx.emit('notification', {
title: `Plugin ${name} Load Error`,
Expand All @@ -81,6 +86,7 @@ class PluginLoader {

unregisterPlugin (name: string): void {
this.list = this.list.filter((item: string) => item !== name)
this.fullList.delete(name)
this.ctx.setCurrentPluginName(name)
this.ctx.helper.uploader.unregister(name)
this.ctx.helper.transformer.unregister(name)
Expand All @@ -97,9 +103,18 @@ class PluginLoader {
return require(pluginDir + name)(this.ctx)
}

// get plugin name list
/**
* Get the list of enabled plugins
*/
getList (): string[] {
return this.list
}

/**
* Get the full list of plugins, whether it is enabled or not
*/
getFullList (): string[] {
return [...this.fullList]
}
}
export default PluginLoader
2 changes: 1 addition & 1 deletion src/plugins/commander/setting.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ const setting = {
{
type: 'list',
name: 'plugin',
choices: ctx.pluginLoader.getList(),
choices: ctx.pluginLoader.getFullList(),
message: 'Choose a plugin'
}
]
Expand Down
2 changes: 1 addition & 1 deletion src/plugins/commander/use.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ const use: IPlugin = {
type: 'checkbox',
name: 'plugins',
message: 'Use plugins',
choices: ctx.pluginLoader.getList(),
choices: ctx.pluginLoader.getFullList(),
default: Object.keys(ctx.getConfig('picgoPlugins')).filter((item: string) => ctx.getConfig(`picgoPlugins.${item}`))
}
}
Expand Down

0 comments on commit 83535b9

Please sign in to comment.