diff options
author | Joram Wilander <jwawilander@gmail.com> | 2017-10-25 08:17:17 -0400 |
---|---|---|
committer | GitHub <noreply@github.com> | 2017-10-25 08:17:17 -0400 |
commit | 16b845c0d77535ea306339f7a8bd22fc72f8a3c5 (patch) | |
tree | e768b8d1ca5cc3f2e55207ea73c5954b37f708ed /plugin | |
parent | 9c0575ce6ef662c18ad7eb91bf6084c6fac1b7ae (diff) | |
download | chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.gz chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.tar.bz2 chat-16b845c0d77535ea306339f7a8bd22fc72f8a3c5.zip |
Differentiate between installed and activated states for plugins (#7706)
Diffstat (limited to 'plugin')
-rw-r--r-- | plugin/pluginenv/environment.go | 14 | ||||
-rw-r--r-- | plugin/pluginenv/environment_test.go | 2 |
2 files changed, 16 insertions, 0 deletions
diff --git a/plugin/pluginenv/environment.go b/plugin/pluginenv/environment.go index 805b33e66..37bd1a482 100644 --- a/plugin/pluginenv/environment.go +++ b/plugin/pluginenv/environment.go @@ -89,6 +89,20 @@ func (env *Environment) ActivePluginIds() (ids []string) { return } +// Returns true if the plugin is active, false otherwise. +func (env *Environment) IsPluginActive(pluginId string) bool { + env.mutex.RLock() + defer env.mutex.RUnlock() + + for id := range env.activePlugins { + if id == pluginId { + return true + } + } + + return false +} + // Activates the plugin with the given id. func (env *Environment) ActivatePlugin(id string) error { env.mutex.Lock() diff --git a/plugin/pluginenv/environment_test.go b/plugin/pluginenv/environment_test.go index c11644b35..e4f63cf70 100644 --- a/plugin/pluginenv/environment_test.go +++ b/plugin/pluginenv/environment_test.go @@ -152,10 +152,12 @@ func TestEnvironment(t *testing.T) { activePlugins = env.ActivePlugins() assert.Len(t, activePlugins, 1) assert.Error(t, env.ActivatePlugin("foo")) + assert.True(t, env.IsPluginActive("foo")) hooks.On("OnDeactivate").Return(nil) assert.NoError(t, env.DeactivatePlugin("foo")) assert.Error(t, env.DeactivatePlugin("foo")) + assert.False(t, env.IsPluginActive("foo")) assert.NoError(t, env.ActivatePlugin("foo")) assert.Equal(t, env.ActivePluginIds(), []string{"foo"}) |