Skip to content

Commit

Permalink
Try to disable a ByDependencyOnly feature only if currently enabled (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeAlhayek authored Sep 2, 2022
1 parent 69e2d47 commit 149ab6c
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,11 @@ public ShellDescriptorFeaturesManager(
{
var featureEventHandlers = ShellScope.Services.GetServices<IFeatureEventHandler>();

var enabledFeatureIds = _extensionManager.GetFeatures()
var enabledFeatures = _extensionManager.GetFeatures()
.Where(f => shellDescriptor.Features.Any(sf => sf.Id == f.Id))
.ToArray();

var enabledFeatureIds = enabledFeatures
.Select(f => f.Id)
.ToHashSet();

Expand All @@ -47,15 +50,15 @@ public ShellDescriptorFeaturesManager(

var alwaysEnabledIds = _alwaysEnabledFeatures.Select(sf => sf.Id).ToArray();

var onDemandFeaturesToDisable = _extensionManager.GetFeatures()
var byDependencyOnlyFeaturesToDisable = enabledFeatures
.Where(f => f.EnabledByDependencyOnly);

var allFeaturesToDisable = featuresToDisable
.Where(f => !alwaysEnabledIds.Contains(f.Id))
.SelectMany(feature => GetFeaturesToDisable(feature, enabledFeatureIds, force))
// Always attempt to disable EnabledByDependencyOnly features
// to ensure we auto disable any feature that is no longer needed
.Union(onDemandFeaturesToDisable)
// Always attempt to disable 'EnabledByDependencyOnly' features
// to ensure we auto disable any feature that is no longer needed.
.Union(byDependencyOnlyFeaturesToDisable)
.Distinct()
.Reverse()
.ToList();
Expand Down

0 comments on commit 149ab6c

Please sign in to comment.