Skip to content

Commit

Permalink
perf: progress ring while loading env
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraZiling committed Apr 28, 2024
1 parent d0b8098 commit c460531
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 81 deletions.
36 changes: 24 additions & 12 deletions src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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<EnvironmentItem>(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<EnvironmentItem>(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>();
mainWindowViewModel.ApplicationTitle =
$"Pip Manager | {CurrentEnvironment.PipVersion} for {CurrentEnvironment.PythonVersion}";
Log.Information($"[Environment] Current Environment changed: {CurrentEnvironment.PythonPath}");
}

CurrentEnvironment = environmentItem;
var mainWindowViewModel = App.GetService<MainWindowViewModel>();
mainWindowViewModel.ApplicationTitle = $"Pip Manager | {CurrentEnvironment.PipVersion} for {CurrentEnvironment.PythonVersion}";
Log.Information($"[Environment] Current Environment changed: {CurrentEnvironment.PythonPath}");
}
}).ContinueWith((_ =>
{
LoadingEnvironmentList = false;
}));
}

public void OnNavigatedFrom()
Expand Down
149 changes: 80 additions & 69 deletions src/PipManager/Views/Pages/Environment/EnvironmentPage.xaml
Original file line number Diff line number Diff line change
Expand Up @@ -21,75 +21,86 @@
xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

<StackPanel>
<StackPanel Orientation="Horizontal">
<ui:Button
Appearance="Primary"
Command="{Binding ViewModel.AddEnvironmentCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_AddEnvironment}}"
Icon="{ui:SymbolIcon Add24}" />
<ui:Button
Command="{Binding ViewModel.DeleteEnvironmentCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_RemoveEnvironment}}"
Icon="{ui:SymbolIcon Delete24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
<ui:Button
Command="{Binding ViewModel.CheckEnvironmentCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_VerifyEnvironment}}"
Icon="{ui:SymbolIcon Check24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
<ui:Button
Command="{Binding ViewModel.CheckEnvironmentUpdateCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_CheckEnvironmentUpdate}}"
Icon="{ui:SymbolIcon ArrowUp24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
<ui:Button
Command="{Binding ViewModel.ClearCacheCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_ClearEnvironmentCache}}"
Icon="{ui:SymbolIcon Eraser24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
</StackPanel>
<ui:ListView
ItemsSource="{Binding ViewModel.EnvironmentItems}"
Margin="0,10,0,0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedItem="{Binding ViewModel.CurrentEnvironment}"
VerticalAlignment="Stretch">
<ui:ListView.ItemTemplate>
<DataTemplate DataType="{x:Type appConfigModels:EnvironmentItem}">
<Grid Margin="0,8,0,0" x:Name="ByEnvironmentVariableGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="180" />
</Grid.ColumnDefinitions>
<Image
Grid.Column="0"
Height="48"
HorizontalAlignment="Right"
RenderOptions.BitmapScalingMode="HighQuality"
Source="../../../Assets/logo/python-logo-only.png"
Width="48" />
<StackPanel Grid.Column="1" Margin="7,0,0,0">
<StackPanel Orientation="Horizontal">
<ui:TextBlock FontTypography="BodyStrong" Text="{Binding PipVersion, Mode=TwoWay}" />
<ui:TextBlock FontTypography="BodyStrong" Text=" " />
<ui:TextBlock FontTypography="BodyStrong" Text="{Binding PythonVersion, StringFormat=for Python {0}}" />
<Grid>
<ui:ProgressRing
Height="80"
HorizontalAlignment="Center"
IsIndeterminate="True"
VerticalAlignment="Center"
Visibility="{Binding ViewModel.LoadingEnvironmentList, Converter={StaticResource BoolToVisibility}}"
Width="80" />
<StackPanel Visibility="{Binding ViewModel.LoadingEnvironmentList, Converter={StaticResource InverseBoolToVisibility}}">
<StackPanel Orientation="Horizontal">
<ui:Button
Appearance="Primary"
Command="{Binding ViewModel.AddEnvironmentCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_AddEnvironment}}"
Icon="{ui:SymbolIcon Add24}" />
<ui:Button
Command="{Binding ViewModel.DeleteEnvironmentCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_RemoveEnvironment}}"
Icon="{ui:SymbolIcon Delete24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
<ui:Button
Command="{Binding ViewModel.CheckEnvironmentCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_VerifyEnvironment}}"
Icon="{ui:SymbolIcon Check24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
<ui:Button
Command="{Binding ViewModel.CheckEnvironmentUpdateCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_CheckEnvironmentUpdate}}"
Icon="{ui:SymbolIcon ArrowUp24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
<ui:Button
Command="{Binding ViewModel.ClearCacheCommand}"
Content="{I18N {x:Static lang:LangKeys.Environment_Operation_ClearEnvironmentCache}}"
Icon="{ui:SymbolIcon Eraser24}"
IsEnabled="{Binding ViewModel.CurrentEnvironment, Converter={StaticResource NullToBool}}"
Margin="5,0,0,0" />
</StackPanel>
<ui:ListView
ItemsSource="{Binding ViewModel.EnvironmentItems}"
Margin="0,10,0,0"
ScrollViewer.HorizontalScrollBarVisibility="Disabled"
SelectedItem="{Binding ViewModel.CurrentEnvironment}"
VerticalAlignment="Stretch">
<ui:ListView.ItemTemplate>
<DataTemplate DataType="{x:Type appConfigModels:EnvironmentItem}">
<Grid Margin="0,8,0,0" x:Name="ByEnvironmentVariableGrid">
<Grid.ColumnDefinitions>
<ColumnDefinition Width="48" />
<ColumnDefinition Width="*" />
<ColumnDefinition Width="180" />
</Grid.ColumnDefinitions>
<Image
Grid.Column="0"
Height="48"
HorizontalAlignment="Right"
RenderOptions.BitmapScalingMode="HighQuality"
Source="../../../Assets/logo/python-logo-only.png"
Width="48" />
<StackPanel Grid.Column="1" Margin="7,0,0,0">
<StackPanel Orientation="Horizontal">
<ui:TextBlock FontTypography="BodyStrong" Text="{Binding PipVersion, Mode=TwoWay}" />
<ui:TextBlock FontTypography="BodyStrong" Text=" " />
<ui:TextBlock FontTypography="BodyStrong" Text="{Binding PythonVersion, StringFormat=for Python {0}}" />
</StackPanel>

<ui:TextBlock
FontTypography="Body"
Foreground="Gray"
Text="{Binding PythonPath}"
TextWrapping="Wrap" />
</StackPanel>
</Grid>
</DataTemplate>
</ui:ListView.ItemTemplate>
</ui:ListView>
</StackPanel>

</Grid>

<ui:TextBlock
FontTypography="Body"
Foreground="Gray"
Text="{Binding PythonPath}"
TextWrapping="Wrap" />
</StackPanel>
</Grid>
</DataTemplate>
</ui:ListView.ItemTemplate>
</ui:ListView>
</StackPanel>
</Page>

0 comments on commit c460531

Please sign in to comment.