@@ -144,9 +144,12 @@ public PluginDef UpdatePluginStatus(IServiceProvider services, string id, bool e
144144 var config = db . GetPluginConfig ( ) ;
145145 if ( enable )
146146 {
147- if ( ! config . EnabledPlugins . Exists ( x => x == id ) )
147+ var dependentPlugins = new HashSet < string > ( ) ;
148+ FindPluginDependency ( id , enable , ref dependentPlugins ) ;
149+ var missingPlugins = dependentPlugins . Where ( x => ! config . EnabledPlugins . Contains ( x ) ) . ToList ( ) ;
150+ if ( ! missingPlugins . IsNullOrEmpty ( ) )
148151 {
149- config . EnabledPlugins . Add ( id ) ;
152+ config . EnabledPlugins . AddRange ( missingPlugins ) ;
150153 db . SavePluginConfig ( config ) ;
151154 }
152155
@@ -186,6 +189,36 @@ public PluginDef UpdatePluginStatus(IServiceProvider services, string id, bool e
186189 return plugin ;
187190 }
188191
192+ private void FindPluginDependency ( string pluginId , bool enabled , ref HashSet < string > dependentPlugins )
193+ {
194+ var pluginDef = _plugins . FirstOrDefault ( x => x . Id == pluginId ) ;
195+ if ( pluginDef == null ) return ;
196+
197+ if ( ! pluginDef . IsCore )
198+ {
199+ pluginDef . Enabled = enabled ;
200+ dependentPlugins . Add ( pluginId ) ;
201+ }
202+
203+ var foundPlugin = _modules . FirstOrDefault ( x => x . Id == pluginId ) ;
204+ if ( foundPlugin == null ) return ;
205+
206+ var attr = foundPlugin . GetType ( ) . GetCustomAttribute < PluginDependencyAttribute > ( ) ;
207+ if ( attr != null && ! attr . PluginNames . IsNullOrEmpty ( ) )
208+ {
209+ foreach ( var name in attr . PluginNames )
210+ {
211+ var plugins = _plugins . Where ( x => x . Assembly == name ) . ToList ( ) ;
212+ if ( plugins . IsNullOrEmpty ( ) ) return ;
213+
214+ foreach ( var plugin in plugins )
215+ {
216+ FindPluginDependency ( plugin . Id , enabled , ref dependentPlugins ) ;
217+ }
218+ }
219+ }
220+ }
221+
189222 public string GetSummaryComment ( Type member )
190223 {
191224 string summary = string . Empty ;
0 commit comments