(packageVersions.Versions!.Reverse());
- TargetVersion = AvailableVersions.First();
- break;
- }
- await CoreWebView2Environment.CreateAsync(null, AppInfo.CachesDir);
- await SearchDetailPage.ProjectDescriptionWebView.EnsureCoreWebView2Async().ConfigureAwait(true);
- try
- {
- var projectDescriptionUrl = message.Package.Url;
- var html = await _httpClient.GetStringAsync(projectDescriptionUrl);
- var htmlDocument = new HtmlDocument();
- htmlDocument.LoadHtml(html);
- string projectDescriptionHtml = string.Format(HtmlModel, _themeType, ThemeTypeInHex, htmlDocument.DocumentNode.SelectSingleNode("//*[@id=\"description\"]/div").InnerHtml);
-
- SearchDetailPage.ProjectDescriptionWebView.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Dark;
- SearchDetailPage.ProjectDescriptionWebView.NavigateToString(projectDescriptionHtml);
- }
- catch (Exception ex)
- {
- Log.Error(ex.Message);
- _toastService.Error(Lang.SearchDetail_ProjectDescription_LoadFailed);
- string projectDescriptionHtml = string.Format(HtmlModel, _themeType, ThemeTypeInHex, $"{Lang.SearchDetail_ProjectDescription_LoadFailed}
");
-
- SearchDetailPage.ProjectDescriptionWebView.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Dark;
- SearchDetailPage.ProjectDescriptionWebView.NavigateToString(projectDescriptionHtml);
- }
- finally
- {
- await Task.Delay(500);
- ProjectDescriptionVisibility = true;
- }
- };
+ await SetupWebViewAsync(message.Package);
+ }
+ catch (Exception ex)
+ {
+ HandleLoadingError(ex);
+ }
+ finally
+ {
+ await Task.Delay(500);
+ ProjectDescriptionVisibility = true;
+ }
+ }
+
+ private async Task SetupWebViewAsync(QueryListItemModel package)
+ {
+ var packageVersions = await _environmentService.GetVersions(package.Name, new CancellationToken(), Configuration.AppConfig!.PackageSource.AllowNonRelease);
+ if (packageVersions.Status is 1 or 2)
+ {
+ _toastService.Error(Lang.SearchDetail_Exception_NetworkError);
+ await Task.Delay(1000);
+ _navigationService.GoBack();
+ return;
+ }
+
+ AvailableVersions = new ObservableCollection(packageVersions.Versions!.Reverse());
+ TargetVersion = AvailableVersions.First();
+
+ await CoreWebView2Environment.CreateAsync(null, AppInfo.CachesDir);
+ await SearchDetailPage.ProjectDescriptionWebView!.EnsureCoreWebView2Async().ConfigureAwait(true);
+ await LoadProjectDescriptionAsync(package.Url);
+ }
+
+ private async Task LoadProjectDescriptionAsync(string projectDescriptionUrl)
+ {
+ try
+ {
+ var html = await _httpClient.GetStringAsync(projectDescriptionUrl);
+ var htmlDocument = new HtmlDocument();
+ htmlDocument.LoadHtml(html);
+ string projectDescriptionHtml = string.Format(HtmlModel, _themeType, ThemeTypeInHex, htmlDocument.DocumentNode.SelectSingleNode("//*[@id=\"description\"]/div").InnerHtml);
+
+ SearchDetailPage.ProjectDescriptionWebView!.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Dark;
+ SearchDetailPage.ProjectDescriptionWebView.NavigateToString(projectDescriptionHtml);
+ }
+ catch (Exception ex)
+ {
+ HandleLoadingError(ex);
+ }
+ }
+
+ private void HandleLoadingError(Exception ex)
+ {
+ Log.Error(ex.Message);
+ _toastService.Error(Lang.SearchDetail_ProjectDescription_LoadFailed);
+ string projectDescriptionHtml = string.Format(HtmlModel, _themeType, ThemeTypeInHex, $"{Lang.SearchDetail_ProjectDescription_LoadFailed}
");
+ SearchDetailPage.ProjectDescriptionWebView!.CoreWebView2.Profile.PreferredColorScheme = CoreWebView2PreferredColorScheme.Dark;
+ SearchDetailPage.ProjectDescriptionWebView.NavigateToString(projectDescriptionHtml);
+ }
+
+ public async Task OnNavigatedToAsync()
+ {
+ if (!_isInitialized)
+ InitializeViewModel();
+ await Application.Current.Dispatcher.InvokeAsync(() =>
+ {
+ _navigationService.GetNavigationControl().BreadcrumbBar!.Visibility = Visibility.Collapsed;
+ });
+ switch (_themeService.GetTheme())
+ {
+ case ApplicationTheme.Light:
+ _themeType = "light";
+ ThemeTypeInHex = "#FFFFFF";
+ _themeTypeInInteger = 16777215;
+ break;
+
+ case ApplicationTheme.Dark:
+ _themeType = "dark";
+ ThemeTypeInHex = "#0D1117";
+ _themeTypeInInteger = 856343;
+ break;
+ case ApplicationTheme.Unknown:
+ case ApplicationTheme.HighContrast:
+ default:
+ throw new ArgumentOutOfRangeException();
+ }
+ SearchDetailPage.ProjectDescriptionWebView!.DefaultBackgroundColor = Color.FromArgb(_themeTypeInInteger);
+ }
+
+ public Task OnNavigatedFromAsync()
+ {
+ _navigationService.GetNavigationControl().BreadcrumbBar!.Visibility = Visibility.Visible;
+ return Task.CompletedTask;
}
}
\ No newline at end of file
diff --git a/src/ViewModels/Pages/Search/SearchViewModel.cs b/src/ViewModels/Pages/Search/SearchViewModel.cs
index e398299..2f5e630 100644
--- a/src/ViewModels/Pages/Search/SearchViewModel.cs
+++ b/src/ViewModels/Pages/Search/SearchViewModel.cs
@@ -8,50 +8,24 @@
using PipManager.Windows.Services.Toast;
using PipManager.Windows.Views.Pages.Search;
using Wpf.Ui;
-using Wpf.Ui.Controls;
+using Wpf.Ui.Abstractions.Controls;
namespace PipManager.Windows.ViewModels.Pages.Search;
-public partial class SearchViewModel(IPackageSearchService packageSearchService, IToastService toastService, IMaskService maskService, INavigationService navigationService) : ObservableObject, INavigationAware
+public partial class SearchViewModel(IPackageSearchService packageSearchService, IToastService toastService, IMaskService maskService, INavigationService navigationService)
+ : ObservableObject, INavigationAware
{
private bool _isInitialized;
- [ObservableProperty]
- private ObservableCollection _queryList = [];
-
- [ObservableProperty]
- private string _queryPackageName = "";
-
- [ObservableProperty]
- private string _totalResultNumber = "";
-
- [ObservableProperty]
- private bool _onQuerying;
-
- [ObservableProperty]
- private bool _successQueried;
-
- [ObservableProperty]
- private bool _reachesFirstPage = true;
-
- [ObservableProperty]
- private bool _reachesLastPage;
-
- [ObservableProperty]
- private int _currentPage = 1;
-
- [ObservableProperty]
- private int _maxPage = 1;
-
- public void OnNavigatedTo()
- {
- if (!_isInitialized)
- InitializeViewModel();
- }
-
- public void OnNavigatedFrom()
- {
- }
+ [ObservableProperty] private ObservableCollection _queryList = [];
+ [ObservableProperty] private string _queryPackageName = "";
+ [ObservableProperty] private string _totalResultNumber = "";
+ [ObservableProperty] private bool _onQuerying;
+ [ObservableProperty] private bool _successQueried;
+ [ObservableProperty] private bool _reachesFirstPage = true;
+ [ObservableProperty] private bool _reachesLastPage;
+ [ObservableProperty] private int _currentPage = 1;
+ [ObservableProperty] private int _maxPage = 1;
private void InitializeViewModel()
{
@@ -162,4 +136,16 @@ private async Task Search(string? parameter)
OnQuerying = false;
}
}
+
+ public Task OnNavigatedToAsync()
+ {
+ if (!_isInitialized)
+ InitializeViewModel();
+ return Task.CompletedTask;
+ }
+
+ public Task OnNavigatedFromAsync()
+ {
+ return Task.CompletedTask;
+ }
}
\ No newline at end of file
diff --git a/src/ViewModels/Pages/Settings/SettingsViewModel.cs b/src/ViewModels/Pages/Settings/SettingsViewModel.cs
index cdc6cd0..d7b84af 100644
--- a/src/ViewModels/Pages/Settings/SettingsViewModel.cs
+++ b/src/ViewModels/Pages/Settings/SettingsViewModel.cs
@@ -10,8 +10,8 @@
using PipManager.Windows.Views.Pages.About;
using PipManager.Windows.Views.Pages.Settings;
using Wpf.Ui;
+using Wpf.Ui.Abstractions.Controls;
using Wpf.Ui.Appearance;
-using Wpf.Ui.Controls;
using Wpf.Ui.Extensions;
namespace PipManager.Windows.ViewModels.Pages.Settings;
@@ -41,16 +41,6 @@ public SettingsViewModel(ISnackbarService snackbarService, IThemeService themeSe
private bool _isInitialized;
- public void OnNavigatedTo()
- {
- if (!_isInitialized)
- InitializeViewModel();
- }
-
- public void OnNavigatedFrom()
- {
- }
-
private void InitializeViewModel()
{
var config = Configuration.AppConfig!;
@@ -219,7 +209,7 @@ private void WebViewClearCache()
{
Directory.Delete(Path.Combine(AppInfo.CachesDir, "EBWebView"), true);
_toastService.Success(Lang.Settings_FileManagement_WebViewSettings_CacheCleared);
- Log.Information($"[Settings] WebView cache removed");
+ Log.Information("[Settings] WebView cache removed");
}
catch (DirectoryNotFoundException)
{
@@ -289,4 +279,16 @@ private static async Task ResetConfigurationAsync()
}
#endregion File Management
+
+ public Task OnNavigatedToAsync()
+ {
+ if (!_isInitialized)
+ InitializeViewModel();
+ return Task.CompletedTask;
+ }
+
+ public Task OnNavigatedFromAsync()
+ {
+ return Task.CompletedTask;
+ }
}
\ No newline at end of file
diff --git a/src/ViewModels/Pages/Tools/ToolsViewModel.cs b/src/ViewModels/Pages/Tools/ToolsViewModel.cs
index 087acff..ad6d238 100644
--- a/src/ViewModels/Pages/Tools/ToolsViewModel.cs
+++ b/src/ViewModels/Pages/Tools/ToolsViewModel.cs
@@ -1,5 +1,5 @@
using Serilog;
-using Wpf.Ui.Controls;
+using Wpf.Ui.Abstractions.Controls;
namespace PipManager.Windows.ViewModels.Pages.Tools;
@@ -10,19 +10,21 @@ public partial class ToolsViewModel : ObservableObject, INavigationAware
[ObservableProperty]
private string? _testProperty;
- public void OnNavigatedTo()
+ private void InitializeViewModel()
{
- if (!_isInitialized)
- InitializeViewModel();
+ _isInitialized = true;
+ Log.Information("[Tools] Initialized");
}
- public void OnNavigatedFrom()
+ public Task OnNavigatedToAsync()
{
+ if (!_isInitialized)
+ InitializeViewModel();
+ return Task.CompletedTask;
}
- private void InitializeViewModel()
+ public Task OnNavigatedFromAsync()
{
- _isInitialized = true;
- Log.Information("[Tools] Initialized");
+ return Task.CompletedTask;
}
}
\ No newline at end of file
diff --git a/src/ViewModels/Windows/MainWindowViewModel.cs b/src/ViewModels/Windows/MainWindowViewModel.cs
index 13ded03..7575dbe 100644
--- a/src/ViewModels/Windows/MainWindowViewModel.cs
+++ b/src/ViewModels/Windows/MainWindowViewModel.cs
@@ -6,6 +6,9 @@ namespace PipManager.Windows.ViewModels.Windows;
public partial class MainWindowViewModel : ObservableObject
{
[ObservableProperty] private bool _experimentMode;
+ [ObservableProperty] private bool _debugMode = App.IsDebugMode;
+ [ObservableProperty] private bool _isTitleBarCoverageGridVisible;
+ [ObservableProperty] private string _applicationTitle = "Pip Manager";
public MainWindowViewModel()
{
@@ -21,10 +24,4 @@ public MainWindowViewModel()
ApplicationTitle = "Pip Manager";
}
}
-
- [ObservableProperty]
- private bool _isTitleBarCoverageGridVisible;
-
- [ObservableProperty]
- private string _applicationTitle = "Pip Manager";
}
\ No newline at end of file
diff --git a/src/Views/Pages/About/AboutPage.xaml b/src/Views/Pages/About/AboutPage.xaml
index 4652b81..4b6c558 100644
--- a/src/Views/Pages/About/AboutPage.xaml
+++ b/src/Views/Pages/About/AboutPage.xaml
@@ -29,26 +29,21 @@
Source="pack://application:,,,/Assets/icon.png"
Width="200" />
-
+
+
+ FontTypography="BodyStrong"
+ Text="{Binding ViewModel.AppVersion, StringFormat=Version: {0}}"
+ VerticalAlignment="Center"
+ Visibility="{Binding ViewModel.DebugMode, Converter={StaticResource InverseBoolToVisibility}}" />
-
-
-
-
-
@@ -98,7 +93,7 @@
+ Text="Copyright (c) 2023-2024 AuroraZiling" />