Skip to content

Commit

Permalink
Disable Quickstart Playground after the experimental feature is turne…
Browse files Browse the repository at this point in the history
…d off (microsoft#3844)

* first commit

* changve to isfeatureenabled

* use constant not string

---------

Co-authored-by: Sophia Chen <[email protected]>
  • Loading branch information
chenss3 and Sophia Chen authored Sep 17, 2024
1 parent 6a236e7 commit 28f4daf
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public partial class MainPageViewModel : SetupPageViewModelBase, IDisposable
{
private readonly ILogger _log = Log.ForContext("SourceContext", nameof(MainPageViewModel));

private const string QuickstartPlaygroundFlowFeatureName = "QuickstartPlayground";
internal const string QuickstartPlaygroundFlowFeatureName = "QuickstartPlayground";

private readonly IHost _host;
private readonly IWinGet _winget;
Expand Down Expand Up @@ -104,7 +104,7 @@ public MainPageViewModel(
_host.GetService<IExperimentationService>().ExperimentalFeatures.FirstOrDefault(f => string.Equals(f.Id, QuickstartPlaygroundFlowFeatureName, StringComparison.Ordinal))!.PropertyChanged += ExperimentalFeaturesViewModel_PropertyChanged;

// Hack around this by setting the property explicitly based on the state of the feature.
EnableQuickstartPlayground = _host.GetService<IExperimentationService>().ExperimentalFeatures.FirstOrDefault(f => string.Equals(f.Id, QuickstartPlaygroundFlowFeatureName, StringComparison.Ordinal))!.IsEnabled;
EnableQuickstartPlayground = _host.GetService<IExperimentationService>().IsFeatureEnabled(QuickstartPlaygroundFlowFeatureName);
}

// Create a PropertyChanged handler that we will add to the ExperimentalFeaturesViewModel
Expand All @@ -113,7 +113,7 @@ private void ExperimentalFeaturesViewModel_PropertyChanged(object sender, System
{
if (e.PropertyName == nameof(ExperimentalFeature.IsEnabled))
{
EnableQuickstartPlayground = _host.GetService<IExperimentationService>().ExperimentalFeatures.FirstOrDefault(f => string.Equals(f.Id, QuickstartPlaygroundFlowFeatureName, StringComparison.Ordinal))!.IsEnabled;
EnableQuickstartPlayground = _host.GetService<IExperimentationService>().IsFeatureEnabled(QuickstartPlaygroundFlowFeatureName);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
using CommunityToolkit.Mvvm.Input;
using DevHome.Common.Contracts;
using DevHome.Common.Extensions;
using DevHome.Common.Services;
using DevHome.Common.TelemetryEvents.SetupFlow.QuickstartPlayground;
using DevHome.SetupFlow.Models;
using DevHome.SetupFlow.Services;
Expand Down Expand Up @@ -52,6 +53,8 @@ public string? FullFolderOutput

private readonly ObservableCollection<ExplorerItem> _dataSource = new();

private readonly IExperimentationService _experimentationService;

public Guid ActivityId { get; }

private IQuickStartProjectGenerationOperation _quickStartProjectGenerationOperation = null!;
Expand Down Expand Up @@ -175,7 +178,8 @@ public QuickstartPlaygroundViewModel(
ISetupFlowStringResource stringResource,
IQuickStartProjectService quickStartProjectService,
ILocalSettingsService localSettingsService,
SetupFlowOrchestrator orchestrator)
SetupFlowOrchestrator orchestrator,
IExperimentationService experimentationService)
: base(stringResource, orchestrator)
{
IsStepPage = false;
Expand All @@ -185,6 +189,8 @@ public QuickstartPlaygroundViewModel(

ActivityId = orchestrator.ActivityId;

_experimentationService = experimentationService;

// Placeholder launch text while button is disabled.
LaunchButtonText = StringResource.GetLocalized(StringResourceKey.QuickstartPlaygroundLaunchButton, string.Empty);
}
Expand Down Expand Up @@ -604,6 +610,17 @@ public void OnQuickstartSelectionChanged()
ConfigureForProviderSelection();
}
}

[RelayCommand]
private void OnLoaded()
{
var isEnabled = _experimentationService.IsFeatureEnabled(MainPageViewModel.QuickstartPlaygroundFlowFeatureName);
if (!isEnabled)
{
var setupFlow = Application.Current.GetService<SetupFlowViewModel>();
setupFlow.ResetToMainPage();
}
}
}

public class ExplorerItem : INotifyPropertyChanged
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ public void TerminateCurrentFlow(string callerNameForTelemetry)
_log.Information($"Terminating Setup flow by caller [{callerNameForTelemetry}]. ActivityId={Orchestrator.ActivityId}");
TelemetryFactory.Get<ITelemetry>().Log("SetupFlow_Termination", LogLevel.Critical, new EndFlowEvent(callerNameForTelemetry), relatedActivityId: Orchestrator.ActivityId);

ResetToMainPage();
}

public void ResetToMainPage()
{
Orchestrator.ReleaseRemoteOperationObject();
_host.GetService<IDevDriveManager>().RemoveAllDevDrives();
_packageProvider.Clear();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,16 @@
xmlns:setupFlowBehaviors="using:DevHome.SetupFlow.Behaviors"
xmlns:controls="using:DevHome.SetupFlow.Controls"
xmlns:ctcontrols="using:CommunityToolkit.WinUI.Controls"
xmlns:i="using:Microsoft.Xaml.Interactivity"
xmlns:ic="using:Microsoft.Xaml.Interactions.Core"
mc:Ignorable="d">

<i:Interaction.Behaviors>
<ic:EventTriggerBehavior EventName="Loaded">
<ic:InvokeCommandAction Command="{x:Bind ViewModel.LoadedCommand}" />
</ic:EventTriggerBehavior>
</i:Interaction.Behaviors>

<setupFlowBehaviors:SetupFlowNavigationBehavior.NextTemplate>
<StackPanel Orientation="Horizontal" HorizontalAlignment="Right">
<Button x:Uid="QuickstartPlaygroundSaveButton"
Expand Down

0 comments on commit 28f4daf

Please sign in to comment.