From cbc116c79d0783fa7e280b15758fd19fe2a06d67 Mon Sep 17 00:00:00 2001
From: kkz <zhaoshuang@uniontech.com>
Date: Fri, 21 Jul 2023 11:18:50 +0800
Subject: [PATCH] fix: fix the issue enabling module repeatly

---
 loader/loader.go | 10 ++++++++++
 loader/module.go |  7 ++++---
 2 files changed, 14 insertions(+), 3 deletions(-)

diff --git a/loader/loader.go b/loader/loader.go
index d218ab6..b34e9e8 100644
--- a/loader/loader.go
+++ b/loader/loader.go
@@ -164,6 +164,11 @@ func (l *Loader) EnableModules(enablingModules []string, disableModules []string
 
 		go func() {
 			l.log.Info("enable module", name)
+			if module.IsEnable() == true {
+				l.log.Infof("module %s has been enabled", name)
+				return;
+			}
+
 			startTime := time.Now()
 
 			// wait for its dependency
@@ -185,6 +190,11 @@ func (l *Loader) EnableModules(enablingModules []string, disableModules []string
 
 	for _, n := range nodes {
 		m := l.modules[n.ID]
+
+		if m.IsEnable() == true {
+			continue;
+		}
+
 		m.WaitEnable()
 	}
 
diff --git a/loader/module.go b/loader/module.go
index 325a572..b4320db 100644
--- a/loader/module.go
+++ b/loader/module.go
@@ -54,9 +54,10 @@ type ModuleBase struct {
 
 func NewModuleBase(name string, impl ModuleImpl, logger *log.Logger) *ModuleBase {
 	m := &ModuleBase{
-		name: name,
-		impl: impl,
-		log:  logger,
+		name:   name,
+		impl:   impl,
+		log:    logger,
+		enabled:false,
 	}
 
 	// 此为等待「enabled」的 WaitGroup，故在 enable 完成之前，需要一直为等待状态。
-- 
2.27.0

