From c59a7f5922212dd612ffc9f4c27a764d906ad635 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Mon, 12 Aug 2024 13:38:48 -0700 Subject: [PATCH 01/11] Environments reload after extensions refresh --- .../ViewModels/LandingPageViewModel.cs | 18 +++++++++++++++--- .../Views/LandingPage.xaml.cs | 2 +- .../ViewModels/ExtensionLibraryViewModel.cs | 3 +++ 3 files changed, 19 insertions(+), 4 deletions(-) diff --git a/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs b/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs index 26d8b682b3..69b76bd8bb 100644 --- a/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs +++ b/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs @@ -9,6 +9,7 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.WinUI; using CommunityToolkit.WinUI.Behaviors; using CommunityToolkit.WinUI.Collections; @@ -26,7 +27,7 @@ namespace DevHome.Environments.ViewModels; /// /// The main view model for the landing page of the Environments tool. /// -public partial class LandingPageViewModel : ObservableObject, IDisposable +public partial class LandingPageViewModel : ObservableObject, IDisposable, IRecipient { private readonly ILogger _log = Log.ForContext("SourceContext", nameof(LandingPageViewModel)); @@ -48,6 +49,8 @@ public partial class LandingPageViewModel : ObservableObject, IDisposable private bool _wasSyncButtonClicked; + private bool _extensionsPageNavigatedTo; + private string _selectedProvider = string.Empty; public bool IsLoading { get; set; } @@ -111,6 +114,7 @@ public LandingPageViewModel( _lastSyncTime = _stringResource.GetLocalized("MomentsAgo"); ComputeSystemCardsView = new AdvancedCollectionView(ComputeSystemCards); ComputeSystemCardsView.SortDescriptions.Add(new SortDescription("IsCardCreating", SortDirection.Descending)); + WeakReferenceMessenger.Default.Register(this); } public void Initialize(StackedNotificationsBehavior notificationQueue) @@ -216,7 +220,7 @@ private async Task RunSyncTimmer() /// /// Main entry point for loading the view model. /// - public async Task LoadModelAsync(bool useDebugValues = false) + public async Task LoadModelAsync() { lock (_lock) { @@ -228,8 +232,10 @@ public async Task LoadModelAsync(bool useDebugValues = false) // If the page has already loaded once, then we don't need to re-load the compute systems as that can take a while. // The user can click the sync button to refresh the compute systems. However, there may be new operations that have started // since the last time the page was loaded. So we need to add those to the view model quickly. + // But if the user navigated to the extensions page, we need to reload the compute systems, since they might + // have enabled/disabled an extension. SetupCreateComputeSystemOperationForUI(); - if (HasPageLoadedForTheFirstTime && !_wasSyncButtonClicked) + if (HasPageLoadedForTheFirstTime && !_wasSyncButtonClicked && !_extensionsPageNavigatedTo) { return; } @@ -269,6 +275,7 @@ public async Task LoadModelAsync(bool useDebugValues = false) { IsLoading = false; HasPageLoadedForTheFirstTime = true; + _extensionsPageNavigatedTo = false; } } @@ -552,4 +559,9 @@ private void UpdateCallToActionText() CallToActionText = callToActionData.CallToActionText; CallToActionHyperLinkButtonText = callToActionData.CallToActionHyperLinkText; } + + public void Receive(ExtensionsPageLoaded message) + { + _extensionsPageNavigatedTo = true; + } } diff --git a/tools/Environments/DevHome.Environments/Views/LandingPage.xaml.cs b/tools/Environments/DevHome.Environments/Views/LandingPage.xaml.cs index 21c8d7af68..249f342bdd 100644 --- a/tools/Environments/DevHome.Environments/Views/LandingPage.xaml.cs +++ b/tools/Environments/DevHome.Environments/Views/LandingPage.xaml.cs @@ -24,6 +24,6 @@ public LandingPage() private async void OnLoaded(object sender, RoutedEventArgs e) { - await ViewModel.LoadModelAsync(false); + await ViewModel.LoadModelAsync(); } } diff --git a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs index 2cee317b31..b8d0c085dc 100644 --- a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs +++ b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs @@ -8,7 +8,9 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; +using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.WinUI; +using DevHome.Common.Environments.Models; using DevHome.Common.Extensions; using DevHome.Common.Services; using Microsoft.UI.Dispatching; @@ -69,6 +71,7 @@ public async Task LoadedAsync() { await GetInstalledPackagesAndExtensionsAsync(); GetAvailablePackages(); + WeakReferenceMessenger.Default.Send(new ExtensionsPageLoaded(true)); } private async void OnExtensionsChanged(object? sender, EventArgs e) From 56cf8d3d042525e9cafc6ab6c9a07f0ab662824a Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Mon, 12 Aug 2024 14:33:08 -0700 Subject: [PATCH 02/11] Added message file --- common/Environments/Models/ExtensionsPageLoaded.cs | 14 ++++++++++++++ 1 file changed, 14 insertions(+) create mode 100644 common/Environments/Models/ExtensionsPageLoaded.cs diff --git a/common/Environments/Models/ExtensionsPageLoaded.cs b/common/Environments/Models/ExtensionsPageLoaded.cs new file mode 100644 index 0000000000..c113eac84c --- /dev/null +++ b/common/Environments/Models/ExtensionsPageLoaded.cs @@ -0,0 +1,14 @@ +// Copyright (c) Microsoft Corporation. +// Licensed under the MIT License. + +using CommunityToolkit.Mvvm.Messaging.Messages; + +namespace DevHome.Common.Environments.Models; + +public class ExtensionsPageLoaded : ValueChangedMessage +{ + public ExtensionsPageLoaded(bool value) + : base(value) + { + } +} From f9a7754e2620545b3852cc7f155393a69faeff69 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Mon, 12 Aug 2024 14:45:53 -0700 Subject: [PATCH 03/11] Added comment --- .../ViewModels/ExtensionLibraryViewModel.cs | 3 +++ 1 file changed, 3 insertions(+) diff --git a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs index b8d0c085dc..59cabaee5b 100644 --- a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs +++ b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs @@ -71,6 +71,9 @@ public async Task LoadedAsync() { await GetInstalledPackagesAndExtensionsAsync(); GetAvailablePackages(); + + // Send a message to the Environments page to let it know that the Extensions page has been loaded. + // And that the Environments page should update its list of environments. WeakReferenceMessenger.Default.Send(new ExtensionsPageLoaded(true)); } From 75aa81c129db7690bcb05b2e296861a2a6051b59 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Fri, 16 Aug 2024 13:54:11 -0700 Subject: [PATCH 04/11] Fixing UAC prompt --- common/Environments/Scripts/HyperVSetupScript.cs | 15 +-------------- 1 file changed, 1 insertion(+), 14 deletions(-) diff --git a/common/Environments/Scripts/HyperVSetupScript.cs b/common/Environments/Scripts/HyperVSetupScript.cs index e0fb5529d6..199b7c6e5c 100644 --- a/common/Environments/Scripts/HyperVSetupScript.cs +++ b/common/Environments/Scripts/HyperVSetupScript.cs @@ -37,21 +37,10 @@ 6. The user is already in the Hyper-V Admin group and the Hyper-V Feature is alr $adminGroupResult = [OperationStatus]::OperationNotRun $hyperVGroupSid = 'S-1-5-32-578' - # Check the security token the user logged on with contains the Hyper-V Administrators group SID (S-1-5-32-578). This can only be updated, - # once the user logs off and on again. Even if we add the user to the group later on in the script. - $foundSecurityTokenString = [System.Security.Principal.WindowsIdentity]::GetCurrent().Groups.Value | Where-Object { $_ -eq $hyperVGroupSid } - $doesUserSecurityTokenContainHyperAdminGroup = $foundSecurityTokenString -eq $hyperVGroupSid - # Check if the Hyper-V feature is enabled $featureState = Get-WindowsOptionalFeature -FeatureName 'Microsoft-Hyper-V' -Online | Select-Object -ExpandProperty State $featureEnabled = $featureState -eq 'Enabled' - if ($doesUserSecurityTokenContainHyperAdminGroup -and $featureEnabled) - { - # User already in Admin group and feature already enabled - exit 6 - } - # Enable the Hyper-V feature if it is not already enabled if (-not $featureEnabled) { @@ -119,9 +108,7 @@ exit 5 } # If both operations have not been run at this point, then user is already in the Hyper-V admin group and the Hyper-V feature is enabled. # This could happen if the script runs the first time without the user being in the group, while Hyper-V is enabled but the user doesn't - # log off/on again or reboot. The second time we run the script there would be no work to be done. Since the actual token of the user - # doesn't update until they log off, the $doesUserSecurityTokenContainHyperAdminGroup variable above will still remain false, which is - # how we ended up here. + # log off/on again or reboot. The second time we run the script there would be no work to be done. elseif ($featureEnablementResult -eq [OperationStatus]::OperationNotRun -and $adminGroupResult -eq [OperationStatus]::OperationNotRun) { exit 6 From 4bebbea97744a3e65190f38c1cef2907feb55ecc Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Wed, 21 Aug 2024 15:23:17 -0700 Subject: [PATCH 05/11] Added selectable text --- .../StackedNotificationsBehaviorExtensions.cs | 41 +++++++++++++------ 1 file changed, 28 insertions(+), 13 deletions(-) diff --git a/common/Extensions/StackedNotificationsBehaviorExtensions.cs b/common/Extensions/StackedNotificationsBehaviorExtensions.cs index c93bbec88b..0fe5edd6b0 100644 --- a/common/Extensions/StackedNotificationsBehaviorExtensions.cs +++ b/common/Extensions/StackedNotificationsBehaviorExtensions.cs @@ -23,27 +23,42 @@ public static void ShowWithWindowExtension( var dispatcherQueue = Application.Current.GetService(); dispatcherQueue?.EnqueueAsync(() => - { + { var notificationToShow = new Notification { Title = title, - Message = message, Severity = severity, - }; + }; + + // Create a stack panel to hold the message and button + // A custom control is needed to allow text selection in the message + var stackPanel = new StackPanel + { + Orientation = Orientation.Vertical, + Margin = new Thickness(0, -15, 0, 20), + Spacing = 10, + }; + + stackPanel.Children.Add(new TextBlock + { + Text = message, + TextWrapping = TextWrapping.WrapWholeWords, + IsTextSelectionEnabled = true, + }); if (command != null) - { - notificationToShow.ActionButton = new Button - { - Content = buttonContent, - Command = command, - }; - + { // Make the command parameter the notification so RelayCommands can reference the notification in case they need // to close it within the command. - notificationToShow.ActionButton.CommandParameter = notificationToShow; - } - + stackPanel.Children.Add(new Button + { + Content = buttonContent, + Command = command, + CommandParameter = notificationToShow, + }); + } + + notificationToShow.Content = stackPanel; behavior.Show(notificationToShow); }); } From 223e0893e2bdf342846a709941f31245952ec987 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Thu, 22 Aug 2024 14:09:21 -0700 Subject: [PATCH 06/11] Added AltName to MachineConfig Flow --- .../ComputeSystemCardViewModel.cs | 8 ++- .../Views/SetupTargetView.xaml | 51 ++++++++++--------- 2 files changed, 32 insertions(+), 27 deletions(-) diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs index 106158a06c..5ce1459843 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs @@ -48,7 +48,10 @@ public partial class ComputeSystemCardViewModel : ObservableObject private bool _isSelected; [ObservableProperty] - private string _computeSystemTitle; + private string _computeSystemTitle; + + [ObservableProperty] + private string _computeSystemAlternativeTitle; [ObservableProperty] private string _computeSystemProviderDisplayName; @@ -68,7 +71,8 @@ public ComputeSystemCardViewModel(ComputeSystemCache computeSystem, IComputeSyst { _dispatcherQueue = dispatcherQueue; _computeSystemManager = manager; - ComputeSystemTitle = computeSystem.DisplayName.Value; + ComputeSystemTitle = computeSystem.DisplayName.Value; + ComputeSystemAlternativeTitle = computeSystem.SupplementalDisplayName.Value; ComputeSystem = computeSystem; ComputeSystem.StateChanged += _computeSystemManager.OnComputeSystemStateChanged; _computeSystemManager.ComputeSystemStateChanged += OnComputeSystemStateChanged; diff --git a/tools/SetupFlow/DevHome.SetupFlow/Views/SetupTargetView.xaml b/tools/SetupFlow/DevHome.SetupFlow/Views/SetupTargetView.xaml index 84d21d9977..108f539906 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/Views/SetupTargetView.xaml +++ b/tools/SetupFlow/DevHome.SetupFlow/Views/SetupTargetView.xaml @@ -8,8 +8,8 @@ xmlns:setupControls="using:DevHome.SetupFlow.Controls" xmlns:devEnvModels="using:DevHome.SetupFlow.Models.Environments" xmlns:devViewModels="using:DevHome.SetupFlow.ViewModels.Environments" - xmlns:devEnvCustomControls="using:DevHome.Common.Environments.CustomControls" - xmlns:devCommonModels="using:DevHome.Common.Environments.Models" + xmlns:devEnvCustomControls="using:DevHome.Common.Environments.CustomControls" + xmlns:devCommonModels="using:DevHome.Common.Environments.Models" xmlns:converters="using:CommunityToolkit.WinUI.Converters" xmlns:ic="using:Microsoft.Xaml.Interactions.Core" xmlns:i="using:Microsoft.Xaml.Interactivity" @@ -56,6 +56,7 @@ - - - @@ -221,7 +222,7 @@ Text="{x:Bind ViewModel.ComputeSystemFilterText, Mode=TwoWay}"> - @@ -240,7 +241,7 @@ - @@ -254,14 +255,14 @@ SelectedValue="{x:Bind ViewModel.SelectedComputeSystemProviderComboBoxName, Mode=TwoWay}"> - - @@ -277,8 +278,8 @@ SelectedIndex="{x:Bind ViewModel.SelectedComputeSystemSortComboBoxIndex, Mode=TwoWay}"> - @@ -295,12 +296,12 @@ - - - @@ -354,7 +355,7 @@ Grid.Row="1" Visibility="{x:Bind ViewModel.ShouldShowCollectionView, Mode=OneWay, Converter={StaticResource CollapsedWhenTrueBoolToVisibilityConverter}}"> - - - - From 689e15f3c784942e1192766bde821d5411b33c0d Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Thu, 22 Aug 2024 14:09:42 -0700 Subject: [PATCH 07/11] Remove empty properties --- .../DevHome.Environments/ViewModels/ComputeSystemViewModel.cs | 4 ++++ .../ViewModels/Environments/ComputeSystemCardViewModel.cs | 4 ++++ 2 files changed, 8 insertions(+) diff --git a/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs b/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs index 9d296e476d..50a281b370 100644 --- a/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs +++ b/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs @@ -221,6 +221,10 @@ private async void SetPropertiesAsync() } var properties = await ComputeSystemHelpers.GetComputeSystemCardPropertiesAsync(ComputeSystem!, PackageFullName); + + // Remove properties with empty values + properties.RemoveAll(p => p?.Value == null || string.IsNullOrEmpty(p.Value.ToString())); + if (!ComputeSystemHelpers.RemoveAllItemsAndReplace(Properties, properties)) { Properties = new(properties); diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs index 5ce1459843..a0c64f51fa 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs @@ -104,6 +104,10 @@ private async Task RefreshOperationDataAsync() private async Task UpdatePropertiesAsync() { var properties = await ComputeSystemHelpers.GetComputeSystemCardPropertiesAsync(ComputeSystem, _packageFullName); + + // Remove properties with empty values + properties.RemoveAll(p => p?.Value == null || string.IsNullOrEmpty(p.Value.ToString())); + lock (_lock) { if (!ComputeSystemHelpers.RemoveAllItemsAndReplace(ComputeSystemProperties, properties)) From 2756b6f37f0824f8bce2ef38f5c02379289aaf8c Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Thu, 22 Aug 2024 15:52:03 -0700 Subject: [PATCH 08/11] Remove empty properties II --- common/Environments/Helpers/ComputeSystemHelpers.cs | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/common/Environments/Helpers/ComputeSystemHelpers.cs b/common/Environments/Helpers/ComputeSystemHelpers.cs index db644b54fa..5d1e85da15 100644 --- a/common/Environments/Helpers/ComputeSystemHelpers.cs +++ b/common/Environments/Helpers/ComputeSystemHelpers.cs @@ -5,6 +5,7 @@ using System.Collections.Generic; using System.Collections.ObjectModel; using System.IO; +using System.Linq; using System.Runtime.InteropServices.WindowsRuntime; using System.Threading.Tasks; using DevHome.Common.Environments.Models; @@ -88,7 +89,13 @@ public static async Task> GetComputeSystemCardPropertiesAsync try { var currentProperties = await computeSystem.GetComputeSystemPropertiesAsync(string.Empty); - return GetComputeSystemCardProperties(currentProperties, packageFullName); + + // Remove properties with empty values + var filteredProperties = currentProperties + .Where(p => p?.Value != null && !string.IsNullOrEmpty(p.Value.ToString())) + .ToList(); + + return GetComputeSystemCardProperties(filteredProperties, packageFullName); } catch (Exception ex) { From 02c0f28f3065837341f2cc4210cb7a85d49b0328 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Fri, 23 Aug 2024 11:01:09 -0700 Subject: [PATCH 09/11] Added ExtensionToggle event --- .../Models/ExtensionsPageLoaded.cs | 14 ---------- common/Services/IExtensionService.cs | 3 +++ src/Services/ExtensionService.cs | 13 ++++++--- .../ViewModels/LandingPageViewModel.cs | 27 ++++++++++--------- .../ViewModels/ExtensionLibraryViewModel.cs | 4 --- 5 files changed, 27 insertions(+), 34 deletions(-) delete mode 100644 common/Environments/Models/ExtensionsPageLoaded.cs diff --git a/common/Environments/Models/ExtensionsPageLoaded.cs b/common/Environments/Models/ExtensionsPageLoaded.cs deleted file mode 100644 index c113eac84c..0000000000 --- a/common/Environments/Models/ExtensionsPageLoaded.cs +++ /dev/null @@ -1,14 +0,0 @@ -// Copyright (c) Microsoft Corporation. -// Licensed under the MIT License. - -using CommunityToolkit.Mvvm.Messaging.Messages; - -namespace DevHome.Common.Environments.Models; - -public class ExtensionsPageLoaded : ValueChangedMessage -{ - public ExtensionsPageLoaded(bool value) - : base(value) - { - } -} diff --git a/common/Services/IExtensionService.cs b/common/Services/IExtensionService.cs index 941e61e583..298c19fe71 100644 --- a/common/Services/IExtensionService.cs +++ b/common/Services/IExtensionService.cs @@ -4,6 +4,7 @@ using System; using System.Collections.Generic; using System.Threading.Tasks; +using Windows.Foundation; namespace DevHome.Common.Services; @@ -21,6 +22,8 @@ public interface IExtensionService public event EventHandler OnExtensionsChanged; + public event TypedEventHandler ExtensionToggled; + public void EnableExtension(string extensionUniqueId); public void DisableExtension(string extensionUniqueId); diff --git a/src/Services/ExtensionService.cs b/src/Services/ExtensionService.cs index e09d7c6ea5..80fa7101ad 100644 --- a/src/Services/ExtensionService.cs +++ b/src/Services/ExtensionService.cs @@ -12,6 +12,7 @@ using Serilog; using Windows.ApplicationModel; using Windows.ApplicationModel.AppExtensions; +using Windows.Foundation; using Windows.Foundation.Collections; using static DevHome.Common.Helpers.ManagementInfrastructureHelper; @@ -23,6 +24,8 @@ public class ExtensionService : IExtensionService, IDisposable public event EventHandler OnExtensionsChanged = (_, _) => { }; + public event TypedEventHandler ExtensionToggled = (_, _) => { }; + private static readonly PackageCatalog _catalog = PackageCatalog.OpenForCurrentUser(); private static readonly object _lock = new(); private readonly SemaphoreSlim _getInstalledExtensionsLock = new(1, 1); @@ -369,14 +372,16 @@ private List GetCreateInstanceList(IPropertySet activationPropSet) public void EnableExtension(string extensionUniqueId) { - var extension = _installedExtensions.Where(extension => extension.ExtensionUniqueId.Equals(extensionUniqueId, StringComparison.Ordinal)); - _enabledExtensions.Add(extension.First()); + var extension = _installedExtensions.Where(extension => extension.ExtensionUniqueId.Equals(extensionUniqueId, StringComparison.Ordinal)).First(); + ExtensionToggled.Invoke(this, extension); + _enabledExtensions.Add(extension); } public void DisableExtension(string extensionUniqueId) { - var extension = _enabledExtensions.Where(extension => extension.ExtensionUniqueId.Equals(extensionUniqueId, StringComparison.Ordinal)); - _enabledExtensions.Remove(extension.First()); + var extension = _enabledExtensions.Where(extension => extension.ExtensionUniqueId.Equals(extensionUniqueId, StringComparison.Ordinal)).First(); + ExtensionToggled.Invoke(this, extension); + _enabledExtensions.Remove(extension); } /// diff --git a/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs b/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs index 69b76bd8bb..7ef113b43e 100644 --- a/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs +++ b/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs @@ -27,7 +27,7 @@ namespace DevHome.Environments.ViewModels; /// /// The main view model for the landing page of the Environments tool. /// -public partial class LandingPageViewModel : ObservableObject, IDisposable, IRecipient +public partial class LandingPageViewModel : ObservableObject, IDisposable { private readonly ILogger _log = Log.ForContext("SourceContext", nameof(LandingPageViewModel)); @@ -49,7 +49,7 @@ public partial class LandingPageViewModel : ObservableObject, IDisposable, IReci private bool _wasSyncButtonClicked; - private bool _extensionsPageNavigatedTo; + private bool _extensionsToggled; private string _selectedProvider = string.Empty; @@ -101,6 +101,7 @@ private enum SortOptions public LandingPageViewModel( INavigationService navigationService, IComputeSystemManager manager, + IExtensionService extensionService, Window mainWindow) { _computeSystemManager = manager; @@ -114,7 +115,15 @@ public LandingPageViewModel( _lastSyncTime = _stringResource.GetLocalized("MomentsAgo"); ComputeSystemCardsView = new AdvancedCollectionView(ComputeSystemCards); ComputeSystemCardsView.SortDescriptions.Add(new SortDescription("IsCardCreating", SortDirection.Descending)); - WeakReferenceMessenger.Default.Register(this); + extensionService.ExtensionToggled += OnExtensionToggled; + } + + private void OnExtensionToggled(IExtensionService sender, IExtensionWrapper extension) + { + if (extension.HasProviderType(ProviderType.ComputeSystem)) + { + _extensionsToggled = true; + } } public void Initialize(StackedNotificationsBehavior notificationQueue) @@ -232,10 +241,9 @@ public async Task LoadModelAsync() // If the page has already loaded once, then we don't need to re-load the compute systems as that can take a while. // The user can click the sync button to refresh the compute systems. However, there may be new operations that have started // since the last time the page was loaded. So we need to add those to the view model quickly. - // But if the user navigated to the extensions page, we need to reload the compute systems, since they might - // have enabled/disabled an extension. + // But if the user toggled extensions, we need to reload the page to show refreshed data. SetupCreateComputeSystemOperationForUI(); - if (HasPageLoadedForTheFirstTime && !_wasSyncButtonClicked && !_extensionsPageNavigatedTo) + if (HasPageLoadedForTheFirstTime && !_wasSyncButtonClicked && !_extensionsToggled) { return; } @@ -275,7 +283,7 @@ public async Task LoadModelAsync() { IsLoading = false; HasPageLoadedForTheFirstTime = true; - _extensionsPageNavigatedTo = false; + _extensionsToggled = false; } } @@ -559,9 +567,4 @@ private void UpdateCallToActionText() CallToActionText = callToActionData.CallToActionText; CallToActionHyperLinkButtonText = callToActionData.CallToActionHyperLinkText; } - - public void Receive(ExtensionsPageLoaded message) - { - _extensionsPageNavigatedTo = true; - } } diff --git a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs index 59cabaee5b..fed6545d8a 100644 --- a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs +++ b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs @@ -71,10 +71,6 @@ public async Task LoadedAsync() { await GetInstalledPackagesAndExtensionsAsync(); GetAvailablePackages(); - - // Send a message to the Environments page to let it know that the Extensions page has been loaded. - // And that the Environments page should update its list of environments. - WeakReferenceMessenger.Default.Send(new ExtensionsPageLoaded(true)); } private async void OnExtensionsChanged(object? sender, EventArgs e) From 7b51b33909c2a65939f52fc44610c3d40470b282 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Mon, 26 Aug 2024 10:40:41 -0700 Subject: [PATCH 10/11] Resolved comments I --- common/Environments/Helpers/ComputeSystemHelpers.cs | 2 +- common/Environments/Scripts/HyperVSetupScript.cs | 4 +++- .../DevHome.Environments/ViewModels/ComputeSystemViewModel.cs | 3 --- .../ViewModels/Environments/ComputeSystemCardViewModel.cs | 3 --- 4 files changed, 4 insertions(+), 8 deletions(-) diff --git a/common/Environments/Helpers/ComputeSystemHelpers.cs b/common/Environments/Helpers/ComputeSystemHelpers.cs index 5d1e85da15..1ef53b4034 100644 --- a/common/Environments/Helpers/ComputeSystemHelpers.cs +++ b/common/Environments/Helpers/ComputeSystemHelpers.cs @@ -92,7 +92,7 @@ public static async Task> GetComputeSystemCardPropertiesAsync // Remove properties with empty values var filteredProperties = currentProperties - .Where(p => p?.Value != null && !string.IsNullOrEmpty(p.Value.ToString())) + .Where(property => property?.Value != null && !string.IsNullOrEmpty(property.Value.ToString())) .ToList(); return GetComputeSystemCardProperties(filteredProperties, packageFullName); diff --git a/common/Environments/Scripts/HyperVSetupScript.cs b/common/Environments/Scripts/HyperVSetupScript.cs index 199b7c6e5c..443e6c1010 100644 --- a/common/Environments/Scripts/HyperVSetupScript.cs +++ b/common/Environments/Scripts/HyperVSetupScript.cs @@ -108,7 +108,9 @@ exit 5 } # If both operations have not been run at this point, then user is already in the Hyper-V admin group and the Hyper-V feature is enabled. # This could happen if the script runs the first time without the user being in the group, while Hyper-V is enabled but the user doesn't - # log off/on again or reboot. The second time we run the script there would be no work to be done. + # log off/on again or reboot. The second time we run the script there would be no work to be done. Since the actual token of the user + # doesn't update until they log off, the $doesUserSecurityTokenContainHyperAdminGroup variable above will still remain false, which is + # how we ended up here. elseif ($featureEnablementResult -eq [OperationStatus]::OperationNotRun -and $adminGroupResult -eq [OperationStatus]::OperationNotRun) { exit 6 diff --git a/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs b/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs index 50a281b370..901fe2489c 100644 --- a/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs +++ b/tools/Environments/DevHome.Environments/ViewModels/ComputeSystemViewModel.cs @@ -222,9 +222,6 @@ private async void SetPropertiesAsync() var properties = await ComputeSystemHelpers.GetComputeSystemCardPropertiesAsync(ComputeSystem!, PackageFullName); - // Remove properties with empty values - properties.RemoveAll(p => p?.Value == null || string.IsNullOrEmpty(p.Value.ToString())); - if (!ComputeSystemHelpers.RemoveAllItemsAndReplace(Properties, properties)) { Properties = new(properties); diff --git a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs index a0c64f51fa..82eaf9ba3c 100644 --- a/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs +++ b/tools/SetupFlow/DevHome.SetupFlow/ViewModels/Environments/ComputeSystemCardViewModel.cs @@ -105,9 +105,6 @@ private async Task UpdatePropertiesAsync() { var properties = await ComputeSystemHelpers.GetComputeSystemCardPropertiesAsync(ComputeSystem, _packageFullName); - // Remove properties with empty values - properties.RemoveAll(p => p?.Value == null || string.IsNullOrEmpty(p.Value.ToString())); - lock (_lock) { if (!ComputeSystemHelpers.RemoveAllItemsAndReplace(ComputeSystemProperties, properties)) From 03b015f8e0837a7e3d49eefc1fbd50ceef3b76b0 Mon Sep 17 00:00:00 2001 From: Huzaifa Danish Date: Tue, 27 Aug 2024 10:55:14 -0700 Subject: [PATCH 11/11] Removed unused headers --- .../DevHome.Environments/ViewModels/LandingPageViewModel.cs | 1 - .../ViewModels/ExtensionLibraryViewModel.cs | 2 -- 2 files changed, 3 deletions(-) diff --git a/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs b/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs index 7ef113b43e..0786b1eba9 100644 --- a/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs +++ b/tools/Environments/DevHome.Environments/ViewModels/LandingPageViewModel.cs @@ -9,7 +9,6 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.WinUI; using CommunityToolkit.WinUI.Behaviors; using CommunityToolkit.WinUI.Collections; diff --git a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs index fed6545d8a..2cee317b31 100644 --- a/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs +++ b/tools/ExtensionLibrary/DevHome.ExtensionLibrary/ViewModels/ExtensionLibraryViewModel.cs @@ -8,9 +8,7 @@ using System.Threading.Tasks; using CommunityToolkit.Mvvm.ComponentModel; using CommunityToolkit.Mvvm.Input; -using CommunityToolkit.Mvvm.Messaging; using CommunityToolkit.WinUI; -using DevHome.Common.Environments.Models; using DevHome.Common.Extensions; using DevHome.Common.Services; using Microsoft.UI.Dispatching;