fix: servers check error

Signed-off-by: MiaoWoo <admin@yumc.pw>
This commit is contained in:
MiaoWoo 2020-02-27 17:57:29 +08:00
parent 7b8e693a03
commit 15a75dffe2

View File

@ -160,10 +160,16 @@ export class PluginManagerImpl implements plugin.PluginManager {
} }
} }
private checkServers(servers: string[]) { private allowProcess(servers: string[]) {
if (!servers) { return true } // Not set servers allow
if (servers.indexOf(`!${this.serverType}`) != -1) { return false } if (!servers) return true
return servers?.indexOf(this.serverType) != -1 // include !type deny
let denyServers = servers.filter(svr => svr.startsWith("!"))
if (denyServers.length !== 0) {
return !denyServers.includes(`!${this.serverType}`)
} else {
return servers.includes(this.serverType)
}
} }
private createPlugin(file: string) { private createPlugin(file: string) {
@ -174,7 +180,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
private buildPlugins() { private buildPlugins() {
let pluginMetadatas = getPluginMetadatas() let pluginMetadatas = getPluginMetadatas()
for (const [_, metadata] of pluginMetadatas) { for (const [_, metadata] of pluginMetadatas) {
if (!this.checkServers(metadata.servers)) { continue } if (!this.allowProcess(metadata.servers)) { continue }
this.buildPlugin(metadata) this.buildPlugin(metadata)
} }
} }
@ -221,7 +227,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
let tabs = getPluginTabCompleterMetadata(pluginInstance) let tabs = getPluginTabCompleterMetadata(pluginInstance)
for (const [_, cmd] of cmds) { for (const [_, cmd] of cmds) {
let tab = tabs.get(cmd.name) let tab = tabs.get(cmd.name)
if (!this.checkServers(cmd.servers)) { continue } if (!this.allowProcess(cmd.servers)) { continue }
this.CommandManager.on(pluginInstance, cmd.name, { this.CommandManager.on(pluginInstance, cmd.name, {
cmd: pluginInstance[cmd.executor].bind(pluginInstance), cmd: pluginInstance[cmd.executor].bind(pluginInstance),
tab: tab ? pluginInstance[tab.executor].bind(pluginInstance) : undefined tab: tab ? pluginInstance[tab.executor].bind(pluginInstance) : undefined
@ -233,7 +239,7 @@ export class PluginManagerImpl implements plugin.PluginManager {
let events = getPluginListenerMetadata(pluginInstance) let events = getPluginListenerMetadata(pluginInstance)
for (const event of events) { for (const event of events) {
// ignore space listener // ignore space listener
if (!this.checkServers(event.servers)) { continue } if (!this.allowProcess(event.servers)) { continue }
// here must bind this to pluginInstance // here must bind this to pluginInstance
this.EventManager.listen(pluginInstance, event.name, pluginInstance[event.executor].bind(pluginInstance)) this.EventManager.listen(pluginInstance, event.name, pluginInstance[event.executor].bind(pluginInstance))
} }