diff --git a/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs b/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs index 7f3f4f5..86c7541 100644 --- a/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs @@ -13,6 +13,7 @@ using Serilog; using System.Collections.ObjectModel; using System.ComponentModel; +using System.Diagnostics; using Wpf.Ui; using Wpf.Ui.Controls; using Wpf.Ui.Extensions; @@ -27,25 +28,36 @@ public partial class EnvironmentViewModel(INavigationService navigationService, { private bool _isInitialized; + [ObservableProperty] private bool _loadingEnvironmentList = true; + public void OnNavigatedTo() { + LoadingEnvironmentList = true; if (!_isInitialized) InitializeViewModel(); - configurationService.RefreshAllEnvironmentVersions(); - EnvironmentItems = new ObservableCollection(configurationService.AppConfig.EnvironmentItems); - var currentEnvironment = configurationService.AppConfig.CurrentEnvironment; - foreach (var environmentItem in EnvironmentItems) + Task.Run(() => { - if (currentEnvironment is null || environmentItem.PythonPath != currentEnvironment.PythonPath) + configurationService.RefreshAllEnvironmentVersions(); + EnvironmentItems = + new ObservableCollection(configurationService.AppConfig.EnvironmentItems); + var currentEnvironment = configurationService.AppConfig.CurrentEnvironment; + foreach (var environmentItem in EnvironmentItems) { - continue; + if (currentEnvironment is null || environmentItem.PythonPath != currentEnvironment.PythonPath) + { + continue; + } + + CurrentEnvironment = environmentItem; + var mainWindowViewModel = App.GetService(); + mainWindowViewModel.ApplicationTitle = + $"Pip Manager | {CurrentEnvironment.PipVersion} for {CurrentEnvironment.PythonVersion}"; + Log.Information($"[Environment] Current Environment changed: {CurrentEnvironment.PythonPath}"); } - - CurrentEnvironment = environmentItem; - var mainWindowViewModel = App.GetService(); - mainWindowViewModel.ApplicationTitle = $"Pip Manager | {CurrentEnvironment.PipVersion} for {CurrentEnvironment.PythonVersion}"; - Log.Information($"[Environment] Current Environment changed: {CurrentEnvironment.PythonPath}"); - } + }).ContinueWith((_ => + { + LoadingEnvironmentList = false; + })); } public void OnNavigatedFrom() diff --git a/src/PipManager/Views/Pages/Environment/EnvironmentPage.xaml b/src/PipManager/Views/Pages/Environment/EnvironmentPage.xaml index 46fd731..d7c0a4a 100644 --- a/src/PipManager/Views/Pages/Environment/EnvironmentPage.xaml +++ b/src/PipManager/Views/Pages/Environment/EnvironmentPage.xaml @@ -21,75 +21,86 @@ xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - - - - - - \ No newline at end of file