From e2bef4ea6a4a1301a1b955cb1578072573f99a40 Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Sat, 6 Apr 2024 20:13:38 +0800 Subject: [PATCH 01/17] fix: cannot install via .whl --- .../Pages/Library/LibraryInstallViewModel.cs | 4 +- .../Views/Pages/Action/ActionPage.xaml | 92 ++++++++++--------- 2 files changed, 54 insertions(+), 42 deletions(-) diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs index 919cecc..185a0f0 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs @@ -316,7 +316,7 @@ private async Task SelectDistributions() using var wheelFileArchive = new ZipArchive(wheelFileStream, ZipArchiveMode.Read); foreach (ZipArchiveEntry entry in wheelFileArchive.Entries) { - if (!entry.FullName.Contains(".dist-info/METADATA") || !entry.FullName.Contains("PKG-INFO")) + if (!entry.FullName.Contains(".dist-info/METADATA") && !entry.FullName.Contains("PKG-INFO")) { continue; } @@ -334,6 +334,8 @@ private async Task SelectDistributions() break; } } + + } } else if (fileName.EndsWith(".tar.gz")) diff --git a/src/PipManager/Views/Pages/Action/ActionPage.xaml b/src/PipManager/Views/Pages/Action/ActionPage.xaml index 171afa9..beca245 100644 --- a/src/PipManager/Views/Pages/Action/ActionPage.xaml +++ b/src/PipManager/Views/Pages/Action/ActionPage.xaml @@ -1,25 +1,25 @@ + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> @@ -34,74 +34,81 @@ Icon="{ui:SymbolIcon Bug24}" /> + ItemsSource="{Binding ViewModel.Actions.AsObservable}" + x:Name="ActionList"> - + - + - + + Text="{Binding OperationDescription}" + VerticalAlignment="Center" /> + VerticalAlignment="Center"> + Value="{Binding ProgressBarValue, Mode=OneWay}" + Width="300" /> - + + TextWrapping="WrapWithOverflow" + VerticalAlignment="Center" /> - + + Margin="5,0,0,0" + Text="{Binding OperationStatus}" + VerticalAlignment="Center" /> @@ -116,15 +123,18 @@ Grid.Column="1" Margin="0,5,0,0" Style="{StaticResource BodyLargeTextBlockStyle}" - Text="Console Output" /> + Text="{I18N {x:Static lang:LangKeys.Action_ConsoleOutput}}" /> + MaxHeight="220" + Text="{Binding ConsoleOutput}" + x:Name="ActionConsoleOutputTextbox"> - + @@ -136,8 +146,8 @@ From b7755b79245f7f3e3b3b488df5ebd301949b7d1c Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Sun, 7 Apr 2024 16:10:31 +0800 Subject: [PATCH 02/17] perf: caught exceptions in log&cache&crushes --- src/PipManager/AppStarting.cs | 38 ++++++++++--------- .../Pages/Settings/SettingsViewModel.cs | 1 + src/PipManager/Views/Windows/MainWindow.xaml | 5 +-- 3 files changed, 23 insertions(+), 21 deletions(-) diff --git a/src/PipManager/AppStarting.cs b/src/PipManager/AppStarting.cs index a9aa8e8..dfb18ce 100644 --- a/src/PipManager/AppStarting.cs +++ b/src/PipManager/AppStarting.cs @@ -65,24 +65,26 @@ public void LogDeletion() if (!_config.Personalization.LogAutoDeletion || !Directory.Exists(AppInfo.LogDir)) return; var fileList = Directory.GetFileSystemEntries(AppInfo.LogDir); var logFileAmount = fileList.Count(file => File.Exists(file) && file.EndsWith(".txt")); - if (logFileAmount >= _config.Personalization.LogAutoDeletionTimes) + if (logFileAmount < _config.Personalization.LogAutoDeletionTimes) { - var directoryInfo = new DirectoryInfo(AppInfo.LogDir); - var filesInfo = directoryInfo.GetFileSystemInfos(); - foreach (var file in filesInfo) + return; + } + + var directoryInfo = new DirectoryInfo(AppInfo.LogDir); + var filesInfo = directoryInfo.GetFileSystemInfos(); + foreach (var file in filesInfo) + { + if (file.Extension != ".txt") continue; + try + { + File.Delete(file.FullName); + } + catch { - if (file.Extension != ".txt") continue; - try - { - File.Delete(file.FullName); - } - catch - { - // ignored - } + Log.Warning("Failed to delete log: {FileFullName}", file.FullName); } - Log.Information($"{logFileAmount} log file(s) deleted"); } + Log.Information($"{logFileAmount} log file(s) deleted"); } public void CrushesDeletion() @@ -106,7 +108,7 @@ public void CrushesDeletion() } catch { - // ignored + Log.Warning("Failed to delete crush file: {FileFullName}", file.FullName); } } Log.Information($"{crushFileAmount} crush file(s) deleted"); @@ -124,9 +126,9 @@ public void CachesDeletion() { subDir.Delete(true); } - catch (Exception) + catch { - // ignored + Log.Warning("Failed to delete cache directory: {DirFullName}", subDir.FullName); } } foreach (var file in filesInfo) @@ -143,7 +145,7 @@ public void CachesDeletion() } catch { - // ignored + Log.Warning("Failed to delete cache file: {FileFullName}", file.FullName); } } Log.Information($"{cacheFileAmount} cache file(s) deleted"); diff --git a/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs b/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs index ffe0275..1899124 100644 --- a/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs @@ -11,6 +11,7 @@ using System.Globalization; using System.IO; using System.Net.Http; +using PipManager.Views.Windows; using Wpf.Ui; using Wpf.Ui.Appearance; using Wpf.Ui.Controls; diff --git a/src/PipManager/Views/Windows/MainWindow.xaml b/src/PipManager/Views/Windows/MainWindow.xaml index 776aa14..66adb33 100644 --- a/src/PipManager/Views/Windows/MainWindow.xaml +++ b/src/PipManager/Views/Windows/MainWindow.xaml @@ -10,7 +10,6 @@ WindowBackdropType="Mica" WindowCornerPreference="Round" WindowStartupLocation="CenterScreen" - WindowState="Normal" d:DataContext="{d:DesignInstance local:MainWindow, IsDesignTimeCreatable=True}" d:DesignHeight="700" @@ -114,8 +113,8 @@ + Title="{Binding ViewModel.ApplicationTitle}" + x:Name="TitleBar"> From 40bd7df5b7cd3d503428a1c5407542a79295de04 Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Tue, 9 Apr 2024 17:08:57 +0800 Subject: [PATCH 03/17] refactor: ActionService --- src/PipManager/Models/Package/PackageItem.cs | 1 + .../Services/Action/ActionService.cs | 78 +++++-------------- .../Environment/EnvironmentService.cs | 1 + 3 files changed, 20 insertions(+), 60 deletions(-) diff --git a/src/PipManager/Models/Package/PackageItem.cs b/src/PipManager/Models/Package/PackageItem.cs index d527f36..9267b31 100644 --- a/src/PipManager/Models/Package/PackageItem.cs +++ b/src/PipManager/Models/Package/PackageItem.cs @@ -4,6 +4,7 @@ namespace PipManager.Models.Package; public class PackageItem { + public string? Priority { get; set; } public string? Name { get; set; } public string? Version { get; set; } public PackageVersion? DetailedVersion { get; set; } diff --git a/src/PipManager/Services/Action/ActionService.cs b/src/PipManager/Services/Action/ActionService.cs index 7cfd836..a1d1093 100644 --- a/src/PipManager/Services/Action/ActionService.cs +++ b/src/PipManager/Services/Action/ActionService.cs @@ -32,6 +32,19 @@ public string TryCancelOperation(string operationId) ActionList.Remove(ActionList[targetAction]); return Lang.Action_OperationCanceled_Success; } + + private static void ConsoleOutputUpdater(ref bool currentActionRunning, ref ActionListItem currentAction, string? data) + { + if (!currentActionRunning && !string.IsNullOrEmpty(data)) + { + currentAction.ConsoleOutput = data.Trim(); + currentActionRunning = true; + } + else if (!string.IsNullOrEmpty(data)) + { + currentAction.ConsoleOutput += '\n' + data.Trim(); + } + } public void Runner() { @@ -52,18 +65,7 @@ public void Runner() foreach (var item in queue) { currentAction.OperationStatus = $"Uninstalling {item}"; - var result = environmentService.Uninstall(item, (_, eventArgs) => - { - if (!currentActionRunning && !string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput = eventArgs.Data.Trim(); - currentActionRunning = true; - } - else if (!string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput += '\n' + eventArgs.Data.Trim(); - } - }); + var result = environmentService.Uninstall(item, (_, eventArgs) => ConsoleOutputUpdater(ref currentActionRunning, ref currentAction, eventArgs.Data)); currentAction.CompletedSubTaskNumber++; Log.Information(result.Success ? $"[Runner] {item} uninstall sub-task completed" @@ -79,18 +81,7 @@ public void Runner() foreach (var item in queue) { currentAction.OperationStatus = $"Installing {item}"; - var result = environmentService.Install(item, (_, eventArgs) => - { - if (!currentActionRunning && !string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput = eventArgs.Data.Trim(); - currentActionRunning = true; - } - else if (!string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput += '\n' + eventArgs.Data.Trim(); - } - }, extraParameters: currentAction.ExtraParameters); + var result = environmentService.Install(item, (_, eventArgs) => ConsoleOutputUpdater(ref currentActionRunning, ref currentAction, eventArgs.Data), extraParameters: currentAction.ExtraParameters); currentAction.CompletedSubTaskNumber++; if (!result.Success) { @@ -110,18 +101,7 @@ public void Runner() var requirementsTempFilePath = Path.Combine(AppInfo.CachesDir, $"temp_install_requirements_{currentAction.OperationId}.txt"); File.WriteAllText(requirementsTempFilePath, currentAction.OperationCommand[0]); currentAction.OperationStatus = "Installing from requirements.txt"; - var result = environmentService.InstallByRequirements(requirementsTempFilePath, (_, eventArgs) => - { - if (!currentActionRunning && !string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput = eventArgs.Data.Trim(); - currentActionRunning = true; - } - else if (!string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput += '\n' + eventArgs.Data.Trim(); - } - }); + var result = environmentService.InstallByRequirements(requirementsTempFilePath, (_, eventArgs) => ConsoleOutputUpdater(ref currentActionRunning, ref currentAction, eventArgs.Data)); if (!result.Success) { errorDetection = true; @@ -137,18 +117,7 @@ public void Runner() foreach (var item in queue) { currentAction.OperationStatus = $"Downloading {item}"; - var result = environmentService.Download(item, currentAction.Path, (_, eventArgs) => - { - if (!currentActionRunning && !string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput = eventArgs.Data.Trim(); - currentActionRunning = true; - } - else if (!string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput += '\n' + eventArgs.Data.Trim(); - } - }, extraParameters: currentAction.ExtraParameters); + var result = environmentService.Download(item, currentAction.Path, (_, eventArgs) => ConsoleOutputUpdater(ref currentActionRunning, ref currentAction, eventArgs.Data), extraParameters: currentAction.ExtraParameters); currentAction.CompletedSubTaskNumber++; if (!result.Success) { @@ -169,18 +138,7 @@ public void Runner() foreach (var item in queue) { currentAction.OperationStatus = $"Updating {item}"; - var result = environmentService.Update(item, (_, eventArgs) => - { - if (!currentActionRunning && !string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput = eventArgs.Data.Trim(); - currentActionRunning = true; - } - else if (!string.IsNullOrEmpty(eventArgs.Data)) - { - currentAction.ConsoleOutput += '\n' + eventArgs.Data.Trim(); - } - }); + var result = environmentService.Update(item, (_, eventArgs) => ConsoleOutputUpdater(ref currentActionRunning, ref currentAction, eventArgs.Data)); currentAction.CompletedSubTaskNumber++; if (!result.Success) { diff --git a/src/PipManager/Services/Environment/EnvironmentService.cs b/src/PipManager/Services/Environment/EnvironmentService.cs index 573cb8c..0e1dbd1 100644 --- a/src/PipManager/Services/Environment/EnvironmentService.cs +++ b/src/PipManager/Services/Environment/EnvironmentService.cs @@ -70,6 +70,7 @@ public ActionResponse PurgeEnvironmentCache(EnvironmentItem environmentItem) var packageDirInfo = new DirectoryInfo(Path.Combine( Path.GetDirectoryName(configurationService.AppConfig.CurrentEnvironment!.PythonPath)!, @"Lib\site-packages")); + var packages = new ConcurrentBag(); var ioTaskList = new List(); var distInfoDirectories = packageDirInfo.GetDirectories() From 7e1d72676cca182be646468f5a811ff8db111a61 Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Thu, 11 Apr 2024 10:00:23 +0800 Subject: [PATCH 04/17] refactor: disable customized `totalSubTaskNumber` --- src/PipManager/Models/Action/ActionListItem.cs | 6 +++--- .../ViewModels/Pages/Environment/EnvironmentViewModel.cs | 3 +-- src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs | 1 - .../ViewModels/Pages/Library/LibraryInstallViewModel.cs | 7 ++----- .../ViewModels/Pages/Library/LibraryViewModel.cs | 6 ++---- 5 files changed, 8 insertions(+), 15 deletions(-) diff --git a/src/PipManager/Models/Action/ActionListItem.cs b/src/PipManager/Models/Action/ActionListItem.cs index 01b56ce..d761006 100644 --- a/src/PipManager/Models/Action/ActionListItem.cs +++ b/src/PipManager/Models/Action/ActionListItem.cs @@ -5,12 +5,12 @@ namespace PipManager.Models.Action; public partial class ActionListItem : ObservableObject { - public ActionListItem(ActionType operationType, string[] operationCommand, string displayCommand = "", string path = "", string[]? extraParameters = null, bool progressIntermediate = false, int totalSubTaskNumber = 1) + public ActionListItem(ActionType operationType, string[] operationCommand, string displayCommand = "", string path = "", string[]? extraParameters = null, bool progressIntermediate = false) { OperationType = operationType; OperationCommand = operationCommand; ProgressIntermediate = progressIntermediate; - TotalSubTaskNumber = totalSubTaskNumber; + TotalSubTaskNumber = operationCommand.Length; Path = path; ExtraParameters = extraParameters; DisplayCommand = displayCommand switch @@ -68,7 +68,7 @@ public ActionListItem(ActionType operationType, string[] operationCommand, strin [ObservableProperty] [NotifyPropertyChangedFor(nameof(ProgressBarValue))] - private int _totalSubTaskNumber = 1; + private int _totalSubTaskNumber; [ObservableProperty] [NotifyPropertyChangedFor(nameof(ProgressBarValue))] diff --git a/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs b/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs index c87d8a6..40e1176 100644 --- a/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Environment/EnvironmentViewModel.cs @@ -132,8 +132,7 @@ await Task.Run(async () => ( ActionType.Update, ["pip"], - progressIntermediate: false, - totalSubTaskNumber: 1 + progressIntermediate: false )); navigationService.Navigate(typeof(ActionPage)); configurationService.RefreshAllEnvironmentVersions(); diff --git a/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs b/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs index f461853..c791709 100644 --- a/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs @@ -17,7 +17,6 @@ private void ActionTest() ( ActionType.Install, ["pytorch"], - totalSubTaskNumber: 1, progressIntermediate: false )); } diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs index 185a0f0..06fce3a 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs @@ -124,8 +124,7 @@ private void AddDefaultToAction() _actionService.AddOperation(new ActionListItem ( ActionType.Install, - operationCommand.ToArray(), - totalSubTaskNumber: operationCommand.Count + operationCommand.ToArray() )); PreInstallPackages.Clear(); } @@ -259,8 +258,7 @@ private void DownloadDistributionsToAction() ActionType.Download, operationCommand.ToArray(), path: DownloadDistributionsFolderPath, - extraParameters: DownloadWheelDependencies ? null : ["--no-deps"], - totalSubTaskNumber: operationCommand.Count + extraParameters: DownloadWheelDependencies ? null : ["--no-deps"] )); PreDownloadPackages.Clear(); _navigationService.Navigate(typeof(ActionPage)); @@ -422,7 +420,6 @@ private void InstallDistributionsToAction() ( ActionType.Install, operationCommand.ToArray(), - totalSubTaskNumber: operationCommand.Count, extraParameters: DownloadWheelDependencies ? null : ["--no-deps"] )); PreInstallDistributions.Clear(); diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs index 2628ecb..289e957 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs @@ -95,8 +95,7 @@ private async Task DeletePackageAsync() ( ActionType.Uninstall, command.Trim().Split(' '), - progressIntermediate: false, - totalSubTaskNumber: selected.Count + progressIntermediate: false )); _navigationService.Navigate(typeof(ActionPage)); } @@ -142,8 +141,7 @@ await Task.Run(() => ( ActionType.Update, operationList.Trim().Split(' '), - progressIntermediate: false, - totalSubTaskNumber: msgList.Count + progressIntermediate: false )); _navigationService.Navigate(typeof(ActionPage)); } From d23861927e40151d27dd6c31cb9e8efec23c598a Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Thu, 11 Apr 2024 10:02:11 +0800 Subject: [PATCH 05/17] fix: no console output while uninstalling --- src/PipManager/Services/Environment/EnvironmentService.cs | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/PipManager/Services/Environment/EnvironmentService.cs b/src/PipManager/Services/Environment/EnvironmentService.cs index 0e1dbd1..5c65039 100644 --- a/src/PipManager/Services/Environment/EnvironmentService.cs +++ b/src/PipManager/Services/Environment/EnvironmentService.cs @@ -371,9 +371,11 @@ public ActionResponse Uninstall(string packageName, DataReceivedEventHandler con }; process.OutputDataReceived += consoleOutputCallback; process.Start(); + process.BeginOutputReadLine(); var error = process.StandardError.ReadToEnd(); process.WaitForExit(); process.Close(); + process.Dispose(); return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; } From 47d48cc375a433af3988031d705f21105df126d3 Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Thu, 11 Apr 2024 10:13:25 +0800 Subject: [PATCH 06/17] refactor: basic environment command --- .../Environment/EnvironmentService.cs | 128 ++++-------------- 1 file changed, 30 insertions(+), 98 deletions(-) diff --git a/src/PipManager/Services/Environment/EnvironmentService.cs b/src/PipManager/Services/Environment/EnvironmentService.cs index 5c65039..078048b 100644 --- a/src/PipManager/Services/Environment/EnvironmentService.cs +++ b/src/PipManager/Services/Environment/EnvironmentService.cs @@ -253,116 +253,46 @@ public async Task GetVersions(string packageName) } } - public ActionResponse Install(string packageName, DataReceivedEventHandler consoleOutputCallback, string[]? extraParameters = null) - { - string? extra = extraParameters != null ? string.Join(" ", extraParameters) : null; - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = configurationService.AppConfig.CurrentEnvironment!.PythonPath, - Arguments = - $"-m pip install \"{packageName}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6 {extra}", - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true - } - }; - process.OutputDataReceived += consoleOutputCallback; - process.Start(); - process.BeginOutputReadLine(); - var error = process.StandardError.ReadToEnd(); - process.WaitForExit(); - process.Close(); - process.Dispose(); - return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; - } + #region Basic Command - public ActionResponse InstallByRequirements(string requirementsFilePath, DataReceivedEventHandler consoleOutputCallback) - { - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = configurationService.AppConfig.CurrentEnvironment!.PythonPath, - Arguments = - $"-m pip install -r \"{requirementsFilePath}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6", - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true - } - }; - process.OutputDataReceived += consoleOutputCallback; - process.Start(); - process.BeginOutputReadLine(); - var error = process.StandardError.ReadToEnd(); - process.WaitForExit(); - process.Close(); - process.Dispose(); - return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; - } + public ActionResponse Install(string packageName, DataReceivedEventHandler consoleOutputCallback, + string[]? extraParameters = null) + => RaiseProcess( + $"-m pip install \"{packageName}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6", + consoleOutputCallback, extraParameters); + + public ActionResponse InstallByRequirements(string requirementsFilePath, + DataReceivedEventHandler consoleOutputCallback) + => RaiseProcess( + $"-m pip install -r \"{requirementsFilePath}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6", + consoleOutputCallback); public ActionResponse Download(string packageName, string downloadPath, DataReceivedEventHandler consoleOutputCallback, string[]? extraParameters = null) - { - string? extra = extraParameters != null ? string.Join(" ", extraParameters) : null; - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = configurationService.AppConfig.CurrentEnvironment!.PythonPath, - Arguments = - $"-m pip download -d \"{downloadPath}\" \"{packageName}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6 {extra}", - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true - } - }; - process.OutputDataReceived += consoleOutputCallback; - process.Start(); - process.BeginOutputReadLine(); - var error = process.StandardError.ReadToEnd(); - process.WaitForExit(); - process.Close(); - process.Dispose(); - return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; - } + => RaiseProcess( + $"-m pip download -d \"{downloadPath}\" \"{packageName}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6", + consoleOutputCallback, extraParameters); public ActionResponse Update(string packageName, DataReceivedEventHandler consoleOutputCallback) - { - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = configurationService.AppConfig.CurrentEnvironment!.PythonPath, - Arguments = - $"-m pip install --upgrade \"{packageName}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6", - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true - } - }; - process.OutputDataReceived += consoleOutputCallback; - process.Start(); - process.BeginOutputReadLine(); - var error = process.StandardError.ReadToEnd(); - process.WaitForExit(); - process.Close(); - process.Dispose(); - return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; - } + => RaiseProcess( + $"-m pip install --upgrade \"{packageName}\" -i {configurationService.GetUrlFromPackageSourceType()} --retries 1 --timeout 6", + consoleOutputCallback); public ActionResponse Uninstall(string packageName, DataReceivedEventHandler consoleOutputCallback) + => RaiseProcess( + $"-m pip uninstall -y \"{packageName}\"", consoleOutputCallback); + + #endregion + + private ActionResponse RaiseProcess(string arguments, DataReceivedEventHandler consoleOutputCallback, + string[]? extraParameters = null) { + string? extra = extraParameters != null ? string.Join(" ", extraParameters) : null; var process = new Process { StartInfo = new ProcessStartInfo { FileName = configurationService.AppConfig.CurrentEnvironment!.PythonPath, - Arguments = $"-m pip uninstall -y \"{packageName}\"", + Arguments = $"{arguments} {extra}", UseShellExecute = false, RedirectStandardOutput = true, RedirectStandardError = true, @@ -379,7 +309,7 @@ public ActionResponse Uninstall(string packageName, DataReceivedEventHandler con return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; } - // Package Version Validation + #region Package Version Validation [GeneratedRegex("[-_.]+", RegexOptions.IgnoreCase)] private static partial Regex PackageNameNormalizerRegex(); @@ -389,4 +319,6 @@ public ActionResponse Uninstall(string packageName, DataReceivedEventHandler con [GeneratedRegex("^([A-Z0-9]|[A-Z0-9][A-Z0-9._-]*[A-Z0-9])$", RegexOptions.IgnoreCase)] private static partial Regex PackageNameVerificationRegex(); + + #endregion } \ No newline at end of file From f3590d6a773a3311f637bbbf05d8f8ce1bf32151 Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Thu, 11 Apr 2024 10:27:49 +0800 Subject: [PATCH 07/17] feat: cancellable running process --- src/PipManager/Languages/Lang.Designer.cs | 6 +- src/PipManager/Languages/Lang.resx | 4 +- src/PipManager/Languages/Lang.zh-cn.resx | 4 +- .../Services/Action/ActionService.cs | 6 +- .../Services/Action/IActionService.cs | 2 +- .../Environment/EnvironmentService.cs | 68 ++++++++++++------- .../Environment/IEnvironmentService.cs | 1 + .../Pages/Action/ActionViewModel.cs | 5 +- 8 files changed, 56 insertions(+), 40 deletions(-) diff --git a/src/PipManager/Languages/Lang.Designer.cs b/src/PipManager/Languages/Lang.Designer.cs index 6eaa83e..6d4a9de 100644 --- a/src/PipManager/Languages/Lang.Designer.cs +++ b/src/PipManager/Languages/Lang.Designer.cs @@ -312,11 +312,11 @@ public static string Action_Operation_Update { } /// - /// Looks up a localized string similar to Action Already Running. + /// Looks up a localized string similar to Failed to cancel. /// - public static string Action_OperationCanceled_AlreadyRunning { + public static string Action_OperationCanceled_Failed { get { - return ResourceManager.GetString("Action_OperationCanceled_AlreadyRunning", resourceCulture); + return ResourceManager.GetString("Action_OperationCanceled_Failed", resourceCulture); } } diff --git a/src/PipManager/Languages/Lang.resx b/src/PipManager/Languages/Lang.resx index ed1af42..f32a40c 100644 --- a/src/PipManager/Languages/Lang.resx +++ b/src/PipManager/Languages/Lang.resx @@ -702,8 +702,8 @@ Action Cancelled - - Action Already Running + + Failed to cancel Cancel diff --git a/src/PipManager/Languages/Lang.zh-cn.resx b/src/PipManager/Languages/Lang.zh-cn.resx index 0e72601..3f5e77e 100644 --- a/src/PipManager/Languages/Lang.zh-cn.resx +++ b/src/PipManager/Languages/Lang.zh-cn.resx @@ -702,8 +702,8 @@ 任务已取消 - - 任务已运行 + + 任务终止失败 取消 diff --git a/src/PipManager/Services/Action/ActionService.cs b/src/PipManager/Services/Action/ActionService.cs index a1d1093..def5b2a 100644 --- a/src/PipManager/Services/Action/ActionService.cs +++ b/src/PipManager/Services/Action/ActionService.cs @@ -22,15 +22,15 @@ public void AddOperation(ActionListItem actionListItem) ActionList.Add(actionListItem); } - public string TryCancelOperation(string operationId) + public bool TryCancelOperation(string operationId) { var targetAction = ActionList.ToList().FindIndex(action => action.OperationId == operationId); if (ActionList[targetAction].OperationStatus != Lang.Action_CurrentStatus_WaitingInQueue) { - return Lang.Action_OperationCanceled_AlreadyRunning; + return environmentService.TryKillProcess(); } ActionList.Remove(ActionList[targetAction]); - return Lang.Action_OperationCanceled_Success; + return true; } private static void ConsoleOutputUpdater(ref bool currentActionRunning, ref ActionListItem currentAction, string? data) diff --git a/src/PipManager/Services/Action/IActionService.cs b/src/PipManager/Services/Action/IActionService.cs index fc43d29..a2c7337 100644 --- a/src/PipManager/Services/Action/IActionService.cs +++ b/src/PipManager/Services/Action/IActionService.cs @@ -11,7 +11,7 @@ public interface IActionService public void AddOperation(ActionListItem actionListItem); - public string? TryCancelOperation(string operationId); + public bool TryCancelOperation(string operationId); public void Runner(); } \ No newline at end of file diff --git a/src/PipManager/Services/Environment/EnvironmentService.cs b/src/PipManager/Services/Environment/EnvironmentService.cs index 078048b..e1af138 100644 --- a/src/PipManager/Services/Environment/EnvironmentService.cs +++ b/src/PipManager/Services/Environment/EnvironmentService.cs @@ -252,6 +252,48 @@ public async Task GetVersions(string packageName) return new GetVersionsResponse { Status = 1, Versions = [] }; } } + + private Process? BasicCommandProcess { get; set; } + + public bool TryKillProcess() + { + if (BasicCommandProcess is null) return false; + try + { + BasicCommandProcess.Kill(); + return true; + } + catch (Exception) + { + return false; + } + } + + private ActionResponse RaiseProcess(string arguments, DataReceivedEventHandler consoleOutputCallback, + string[]? extraParameters = null) + { + string? extra = extraParameters != null ? string.Join(" ", extraParameters) : null; + BasicCommandProcess = new Process + { + StartInfo = new ProcessStartInfo + { + FileName = configurationService.AppConfig.CurrentEnvironment!.PythonPath, + Arguments = $"{arguments} {extra}", + UseShellExecute = false, + RedirectStandardOutput = true, + RedirectStandardError = true, + CreateNoWindow = true + } + }; + BasicCommandProcess.OutputDataReceived += consoleOutputCallback; + BasicCommandProcess.Start(); + BasicCommandProcess.BeginOutputReadLine(); + var error = BasicCommandProcess.StandardError.ReadToEnd(); + BasicCommandProcess.WaitForExit(); + BasicCommandProcess.Close(); + BasicCommandProcess.Dispose(); + return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; + } #region Basic Command @@ -283,32 +325,6 @@ public ActionResponse Uninstall(string packageName, DataReceivedEventHandler con #endregion - private ActionResponse RaiseProcess(string arguments, DataReceivedEventHandler consoleOutputCallback, - string[]? extraParameters = null) - { - string? extra = extraParameters != null ? string.Join(" ", extraParameters) : null; - var process = new Process - { - StartInfo = new ProcessStartInfo - { - FileName = configurationService.AppConfig.CurrentEnvironment!.PythonPath, - Arguments = $"{arguments} {extra}", - UseShellExecute = false, - RedirectStandardOutput = true, - RedirectStandardError = true, - CreateNoWindow = true - } - }; - process.OutputDataReceived += consoleOutputCallback; - process.Start(); - process.BeginOutputReadLine(); - var error = process.StandardError.ReadToEnd(); - process.WaitForExit(); - process.Close(); - process.Dispose(); - return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; - } - #region Package Version Validation [GeneratedRegex("[-_.]+", RegexOptions.IgnoreCase)] diff --git a/src/PipManager/Services/Environment/IEnvironmentService.cs b/src/PipManager/Services/Environment/IEnvironmentService.cs index 9267e32..a9e7bb9 100644 --- a/src/PipManager/Services/Environment/IEnvironmentService.cs +++ b/src/PipManager/Services/Environment/IEnvironmentService.cs @@ -16,6 +16,7 @@ public interface IEnvironmentService public Task?> GetLibraries(); public Task GetVersions(string packageName); + public bool TryKillProcess(); public ActionResponse Install(string packageName, DataReceivedEventHandler consoleOutputCallback, string[]? extraParameters = null); diff --git a/src/PipManager/ViewModels/Pages/Action/ActionViewModel.cs b/src/PipManager/ViewModels/Pages/Action/ActionViewModel.cs index bc4300c..929f05b 100644 --- a/src/PipManager/ViewModels/Pages/Action/ActionViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Action/ActionViewModel.cs @@ -59,10 +59,9 @@ private void CancelAction(string? operationId) return; } - var result = _actionService.TryCancelOperation(operationId); - if(result == Lang.Action_OperationCanceled_AlreadyRunning) + if(!_actionService.TryCancelOperation(operationId)) { - _toastService.Error(Lang.Action_OperationCanceled_AlreadyRunning); + _toastService.Error(Lang.Action_OperationCanceled_Failed); Log.Warning("[Action] Operation cancellation failed (already running): {OperationId}", operationId); } else From c3892e52b9d1e8692a1f593d014f2bb4ef996bc4 Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Thu, 11 Apr 2024 15:51:20 +0800 Subject: [PATCH 08/17] refactor: remove redundant code --- src/PipManager/PipManager.csproj | 2 +- .../Pages/Library/LibraryDetailViewModel.cs | 2 +- .../Pages/Library/LibraryInstallViewModel.cs | 2 +- .../Pages/Library/LibraryViewModel.cs | 1 - .../Pages/Search/SearchDetailViewModel.cs | 17 +++++++---- .../Pages/Search/SearchViewModel.cs | 30 ++++++++++--------- .../Pages/Settings/SettingsViewModel.cs | 1 - 7 files changed, 30 insertions(+), 25 deletions(-) diff --git a/src/PipManager/PipManager.csproj b/src/PipManager/PipManager.csproj index c8ebb3d..196f3de 100644 --- a/src/PipManager/PipManager.csproj +++ b/src/PipManager/PipManager.csproj @@ -65,7 +65,7 @@ Lang.Designer.cs - + PublicResXFileCodeGenerator diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryDetailViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryDetailViewModel.cs index 56a9712..95af72f 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryDetailViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryDetailViewModel.cs @@ -56,7 +56,7 @@ private void InitializeViewModel() _isInitialized = true; } - public void Receive(object recipient, LibraryDetailMessage message) + private void Receive(object recipient, LibraryDetailMessage message) { Package = message.Package; diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs index 06fce3a..6f650a3 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs @@ -62,7 +62,7 @@ private void InitializeViewModel() _isInitialized = true; } - public void Receive(object recipient, InstalledPackagesMessage message) + private void Receive(object recipient, InstalledPackagesMessage message) { _installedPackages = message.InstalledPackages; } diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs index 289e957..33b302e 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs @@ -167,7 +167,6 @@ private void ToDetailPage(object parameter) [ObservableProperty] private ObservableCollection _libraryList = []; [ObservableProperty] private bool _environmentFoundVisible; - [ObservableProperty] private bool _listVisible; [RelayCommand] private void NavigateToAddEnvironment() diff --git a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs index a49b5e9..eb5a9e1 100644 --- a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs @@ -11,6 +11,7 @@ using System.Drawing; using System.Net.Http; using Wpf.Ui; +using Wpf.Ui.Appearance; using Wpf.Ui.Controls; namespace PipManager.ViewModels.Pages.Search; @@ -35,7 +36,7 @@ public record SearchDetailMessage(QueryListItemModel Package); private int _themeTypeInInteger = 16448250; - private const string _htmlModel = """ + private const string HtmlModel = """ @@ -72,17 +73,21 @@ public void OnNavigatedTo() _navigationService.GetNavigationControl().BreadcrumbBar!.Visibility = Visibility.Collapsed; switch (_themeService.GetTheme()) { - case Wpf.Ui.Appearance.ApplicationTheme.Light: + case ApplicationTheme.Light: _themeType = "light"; ThemeTypeInHex = "#FFFFFF"; _themeTypeInInteger = 16777215; break; - case Wpf.Ui.Appearance.ApplicationTheme.Dark: + 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); } @@ -118,7 +123,7 @@ private async Task InstallPackage() } } - public void Receive(object recipient, SearchDetailMessage message) + private void Receive(object recipient, SearchDetailMessage message) { Package = message.Package; @@ -149,7 +154,7 @@ public void Receive(object recipient, SearchDetailMessage message) 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); + 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); @@ -158,7 +163,7 @@ public void Receive(object recipient, SearchDetailMessage message) { Log.Error(ex.Message); _toastService.Error(Lang.SearchDetail_ProjectDescription_LoadFailed); - string projectDescriptionHtml = string.Format(_htmlModel, _themeType, ThemeTypeInHex, $"

{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); diff --git a/src/PipManager/ViewModels/Pages/Search/SearchViewModel.cs b/src/PipManager/ViewModels/Pages/Search/SearchViewModel.cs index d16c340..2361be0 100644 --- a/src/PipManager/ViewModels/Pages/Search/SearchViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Search/SearchViewModel.cs @@ -74,7 +74,7 @@ private void ToDetailPage(object parameter) #endregion Details [RelayCommand] - public async Task ToPreviousPage() + private async Task ToPreviousPage() { if (CurrentPage == 1) { @@ -89,7 +89,7 @@ public async Task ToPreviousPage() } [RelayCommand] - public async Task ToNextPage() + private async Task ToNextPage() { if (CurrentPage == MaxPage) { @@ -113,12 +113,9 @@ private void Process(QueryWrapper queryWrapper) { if (queryWrapper.Status == QueryStatus.Success) { - foreach (var resultItem in queryWrapper.Results!) + foreach (var resultItem in queryWrapper.Results!.Where(resultItem => string.IsNullOrEmpty(resultItem.Description))) { - if (string.IsNullOrEmpty(resultItem.Description)) - { - resultItem.Description = Lang.Search_List_NoDescription; - } + resultItem.Description = Lang.Search_List_NoDescription; } QueryList = new ObservableCollection(queryWrapper.Results!); TotalResultNumber = queryWrapper.ResultCount!; @@ -128,13 +125,18 @@ private void Process(QueryWrapper queryWrapper) } else { - if (queryWrapper.Status == QueryStatus.NoResults) + switch (queryWrapper.Status) { - toastService.Error(Lang.Search_Query_NoResults); - } - else if (queryWrapper.Status == QueryStatus.Timeout) - { - toastService.Error(Lang.Search_Query_Timeout); + case QueryStatus.NoResults: + toastService.Error(Lang.Search_Query_NoResults); + break; + case QueryStatus.Timeout: + toastService.Error(Lang.Search_Query_Timeout); + break; + case QueryStatus.Success: + break; + default: + throw new ArgumentOutOfRangeException(); } QueryList.Clear(); TotalResultNumber = ""; @@ -144,7 +146,7 @@ private void Process(QueryWrapper queryWrapper) } [RelayCommand] - public async Task Search(string? parameter) + private async Task Search(string? parameter) { if (parameter != null && !string.IsNullOrEmpty(parameter)) { diff --git a/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs b/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs index 1899124..ffe0275 100644 --- a/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Settings/SettingsViewModel.cs @@ -11,7 +11,6 @@ using System.Globalization; using System.IO; using System.Net.Http; -using PipManager.Views.Windows; using Wpf.Ui; using Wpf.Ui.Appearance; using Wpf.Ui.Controls; From 94e86e09798a920332856cd3f2cdcd7928f37e4a Mon Sep 17 00:00:00 2001 From: Mccree Lee <2935876049@qq.com> Date: Fri, 12 Apr 2024 23:50:15 +0800 Subject: [PATCH 09/17] feat: Overlay (part) --- src/PipManager/App.xaml | 4 +- src/PipManager/App.xaml.cs | 7 + src/PipManager/PipManager.csproj | 1 + src/PipManager/Resources/Animations.xaml | 259 ++++++++++++++++++ .../Services/Overlay/IOverlayService.cs | 6 + .../Services/Overlay/OverlayService.cs | 16 ++ .../ViewModels/Pages/Lab/LabViewModel.cs | 9 +- .../Pages/Overlay/OverlayViewModel.cs | 18 ++ src/PipManager/Views/Pages/Lab/LabPage.xaml | 2 +- .../Views/Pages/Overlay/OverlayPage.xaml | 23 ++ .../Views/Pages/Overlay/OverlayPage.xaml.cs | 16 ++ .../Views/Pages/Settings/SettingsPage.xaml | 3 +- src/PipManager/Views/Windows/MainWindow.xaml | 10 +- 13 files changed, 364 insertions(+), 10 deletions(-) create mode 100644 src/PipManager/Resources/Animations.xaml create mode 100644 src/PipManager/Services/Overlay/IOverlayService.cs create mode 100644 src/PipManager/Services/Overlay/OverlayService.cs create mode 100644 src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs create mode 100644 src/PipManager/Views/Pages/Overlay/OverlayPage.xaml create mode 100644 src/PipManager/Views/Pages/Overlay/OverlayPage.xaml.cs diff --git a/src/PipManager/App.xaml b/src/PipManager/App.xaml index 3c7c0a3..ad3dcdf 100644 --- a/src/PipManager/App.xaml +++ b/src/PipManager/App.xaml @@ -4,6 +4,7 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:valueConverters="clr-namespace:ValueConverters;assembly=ValueConverters" + xmlns:xamlFlair="clr-namespace:XamlFlair;assembly=XamlFlair.WPF" DispatcherUnhandledException="OnDispatcherUnhandledException" Exit="OnExit" Startup="OnStartup"> @@ -13,7 +14,8 @@ - + + diff --git a/src/PipManager/App.xaml.cs b/src/PipManager/App.xaml.cs index 56f99d6..be3d1ac 100644 --- a/src/PipManager/App.xaml.cs +++ b/src/PipManager/App.xaml.cs @@ -31,6 +31,9 @@ using System.Net.Http; using System.Runtime.InteropServices; using System.Windows.Threading; +using PipManager.Services.Overlay; +using PipManager.ViewModels.Pages.Overlay; +using PipManager.Views.Pages.Overlay; using Wpf.Ui; using AboutViewModel = PipManager.ViewModels.Pages.About.AboutViewModel; using ActionViewModel = PipManager.ViewModels.Pages.Action.ActionViewModel; @@ -74,6 +77,7 @@ public partial class App services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); @@ -90,6 +94,9 @@ public partial class App services.AddSingleton(); services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); + services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/PipManager/PipManager.csproj b/src/PipManager/PipManager.csproj index 196f3de..c3c2025 100644 --- a/src/PipManager/PipManager.csproj +++ b/src/PipManager/PipManager.csproj @@ -43,6 +43,7 @@ + diff --git a/src/PipManager/Resources/Animations.xaml b/src/PipManager/Resources/Animations.xaml new file mode 100644 index 0000000..56a6145 --- /dev/null +++ b/src/PipManager/Resources/Animations.xaml @@ -0,0 +1,259 @@ + + + 24 + 0.75 + 1.25 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/PipManager/Services/Overlay/IOverlayService.cs b/src/PipManager/Services/Overlay/IOverlayService.cs new file mode 100644 index 0000000..b0dba65 --- /dev/null +++ b/src/PipManager/Services/Overlay/IOverlayService.cs @@ -0,0 +1,6 @@ +namespace PipManager.Services.Overlay; + +public interface IOverlayService +{ + public void ShowOverlay(); +} diff --git a/src/PipManager/Services/Overlay/OverlayService.cs b/src/PipManager/Services/Overlay/OverlayService.cs new file mode 100644 index 0000000..94a9b16 --- /dev/null +++ b/src/PipManager/Services/Overlay/OverlayService.cs @@ -0,0 +1,16 @@ +using PipManager.ViewModels.Pages.Overlay; + +namespace PipManager.Services.Overlay; + +public class OverlayService: IOverlayService +{ + private OverlayViewModel _overlayViewModel; + public OverlayService(OverlayViewModel overlayViewModel) + { + _overlayViewModel = overlayViewModel; + } + public void ShowOverlay() + { + _overlayViewModel.IsOverlayVisible = true; + } +} diff --git a/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs b/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs index c791709..58437a1 100644 --- a/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs @@ -1,11 +1,12 @@ using PipManager.Models.Action; using PipManager.Services.Action; +using PipManager.Services.Overlay; using Serilog; using Wpf.Ui.Controls; namespace PipManager.ViewModels.Pages.Lab; -public partial class LabViewModel(IActionService actionService) +public partial class LabViewModel(IActionService actionService, IOverlayService overlayService) : ObservableObject, INavigationAware { private bool _isInitialized; @@ -21,6 +22,12 @@ private void ActionTest() )); } + [RelayCommand] + private void OverlayTest() + { + overlayService.ShowOverlay(); + } + public void OnNavigatedTo() { if (!_isInitialized) diff --git a/src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs b/src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs new file mode 100644 index 0000000..34c7667 --- /dev/null +++ b/src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs @@ -0,0 +1,18 @@ +using PipManager.Views.Pages.Overlay; + +namespace PipManager.ViewModels.Pages.Overlay; + +public partial class OverlayViewModel : ObservableObject +{ + [ObservableProperty] + private int _testValue; + + [ObservableProperty] + private bool _isOverlayVisible; + + [RelayCommand] + private void CloseOverlay() + { + IsOverlayVisible = false; + } +} diff --git a/src/PipManager/Views/Pages/Lab/LabPage.xaml b/src/PipManager/Views/Pages/Lab/LabPage.xaml index c91aa61..f151b16 100644 --- a/src/PipManager/Views/Pages/Lab/LabPage.xaml +++ b/src/PipManager/Views/Pages/Lab/LabPage.xaml @@ -18,6 +18,6 @@ mc:Ignorable="d"> - +
\ No newline at end of file diff --git a/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml new file mode 100644 index 0000000..009c29e --- /dev/null +++ b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml @@ -0,0 +1,23 @@ + + + + + + + + + diff --git a/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml.cs b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml.cs new file mode 100644 index 0000000..2dee178 --- /dev/null +++ b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml.cs @@ -0,0 +1,16 @@ +using System.Windows.Controls; +using PipManager.ViewModels.Pages.Overlay; + +namespace PipManager.Views.Pages.Overlay; + +public partial class OverlayPage +{ + public OverlayViewModel ViewModel { get; } + + public OverlayPage() + { + ViewModel = App.GetService(); + DataContext = this; + InitializeComponent(); + } +} diff --git a/src/PipManager/Views/Pages/Settings/SettingsPage.xaml b/src/PipManager/Views/Pages/Settings/SettingsPage.xaml index 899bba2..4f482f2 100644 --- a/src/PipManager/Views/Pages/Settings/SettingsPage.xaml +++ b/src/PipManager/Views/Pages/Settings/SettingsPage.xaml @@ -18,7 +18,8 @@ xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" xmlns:settings="clr-namespace:PipManager.Views.Pages.Settings" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:xamlFlair="clr-namespace:XamlFlair;assembly=XamlFlair.WPF"> diff --git a/src/PipManager/Views/Windows/MainWindow.xaml b/src/PipManager/Views/Windows/MainWindow.xaml index 66adb33..d21dd38 100644 --- a/src/PipManager/Views/Windows/MainWindow.xaml +++ b/src/PipManager/Views/Windows/MainWindow.xaml @@ -34,7 +34,8 @@ xmlns:tools="clr-namespace:PipManager.Views.Pages.Tools" xmlns:tray="http://schemas.lepo.co/wpfui/2022/xaml/tray" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"> + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" + xmlns:overlay="clr-namespace:PipManager.Views.Pages.Overlay"> @@ -98,11 +99,8 @@ Grid.Row="0" Grid.RowSpan="2" x:Name="MaskPresenter" /> - - + + Date: Sun, 14 Apr 2024 18:52:53 +0800 Subject: [PATCH 10/17] feat: Overlay (part) --- .../PipManager.PackageSearch.csproj | 2 +- src/PipManager/App.xaml.cs | 2 - .../Models/Package/PackageUpdateItem.cs | 11 +++++ src/PipManager/PipManager.csproj | 5 +- .../Library/DeletionWarningContentDialog.cs | 2 +- .../Library/InstallAddContentDialog.cs | 2 +- .../Services/Overlay/IOverlayService.cs | 6 --- .../Services/Overlay/OverlayService.cs | 16 ------ .../ViewModels/Pages/Lab/LabViewModel.cs | 11 +---- .../Pages/Library/LibraryInstallViewModel.cs | 4 +- .../Pages/Library/LibraryViewModel.cs | 32 ++++++------ .../Pages/Overlay/OverlayViewModel.cs | 33 +++++++++++-- .../Views/Pages/Library/LibraryPage.xaml | 34 ++++++------- .../Views/Pages/Overlay/OverlayPage.xaml | 49 +++++++++++++++---- 14 files changed, 124 insertions(+), 85 deletions(-) create mode 100644 src/PipManager/Models/Package/PackageUpdateItem.cs delete mode 100644 src/PipManager/Services/Overlay/IOverlayService.cs delete mode 100644 src/PipManager/Services/Overlay/OverlayService.cs diff --git a/src/PipManager.PackageSearch/PipManager.PackageSearch.csproj b/src/PipManager.PackageSearch/PipManager.PackageSearch.csproj index 9c60061..2523916 100644 --- a/src/PipManager.PackageSearch/PipManager.PackageSearch.csproj +++ b/src/PipManager.PackageSearch/PipManager.PackageSearch.csproj @@ -19,7 +19,7 @@ - + diff --git a/src/PipManager/App.xaml.cs b/src/PipManager/App.xaml.cs index be3d1ac..f3a2384 100644 --- a/src/PipManager/App.xaml.cs +++ b/src/PipManager/App.xaml.cs @@ -31,7 +31,6 @@ using System.Net.Http; using System.Runtime.InteropServices; using System.Windows.Threading; -using PipManager.Services.Overlay; using PipManager.ViewModels.Pages.Overlay; using PipManager.Views.Pages.Overlay; using Wpf.Ui; @@ -77,7 +76,6 @@ public partial class App services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); - services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); services.AddSingleton(); diff --git a/src/PipManager/Models/Package/PackageUpdateItem.cs b/src/PipManager/Models/Package/PackageUpdateItem.cs new file mode 100644 index 0000000..4089d3d --- /dev/null +++ b/src/PipManager/Models/Package/PackageUpdateItem.cs @@ -0,0 +1,11 @@ +using PipManager.Languages; +using PipManager.Models.Pages; + +namespace PipManager.Models.Package; + +public class PackageUpdateItem(LibraryListItem libraryListItem, string newVersion) +{ + public string PackageName { get; set; } = libraryListItem.PackageName; + public string PackageVersion { get; set; } = string.Format(Lang.Library_CheckUpdate_Current, libraryListItem.PackageVersion); + public string NewVersion { get; set; } = string.Format(Lang.Library_CheckUpdate_Latest, newVersion); +} diff --git a/src/PipManager/PipManager.csproj b/src/PipManager/PipManager.csproj index c3c2025..0ef5769 100644 --- a/src/PipManager/PipManager.csproj +++ b/src/PipManager/PipManager.csproj @@ -28,7 +28,6 @@ - @@ -39,10 +38,10 @@ - + - + diff --git a/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs b/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs index 7590f80..aa0afeb 100644 --- a/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs +++ b/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs @@ -10,7 +10,7 @@ public class DeletionWarningContentDialog private readonly ContentDialog _contentDialog; public List LibraryList { get; set; } - public DeletionWarningContentDialog(ContentPresenter contentPresenter, List libraryList) + public DeletionWarningContentDialog(ContentPresenter? contentPresenter, List libraryList) { LibraryList = libraryList; _contentDialog = new ContentDialog(contentPresenter) diff --git a/src/PipManager/Resources/Library/InstallAddContentDialog.cs b/src/PipManager/Resources/Library/InstallAddContentDialog.cs index 705937e..44b7ed1 100644 --- a/src/PipManager/Resources/Library/InstallAddContentDialog.cs +++ b/src/PipManager/Resources/Library/InstallAddContentDialog.cs @@ -5,7 +5,7 @@ namespace PipManager.Resources.Library; -public class InstallAddContentDialog(ContentPresenter contentPresenter) +public class InstallAddContentDialog(ContentPresenter? contentPresenter) { private readonly ContentDialog _contentDialog = new(contentPresenter) { diff --git a/src/PipManager/Services/Overlay/IOverlayService.cs b/src/PipManager/Services/Overlay/IOverlayService.cs deleted file mode 100644 index b0dba65..0000000 --- a/src/PipManager/Services/Overlay/IOverlayService.cs +++ /dev/null @@ -1,6 +0,0 @@ -namespace PipManager.Services.Overlay; - -public interface IOverlayService -{ - public void ShowOverlay(); -} diff --git a/src/PipManager/Services/Overlay/OverlayService.cs b/src/PipManager/Services/Overlay/OverlayService.cs deleted file mode 100644 index 94a9b16..0000000 --- a/src/PipManager/Services/Overlay/OverlayService.cs +++ /dev/null @@ -1,16 +0,0 @@ -using PipManager.ViewModels.Pages.Overlay; - -namespace PipManager.Services.Overlay; - -public class OverlayService: IOverlayService -{ - private OverlayViewModel _overlayViewModel; - public OverlayService(OverlayViewModel overlayViewModel) - { - _overlayViewModel = overlayViewModel; - } - public void ShowOverlay() - { - _overlayViewModel.IsOverlayVisible = true; - } -} diff --git a/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs b/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs index 58437a1..eb63223 100644 --- a/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs @@ -1,12 +1,12 @@ using PipManager.Models.Action; using PipManager.Services.Action; -using PipManager.Services.Overlay; +using PipManager.ViewModels.Pages.Overlay; using Serilog; using Wpf.Ui.Controls; namespace PipManager.ViewModels.Pages.Lab; -public partial class LabViewModel(IActionService actionService, IOverlayService overlayService) +public partial class LabViewModel(IActionService actionService) : ObservableObject, INavigationAware { private bool _isInitialized; @@ -21,13 +21,6 @@ private void ActionTest() progressIntermediate: false )); } - - [RelayCommand] - private void OverlayTest() - { - overlayService.ShowOverlay(); - } - public void OnNavigatedTo() { if (!_isInitialized) diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs index 6f650a3..b6bf582 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs @@ -75,7 +75,7 @@ private void Receive(object recipient, InstalledPackagesMessage message) [RelayCommand] private async Task AddDefaultTask() { - var custom = new InstallAddContentDialog(_contentDialogService.GetContentPresenter()); + var custom = new InstallAddContentDialog(_contentDialogService.GetDialogHost()); var packageName = await custom.ShowAsync(); if (packageName == "") { @@ -196,7 +196,7 @@ private void AddRequirementsToAction() [RelayCommand] private async Task DownloadDistributionsTask() { - var custom = new InstallAddContentDialog(_contentDialogService.GetContentPresenter()); + var custom = new InstallAddContentDialog(_contentDialogService.GetDialogHost()); var packageName = await custom.ShowAsync(); if (packageName == "") { diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs index 33b302e..3f87a7d 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryViewModel.cs @@ -14,6 +14,8 @@ using PipManager.Views.Pages.Library; using Serilog; using System.Collections.ObjectModel; +using System.IO.Packaging; +using PipManager.ViewModels.Pages.Overlay; using Wpf.Ui; using Wpf.Ui.Appearance; using Wpf.Ui.Controls; @@ -33,8 +35,9 @@ public partial class LibraryViewModel : ObservableObject, INavigationAware private readonly IMaskService _maskService; private readonly IToastService _toastService; private readonly IContentDialogService _contentDialogService; + private readonly OverlayViewModel _overlayViewModel; - public LibraryViewModel(INavigationService navigationService, IEnvironmentService environmentService, + public LibraryViewModel(INavigationService navigationService, IEnvironmentService environmentService, OverlayViewModel overlayViewModel, IConfigurationService configurationService, IActionService actionService, IThemeService themeService, IMaskService maskService, IToastService toastService, IContentDialogService contentDialogService) { _navigationService = navigationService; @@ -44,6 +47,7 @@ public LibraryViewModel(INavigationService navigationService, IEnvironmentServic _maskService = maskService; _toastService = toastService; _contentDialogService = contentDialogService; + _overlayViewModel = overlayViewModel; themeService.SetTheme(_configurationService.AppConfig.Personalization.Theme switch { @@ -87,7 +91,7 @@ private void InstallPackage() private async Task DeletePackageAsync() { var selected = LibraryList.Where(libraryListItem => libraryListItem.IsSelected).ToList(); - var custom = new DeletionWarningContentDialog(_contentDialogService.GetContentPresenter(), selected); + var custom = new DeletionWarningContentDialog(_contentDialogService.GetDialogHost(), selected); var result = await custom.ShowAsync(); var command = selected.Aggregate("", (current, item) => current + (item.PackageName + ' ')); if (result != ContentDialogResult.Primary) return; @@ -108,7 +112,7 @@ private async Task DeletePackageAsync() private async Task CheckUpdate() { _maskService.Show(Lang.Library_Operation_CheckUpdate); - var msgList = new List(); + var msgList = new List(); var operationList = ""; var ioTaskList = new List(); var msgListLock = new object(); @@ -122,7 +126,7 @@ await Task.Run(() => lock (msgListLock) { operationList += $"{item.PackageName}=={latest.Versions!.Last()} "; - msgList.Add(new LibraryCheckUpdateContentDialogContentListItem(item, latest.Versions!.Last())); + msgList.Add(new PackageUpdateItem(item, latest.Versions!.Last())); } }))); Task.WaitAll([.. ioTaskList]); @@ -134,16 +138,16 @@ await Task.Run(() => } else { - var custom = new CheckUpdateContentDialog(_contentDialogService.GetContentPresenter(), msgList); - var result = await custom.ShowAsync(); - if (result != ContentDialogResult.Primary) return; - _actionService.AddOperation(new ActionListItem - ( - ActionType.Update, - operationList.Trim().Split(' '), - progressIntermediate: false - )); - _navigationService.Navigate(typeof(ActionPage)); + _overlayViewModel.ShowPackageUpdateOverlay(msgList, () => + { + _actionService.AddOperation(new ActionListItem + ( + ActionType.Update, + operationList.Trim().Split(' '), + progressIntermediate: false + )); + _navigationService.Navigate(typeof(ActionPage)); + }); } } diff --git a/src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs b/src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs index 34c7667..7333995 100644 --- a/src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Overlay/OverlayViewModel.cs @@ -1,11 +1,13 @@ -using PipManager.Views.Pages.Overlay; +using System.Collections.ObjectModel; +using PipManager.Models.Package; +using PipManager.Views.Pages.Overlay; +using PipManager.Views.Windows; namespace PipManager.ViewModels.Pages.Overlay; -public partial class OverlayViewModel : ObservableObject +public partial class OverlayViewModel: ObservableObject { - [ObservableProperty] - private int _testValue; + private System.Action? ConfirmCallback; [ObservableProperty] private bool _isOverlayVisible; @@ -14,5 +16,28 @@ public partial class OverlayViewModel : ObservableObject private void CloseOverlay() { IsOverlayVisible = false; + App.GetService().TitleBarCoverageGrid.Visibility = Visibility.Collapsed; + } + + private void ShowOverlay() + { + IsOverlayVisible = true; + App.GetService().TitleBarCoverageGrid.Visibility = Visibility.Visible; + } + + [ObservableProperty] private ObservableCollection _packageUpdateItems = []; + + public void ShowPackageUpdateOverlay(List packageUpdates, System.Action callback) + { + ConfirmCallback = callback; + PackageUpdateItems = new ObservableCollection(packageUpdates); + ShowOverlay(); + } + + [RelayCommand] + private void Confirm() + { + CloseOverlay(); + ConfirmCallback?.Invoke(); } } diff --git a/src/PipManager/Views/Pages/Library/LibraryPage.xaml b/src/PipManager/Views/Pages/Library/LibraryPage.xaml index 5452a22..008ded7 100644 --- a/src/PipManager/Views/Pages/Library/LibraryPage.xaml +++ b/src/PipManager/Views/Pages/Library/LibraryPage.xaml @@ -57,7 +57,7 @@ BorderThickness="1" CornerRadius="5" Margin="0,0,5,0" - Visibility="{Binding ViewModel.ListVisible, Converter={StaticResource InverseBoolToVisibility}}"> + Visibility="{Binding ViewModel.LibraryList, Converter={StaticResource NotNullToVisibility}}"> @@ -74,7 +74,7 @@ BorderThickness="1" CornerRadius="5" Margin="0,0,5,0" - Visibility="{Binding ViewModel.ListVisible, Converter={StaticResource InverseBoolToVisibility}}"> + Visibility="{Binding ViewModel.LibraryList, Converter={StaticResource NotNullToVisibility}}"> @@ -93,21 +93,21 @@ - - - - - - + Grid.Row="1" + IsTextSearchCaseSensitive="False" + IsTextSearchEnabled="True" + ItemsSource="{Binding ViewModel.LibraryList, Mode=TwoWay}" + Margin="0,10,0,0" + SelectionMode="Multiple" + TextSearch.TextPath="PackageName" + Visibility="{Binding ViewModel.LibraryList, Converter={StaticResource NotNullToVisibility}}" + x:Name="LibraryList"> + + + + + + diff --git a/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml index 009c29e..e43e40f 100644 --- a/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml +++ b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml @@ -6,18 +6,49 @@ xmlns:d="http://schemas.microsoft.com/expression/blend/2008" xmlns:local="clr-namespace:PipManager.Views.Pages.Overlay" xmlns:xamlFlair="clr-namespace:XamlFlair;assembly=XamlFlair.WPF" + xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" + xmlns:package="clr-namespace:PipManager.Models.Package" + d:DesignHeight="700" + d:DesignWidth="1200" d:DataContext="{d:DesignInstance local:OverlayPage, IsDesignTimeCreatable=False}" + Background="{DynamicResource ApplicationBackgroundBrush}" + ui:Design.Foreground="{DynamicResource TextFillColorPrimaryBrush}" Visibility="{Binding ViewModel.IsOverlayVisible, Converter={StaticResource BoolToVisibility}}" + xamlFlair:Animations.Primary="{xamlFlair:Animate BasedOn={StaticResource FadeInAndSlideFromBottom}, Duration=500, Event=None}" + xamlFlair:Animations.AllowOpacityReset="True" + xamlFlair:Animations.PrimaryBinding="{Binding ViewModel.IsOverlayVisible}" mc:Ignorable="d"> - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + From 176ae587a44bf3554da003d43ffc6484a66fd3fd Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Sun, 14 Apr 2024 18:53:17 +0800 Subject: [PATCH 11/17] perf: WPF-UI 3.0.3 -> 3.0.4 --- src/PipManager/Views/Windows/MainWindow.xaml | 10 ++++++---- src/PipManager/Views/Windows/MainWindow.xaml.cs | 2 +- 2 files changed, 7 insertions(+), 5 deletions(-) diff --git a/src/PipManager/Views/Windows/MainWindow.xaml b/src/PipManager/Views/Windows/MainWindow.xaml index d21dd38..1c0d1c6 100644 --- a/src/PipManager/Views/Windows/MainWindow.xaml +++ b/src/PipManager/Views/Windows/MainWindow.xaml @@ -107,16 +107,18 @@ Grid.RowSpan="2" x:Name="RootContentDialog" /> - + CloseWindowByDoubleClickOnIcon="True" + Title="{Binding ViewModel.ApplicationTitle}"> + + + + Date: Sun, 14 Apr 2024 20:22:32 +0800 Subject: [PATCH 12/17] perf: remove redundant code --- src/PipManager/Models/AppConfig.cs | 2 +- src/PipManager/Models/DataColor.cs | 8 ---- src/PipManager/Models/ExceptionType.cs | 4 +- src/PipManager/Models/Package/PackageItem.cs | 1 - .../Models/Package/PackageVersion.cs | 18 -------- .../Pages/AddEnvironmentByWaysListItem.cs | 15 ------- .../Models/Pages/LibraryListItem.cs | 30 ++++++------- .../Environment/EnvironmentService.cs | 6 +-- .../Views/Pages/Overlay/OverlayPage.xaml | 43 ++++++++++--------- 9 files changed, 42 insertions(+), 85 deletions(-) delete mode 100644 src/PipManager/Models/DataColor.cs delete mode 100644 src/PipManager/Models/Pages/AddEnvironmentByWaysListItem.cs diff --git a/src/PipManager/Models/AppConfig.cs b/src/PipManager/Models/AppConfig.cs index 802b704..ded0761 100644 --- a/src/PipManager/Models/AppConfig.cs +++ b/src/PipManager/Models/AppConfig.cs @@ -6,7 +6,7 @@ namespace PipManager.Models; public class AppConfig { [JsonProperty("currentEnvironment")] public EnvironmentItem? CurrentEnvironment { get; set; } - [JsonProperty("environments")] public List EnvironmentItems { get; set; } = new(); + [JsonProperty("environments")] public List EnvironmentItems { get; set; } = []; [JsonProperty("packageSource")] public PackageSource PackageSource { get; set; } = new(); [JsonProperty("personalization")] public Personalization Personalization { get; set; } = new(); } \ No newline at end of file diff --git a/src/PipManager/Models/DataColor.cs b/src/PipManager/Models/DataColor.cs deleted file mode 100644 index 0f52d22..0000000 --- a/src/PipManager/Models/DataColor.cs +++ /dev/null @@ -1,8 +0,0 @@ -using System.Windows.Media; - -namespace PipManager.Models; - -public struct DataColor -{ - public Brush Color { get; set; } -} \ No newline at end of file diff --git a/src/PipManager/Models/ExceptionType.cs b/src/PipManager/Models/ExceptionType.cs index 9ccb69c..6576ccc 100644 --- a/src/PipManager/Models/ExceptionType.cs +++ b/src/PipManager/Models/ExceptionType.cs @@ -3,8 +3,8 @@ public enum ExceptionType { // Environment - Environment_Broken, + EnvironmentBroken, // Process - Process_Error + ProcessError } \ No newline at end of file diff --git a/src/PipManager/Models/Package/PackageItem.cs b/src/PipManager/Models/Package/PackageItem.cs index 9267b31..d527f36 100644 --- a/src/PipManager/Models/Package/PackageItem.cs +++ b/src/PipManager/Models/Package/PackageItem.cs @@ -4,7 +4,6 @@ namespace PipManager.Models.Package; public class PackageItem { - public string? Priority { get; set; } public string? Name { get; set; } public string? Version { get; set; } public PackageVersion? DetailedVersion { get; set; } diff --git a/src/PipManager/Models/Package/PackageVersion.cs b/src/PipManager/Models/Package/PackageVersion.cs index 2adcf95..9e76a7a 100644 --- a/src/PipManager/Models/Package/PackageVersion.cs +++ b/src/PipManager/Models/Package/PackageVersion.cs @@ -2,24 +2,6 @@ public class PackageVersion { - public PackageVersion() - { - } - - public PackageVersion(string epoch, string release, string preL, string preN, string postN1, string postL, string postN2, string devL, string devN, string local) - { - Epoch = epoch; - Release = release; - PreL = preL; - PreN = preN; - PostN1 = postN1; - PostL = postL; - PostN2 = postN2; - DevL = devL; - DevN = devN; - Local = local; - } - public string Epoch { get; set; } = ""; public string Release { get; set; } = ""; public string PreL { get; set; } = ""; diff --git a/src/PipManager/Models/Pages/AddEnvironmentByWaysListItem.cs b/src/PipManager/Models/Pages/AddEnvironmentByWaysListItem.cs deleted file mode 100644 index 4831172..0000000 --- a/src/PipManager/Models/Pages/AddEnvironmentByWaysListItem.cs +++ /dev/null @@ -1,15 +0,0 @@ -using Wpf.Ui.Controls; - -namespace PipManager.Models.Pages; - -public class AddEnvironmentByWaysListItem -{ - public AddEnvironmentByWaysListItem(SymbolIcon icon, string way) - { - SymbolIcon = icon; - Way = way; - } - - public SymbolIcon SymbolIcon { get; set; } - public string Way { get; set; } -} \ No newline at end of file diff --git a/src/PipManager/Models/Pages/LibraryListItem.cs b/src/PipManager/Models/Pages/LibraryListItem.cs index 691c38d..8bf0e8b 100644 --- a/src/PipManager/Models/Pages/LibraryListItem.cs +++ b/src/PipManager/Models/Pages/LibraryListItem.cs @@ -3,22 +3,18 @@ namespace PipManager.Models.Pages; -public class LibraryListItem +public class LibraryListItem( + SymbolIcon icon, + string packageName, + string packageVersion, + PackageVersion packageDetailedVersion, + string packageSummary, + bool isSelected) { - public LibraryListItem(SymbolIcon icon, string packageName, string packageVersion, PackageVersion packageDetailedVersion, string packageSummary, bool isSelected) - { - PackageIcon = icon; - PackageName = packageName; - PackageVersion = packageVersion; - PackageSummary = packageSummary; - IsSelected = isSelected; - PackageDetailedVersion = packageDetailedVersion; - } - - public SymbolIcon PackageIcon { get; set; } - public string PackageName { get; set; } - public string PackageVersion { get; set; } - public PackageVersion PackageDetailedVersion { get; set; } - public string PackageSummary { get; set; } - public bool IsSelected { get; set; } + public SymbolIcon PackageIcon { get; set; } = icon; + public string PackageName { get; set; } = packageName; + public string PackageVersion { get; set; } = packageVersion; + public PackageVersion PackageDetailedVersion { get; set; } = packageDetailedVersion; + public string PackageSummary { get; set; } = packageSummary; + public bool IsSelected { get; set; } = isSelected; } \ No newline at end of file diff --git a/src/PipManager/Services/Environment/EnvironmentService.cs b/src/PipManager/Services/Environment/EnvironmentService.cs index e1af138..262e313 100644 --- a/src/PipManager/Services/Environment/EnvironmentService.cs +++ b/src/PipManager/Services/Environment/EnvironmentService.cs @@ -33,7 +33,7 @@ public ActionResponse CheckEnvironmentAvailable(EnvironmentItem environmentItem) var verify = configurationService.GetEnvironmentItemFromCommand(environmentItem.PythonPath!, "-m pip -V"); return verify != null && environmentItem.PythonPath != string.Empty ? new ActionResponse { Success = true } - : new ActionResponse { Success = false, Exception = ExceptionType.Environment_Broken }; + : new ActionResponse { Success = false, Exception = ExceptionType.EnvironmentBroken }; } public ActionResponse PurgeEnvironmentCache(EnvironmentItem environmentItem) @@ -57,7 +57,7 @@ public ActionResponse PurgeEnvironmentCache(EnvironmentItem environmentItem) process.Close(); process.Dispose(); error = error.Replace("WARNING: No matching packages", "").Trim(); - return !string.IsNullOrEmpty(error) ? new ActionResponse { Success = false, Exception = ExceptionType.Process_Error, Message = error } : new ActionResponse { Success = true, Message = output[15..].TrimEnd()}; + return !string.IsNullOrEmpty(error) ? new ActionResponse { Success = false, Exception = ExceptionType.ProcessError, Message = error } : new ActionResponse { Success = true, Message = output[15..].TrimEnd()}; } public async Task?> GetLibraries() @@ -292,7 +292,7 @@ private ActionResponse RaiseProcess(string arguments, DataReceivedEventHandler c BasicCommandProcess.WaitForExit(); BasicCommandProcess.Close(); BasicCommandProcess.Dispose(); - return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.Process_Error, Message = error }; + return new ActionResponse { Success = string.IsNullOrEmpty(error), Exception = ExceptionType.ProcessError, Message = error }; } #region Basic Command diff --git a/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml index e43e40f..8868907 100644 --- a/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml +++ b/src/PipManager/Views/Pages/Overlay/OverlayPage.xaml @@ -17,34 +17,37 @@ Visibility="{Binding ViewModel.IsOverlayVisible, Converter={StaticResource BoolToVisibility}}" xamlFlair:Animations.Primary="{xamlFlair:Animate BasedOn={StaticResource FadeInAndSlideFromBottom}, Duration=500, Event=None}" xamlFlair:Animations.AllowOpacityReset="True" + ScrollViewer.CanContentScroll="False" xamlFlair:Animations.PrimaryBinding="{Binding ViewModel.IsOverlayVisible}" mc:Ignorable="d"> - + - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + From 16d0bb820f4e7a9a1413a4229c47654965208a37 Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Sun, 14 Apr 2024 20:22:41 +0800 Subject: [PATCH 13/17] perf: support install package in search --- .../Pages/Search/SearchDetailViewModel.cs | 21 ++++++++++++++++++- .../Views/Pages/Search/SearchDetailPage.xaml | 6 ++++-- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs index eb5a9e1..6a6d60f 100644 --- a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs @@ -10,6 +10,9 @@ using System.Collections.ObjectModel; using System.Drawing; using System.Net.Http; +using PipManager.Models.Action; +using PipManager.Services.Action; +using PipManager.Services.Mask; using Wpf.Ui; using Wpf.Ui.Appearance; using Wpf.Ui.Controls; @@ -24,6 +27,8 @@ public record SearchDetailMessage(QueryListItemModel Package); private readonly HttpClient _httpClient; private readonly IThemeService _themeService; private readonly IToastService _toastService; + private readonly IMaskService _maskService; + private readonly IActionService _actionService; private readonly IEnvironmentService _environmentService; [ObservableProperty] @@ -55,13 +60,15 @@ public record SearchDetailMessage(QueryListItemModel Package); [ObservableProperty] private QueryListItemModel? _package; - public SearchDetailViewModel(INavigationService navigationService, HttpClient httpClient, IThemeService themeService, IToastService toastService, IEnvironmentService environmentService) + public SearchDetailViewModel(INavigationService navigationService, HttpClient httpClient, IThemeService themeService, IToastService toastService, IEnvironmentService environmentService, IMaskService maskService, IActionService actionService) { _navigationService = navigationService; _httpClient = httpClient; _themeService = themeService; _toastService = toastService; _environmentService = environmentService; + _maskService = maskService; + _actionService = actionService; WeakReferenceMessenger.Default.Register(this, Receive); } @@ -108,6 +115,12 @@ private void InitializeViewModel() [ObservableProperty] private string _targetVersion = ""; + [RelayCommand] + private async Task DownloadPackage() + { + + } + [RelayCommand] private async Task InstallPackage() { @@ -120,7 +133,13 @@ private async Task InstallPackage() if (installedPackages.Any(item => item.Name == Package!.Name)) { _toastService.Error(Lang.LibraryInstall_Add_AlreadyInstalled); + return; } + _actionService.AddOperation(new ActionListItem + ( + ActionType.Install, + [$"{Package!.Name}=={TargetVersion}"] + )); } private void Receive(object recipient, SearchDetailMessage message) diff --git a/src/PipManager/Views/Pages/Search/SearchDetailPage.xaml b/src/PipManager/Views/Pages/Search/SearchDetailPage.xaml index 683135c..381bb52 100644 --- a/src/PipManager/Views/Pages/Search/SearchDetailPage.xaml +++ b/src/PipManager/Views/Pages/Search/SearchDetailPage.xaml @@ -99,13 +99,15 @@ Appearance="Secondary" Content="{I18N {x:Static lang:LangKeys.SearchDetail_DownloadDistributions}}" Icon="{ui:SymbolIcon ArrowCircleDown24}" - IsEnabled="False" + IsEnabled="{Binding ViewModel.ProjectDescriptionVisibility}" + Command="{Binding ViewModel.DownloadPackageCommand}" Margin="15,0,0,0" /> From d03064c7ac1862bbf196f8a83762ae2c9d35ec56 Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Sun, 14 Apr 2024 20:28:09 +0800 Subject: [PATCH 14/17] perf: support download distributions in search --- src/PipManager/Languages/Lang.Designer.cs | 9 +++++++++ src/PipManager/Languages/Lang.resx | 3 +++ src/PipManager/Languages/Lang.zh-cn.resx | 3 +++ .../Pages/Library/LibraryInstallViewModel.cs | 10 ++++++---- .../Pages/Search/SearchDetailViewModel.cs | 20 +++++++++++++++++-- 5 files changed, 39 insertions(+), 6 deletions(-) diff --git a/src/PipManager/Languages/Lang.Designer.cs b/src/PipManager/Languages/Lang.Designer.cs index 6d4a9de..aa4d53f 100644 --- a/src/PipManager/Languages/Lang.Designer.cs +++ b/src/PipManager/Languages/Lang.Designer.cs @@ -644,6 +644,15 @@ public static string Development_Developing { } } + /// + /// Looks up a localized string similar to Open download folder (for wheel files). + /// + public static string Dialog_Title_DownloadDistributions { + get { + return ResourceManager.GetString("Dialog_Title_DownloadDistributions", resourceCulture); + } + } + /// /// Looks up a localized string similar to Add Environment. /// diff --git a/src/PipManager/Languages/Lang.resx b/src/PipManager/Languages/Lang.resx index f32a40c..4d242cc 100644 --- a/src/PipManager/Languages/Lang.resx +++ b/src/PipManager/Languages/Lang.resx @@ -732,4 +732,7 @@ Failed to clear caches + + Open download folder (for wheel files) + \ No newline at end of file diff --git a/src/PipManager/Languages/Lang.zh-cn.resx b/src/PipManager/Languages/Lang.zh-cn.resx index 3f5e77e..25bb298 100644 --- a/src/PipManager/Languages/Lang.zh-cn.resx +++ b/src/PipManager/Languages/Lang.zh-cn.resx @@ -732,4 +732,7 @@ 清除缓存失败 + + 打开下载文件夹 + \ No newline at end of file diff --git a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs index b6bf582..ad1d0da 100644 --- a/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Library/LibraryInstallViewModel.cs @@ -236,14 +236,16 @@ private void BrowseDownloadDistributionsFolderTask() { var openFolderDialog = new OpenFolderDialog { - Title = "Download Folder (for wheel files)" + Title = Lang.Dialog_Title_DownloadDistributions }; var result = openFolderDialog.ShowDialog(); - if (result == true) + if (result != true) { - DownloadDistributionsFolderPath = openFolderDialog.FolderName; - DownloadDistributionsEnabled = PreDownloadPackages.Count > 0; + return; } + + DownloadDistributionsFolderPath = openFolderDialog.FolderName; + DownloadDistributionsEnabled = PreDownloadPackages.Count > 0; } [RelayCommand] diff --git a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs index 6a6d60f..dc1b727 100644 --- a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs @@ -10,6 +10,7 @@ using System.Collections.ObjectModel; using System.Drawing; using System.Net.Http; +using Microsoft.Win32; using PipManager.Models.Action; using PipManager.Services.Action; using PipManager.Services.Mask; @@ -116,9 +117,24 @@ private void InitializeViewModel() private string _targetVersion = ""; [RelayCommand] - private async Task DownloadPackage() + private void DownloadPackage() { - + var openFolderDialog = new OpenFolderDialog + { + Title = Lang.Dialog_Title_DownloadDistributions + }; + var result = openFolderDialog.ShowDialog(); + if (result != true) + { + return; + } + _actionService.AddOperation(new ActionListItem + ( + ActionType.Download, + [$"{Package!.Name}=={TargetVersion}"], + path: openFolderDialog.FolderName, + extraParameters: ["--no-deps"] + )); } [RelayCommand] From 3e49056b3e95501aaaf96b75c0c15609d39401c8 Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Sun, 14 Apr 2024 20:42:07 +0800 Subject: [PATCH 15/17] feat: check packages update with overlay --- src/PipManager/Languages/Lang.Designer.cs | 27 ++++++++++ src/PipManager/Languages/Lang.resx | 9 ++++ src/PipManager/Languages/Lang.zh-cn.resx | 9 ++++ .../Library/CheckUpdateContentDialog.cs | 49 ----------------- .../Resources/Library/LibraryStyles.xaml | 54 ------------------- .../Views/Pages/Overlay/OverlayPage.xaml | 10 ++-- 6 files changed, 50 insertions(+), 108 deletions(-) delete mode 100644 src/PipManager/Resources/Library/CheckUpdateContentDialog.cs diff --git a/src/PipManager/Languages/Lang.Designer.cs b/src/PipManager/Languages/Lang.Designer.cs index aa4d53f..2a2b18c 100644 --- a/src/PipManager/Languages/Lang.Designer.cs +++ b/src/PipManager/Languages/Lang.Designer.cs @@ -1454,6 +1454,33 @@ public static string Mask_Loading { } } + /// + /// Looks up a localized string similar to Cancel. + /// + public static string Overlay_Button_Cancel { + get { + return ResourceManager.GetString("Overlay_Button_Cancel", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to Update. + /// + public static string Overlay_Button_Update { + get { + return ResourceManager.GetString("Overlay_Button_Update", resourceCulture); + } + } + + /// + /// Looks up a localized string similar to New Versions Found. + /// + public static string Overlay_Title_PackageUpdate { + get { + return ResourceManager.GetString("Overlay_Title_PackageUpdate", resourceCulture); + } + } + /// /// Looks up a localized string similar to The newest and compatible version will be selected. /// diff --git a/src/PipManager/Languages/Lang.resx b/src/PipManager/Languages/Lang.resx index 4d242cc..d23e07c 100644 --- a/src/PipManager/Languages/Lang.resx +++ b/src/PipManager/Languages/Lang.resx @@ -735,4 +735,13 @@ Open download folder (for wheel files) + + New Versions Found + + + Cancel + + + Update + \ No newline at end of file diff --git a/src/PipManager/Languages/Lang.zh-cn.resx b/src/PipManager/Languages/Lang.zh-cn.resx index 25bb298..427f093 100644 --- a/src/PipManager/Languages/Lang.zh-cn.resx +++ b/src/PipManager/Languages/Lang.zh-cn.resx @@ -735,4 +735,13 @@ 打开下载文件夹 + + 发现新版本 + + + 取消 + + + 更新 + \ No newline at end of file diff --git a/src/PipManager/Resources/Library/CheckUpdateContentDialog.cs b/src/PipManager/Resources/Library/CheckUpdateContentDialog.cs deleted file mode 100644 index e59efa3..0000000 --- a/src/PipManager/Resources/Library/CheckUpdateContentDialog.cs +++ /dev/null @@ -1,49 +0,0 @@ -using PipManager.Languages; -using PipManager.Models.Pages; -using System.Windows.Controls; -using Wpf.Ui.Controls; -using TextBlock = System.Windows.Controls.TextBlock; - -namespace PipManager.Resources.Library; - -public class CheckUpdateContentDialog -{ - private readonly ContentDialog _contentDialog; - public List LibraryList { get; set; } - - public CheckUpdateContentDialog(ContentPresenter contentPresenter, List libraryList) - { - LibraryList = libraryList; - _contentDialog = new ContentDialog(contentPresenter) - { - PrimaryButtonText = Lang.ContentDialog_PrimaryButton_Action, - CloseButtonText = Lang.ContentDialog_CloseButton_Cancel, - IsPrimaryButtonEnabled = false, - Title = Lang.ContentDialog_Title_Notice, - Content = Application.Current.TryFindResource("LibraryCheckUpdateContentDialogContent") - }; - (((_contentDialog.Content as Grid)!.Children[2] as ScrollViewer)!.Content as ItemsControl)!.ItemsSource = LibraryList; - - var needUpdate = LibraryList.Any(item => item.NeedUpdate); - ((_contentDialog.Content as Grid)!.Children[0] as TextBlock)!.Visibility = - needUpdate ? Visibility.Visible : Visibility.Collapsed; - (((_contentDialog.Content as Grid)!.Children[2] as ScrollViewer)!.Content as ItemsControl)!.Visibility = - needUpdate ? Visibility.Visible : Visibility.Collapsed; - ((_contentDialog.Content as Grid)!.Children[1] as TextBlock)!.Visibility = - needUpdate ? Visibility.Collapsed : Visibility.Visible; - _contentDialog.IsPrimaryButtonEnabled = needUpdate; - } - - public async Task ShowAsync() - { - return await _contentDialog.ShowAsync(); - } -} - -public class LibraryCheckUpdateContentDialogContentListItem(LibraryListItem libraryListItem, string newVersion) -{ - public string PackageName { get; set; } = libraryListItem.PackageName; - public string PackageVersion { get; set; } = string.Format(Lang.Library_CheckUpdate_Current, libraryListItem.PackageVersion); - public string NewVersion { get; set; } = string.Format(Lang.Library_CheckUpdate_Latest, newVersion); - public bool NeedUpdate { get; set; } = newVersion != libraryListItem.PackageVersion; -} \ No newline at end of file diff --git a/src/PipManager/Resources/Library/LibraryStyles.xaml b/src/PipManager/Resources/Library/LibraryStyles.xaml index 807c4b3..d04d543 100644 --- a/src/PipManager/Resources/Library/LibraryStyles.xaml +++ b/src/PipManager/Resources/Library/LibraryStyles.xaml @@ -36,60 +36,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -41,7 +42,7 @@ - + @@ -49,9 +50,8 @@ - - - + + From f08c947fc81b42835f63d2b3d44d6908e6257576 Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Sun, 14 Apr 2024 20:51:06 +0800 Subject: [PATCH 16/17] perf: apply MiSans to Toast --- src/PipManager/Controls/Toast.xaml.cs | 45 ++++++++------------------- 1 file changed, 13 insertions(+), 32 deletions(-) diff --git a/src/PipManager/Controls/Toast.xaml.cs b/src/PipManager/Controls/Toast.xaml.cs index ffddcad..ef390b9 100644 --- a/src/PipManager/Controls/Toast.xaml.cs +++ b/src/PipManager/Controls/Toast.xaml.cs @@ -8,23 +8,13 @@ namespace PipManager.Controls { public class ToastOptions { - public double ToastWidth { get; set; } - public double ToastHeight { get; set; } - public double TextWidth { get; set; } - public int Time { get; set; } = 2000; - public SymbolRegular Icon { get; set; } = SymbolRegular.Info24; - public Brush Foreground { get; set; } = new SolidColorBrush(Colors.Black); - public Brush IconForeground { get; set; } = new SolidColorBrush(Colors.Black); - public FontFamily FontFamily { get; set; } = new("Microsoft YaHei"); - public FontWeight FontWeight { get; set; } = SystemFonts.MenuFontWeight; - public Brush BorderBrush { get; set; } = new SolidColorBrush(Color.FromRgb(229, 229, 229)); - public Thickness BorderThickness { get; set; } = new(2); - public Brush Background { get; set; } = new SolidColorBrush(Color.FromArgb(40, 0, 255, 0)); - public ApplicationTheme Theme { get; set; } = ApplicationTheme.Light; - public ToastType ToastType { get; set; } = ToastType.Info; - public EventHandler? Closed { get; internal set; } - public EventHandler? Click { get; internal set; } - public Thickness ToastMargin { get; set; } = new(0, 120, 0, 0); + public int Time { get; init; } = 2000; + public FontFamily FontFamily { get; } = new(new Uri("pack://application:,,,/"), "./Resources/Fonts/MiSans-Regular.ttf#MiSans"); + public FontWeight FontWeight { get; } = SystemFonts.MenuFontWeight; + public Thickness BorderThickness { get; } = new(2); + public ApplicationTheme Theme { get; init; } = ApplicationTheme.Light; + public ToastType ToastType { get; init; } = ToastType.Info; + public Thickness ToastMargin { get; } = new(0, 120, 0, 0); } public enum ToastType @@ -34,10 +24,7 @@ public enum ToastType Error, Success } - - /// - /// Toast.xaml 的交互逻辑 - /// + public partial class Toast { private readonly Window? _owner; @@ -58,13 +45,7 @@ private Toast(Window? owner, string title, string message, ToastOptions? options InitializeComponent(); if (options != null) { - if (options.ToastWidth != 0) ToastWidth = options.ToastWidth; - if (options.ToastHeight != 0) ToastHeight = options.ToastHeight; - if (options.TextWidth != 0) TextWidth = options.TextWidth; - Time = options.Time; - Closed += options.Closed; - Click += options.Click; FontFamily = options.FontFamily; FontWeight = options.FontWeight; BorderThickness = options.BorderThickness; @@ -283,7 +264,7 @@ private static void SetPopupOffset(Popup? popup, Toast toast) popup.VerticalOffset = margin.Top; } - public void Close() + private void Close() { _timer?.Stop(); _timer = null; @@ -357,7 +338,7 @@ private string Message private double ToastWidth { get => (double)GetValue(ToastWidthProperty); - set => SetValue(ToastWidthProperty, value); + init => SetValue(ToastWidthProperty, value); } private static readonly DependencyProperty ToastWidthProperty = @@ -366,7 +347,7 @@ private double ToastWidth private double ToastHeight { get => (double)GetValue(ToastHeightProperty); - set => SetValue(ToastHeightProperty, value); + init => SetValue(ToastHeightProperty, value); } private static readonly DependencyProperty ToastHeightProperty = @@ -384,7 +365,7 @@ private SymbolRegular Icon private int Time { get => (int)GetValue(TimeProperty); - set => SetValue(TimeProperty, value); + init => SetValue(TimeProperty, value); } private static readonly DependencyProperty TimeProperty = @@ -402,7 +383,7 @@ public double TextWidth public Thickness ToastMargin { get => (Thickness)GetValue(ToastMarginProperty); - set => SetValue(ToastMarginProperty, value); + init => SetValue(ToastMarginProperty, value); } public static readonly DependencyProperty ToastMarginProperty = From cab72be8d62271871d8bd92189b40be339348b1d Mon Sep 17 00:00:00 2001 From: AuroraZiling <2935876049@qq.com> Date: Sun, 14 Apr 2024 21:01:05 +0800 Subject: [PATCH 17/17] perf: remove redundant code --- build.ps1 | 2 +- src/PipManager/App.xaml | 1 - .../Resources/Library/DeletionWarningContentDialog.cs | 2 +- src/PipManager/Resources/Library/LibraryStyles.xaml | 4 +--- src/PipManager/ViewModels/Pages/Lab/LabViewModel.cs | 1 - .../ViewModels/Pages/Library/LibraryViewModel.cs | 1 - .../ViewModels/Pages/Overlay/OverlayViewModel.cs | 7 +++---- .../ViewModels/Pages/Search/SearchDetailViewModel.cs | 5 +---- src/PipManager/Views/Pages/Lab/LabPage.xaml | 1 - src/PipManager/Views/Pages/Library/LibraryDetailPage.xaml | 3 ++- src/PipManager/Views/Pages/Overlay/OverlayPage.xaml.cs | 3 +-- src/PipManager/Views/Pages/Search/SearchDetailPage.xaml | 3 ++- src/PipManager/Views/Pages/Settings/SettingsPage.xaml | 3 +-- 13 files changed, 13 insertions(+), 23 deletions(-) diff --git a/build.ps1 b/build.ps1 index 8c9f4f0..19247d5 100644 --- a/build.ps1 +++ b/build.ps1 @@ -1,6 +1,6 @@ param( [string] $Architecture = "x64", - [string] $Version = "0.0.3.0" + [string] $Version = "0.0.4.0" ) $ErrorActionPreference = "Stop"; diff --git a/src/PipManager/App.xaml b/src/PipManager/App.xaml index ad3dcdf..7454926 100644 --- a/src/PipManager/App.xaml +++ b/src/PipManager/App.xaml @@ -4,7 +4,6 @@ xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" xmlns:valueConverters="clr-namespace:ValueConverters;assembly=ValueConverters" - xmlns:xamlFlair="clr-namespace:XamlFlair;assembly=XamlFlair.WPF" DispatcherUnhandledException="OnDispatcherUnhandledException" Exit="OnExit" Startup="OnStartup"> diff --git a/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs b/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs index aa0afeb..78045f7 100644 --- a/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs +++ b/src/PipManager/Resources/Library/DeletionWarningContentDialog.cs @@ -8,7 +8,7 @@ namespace PipManager.Resources.Library; public class DeletionWarningContentDialog { private readonly ContentDialog _contentDialog; - public List LibraryList { get; set; } + private List LibraryList { get; set; } public DeletionWarningContentDialog(ContentPresenter? contentPresenter, List libraryList) { diff --git a/src/PipManager/Resources/Library/LibraryStyles.xaml b/src/PipManager/Resources/Library/LibraryStyles.xaml index d04d543..beac0a6 100644 --- a/src/PipManager/Resources/Library/LibraryStyles.xaml +++ b/src/PipManager/Resources/Library/LibraryStyles.xaml @@ -2,10 +2,8 @@ xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" xmlns:lang="clr-namespace:PipManager.Languages" - xmlns:library="clr-namespace:PipManager.Resources.Library" xmlns:pages="clr-namespace:PipManager.Models.Pages" - xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml" - xmlns:valueConverters="clr-namespace:ValueConverters;assembly=ValueConverters"> + xmlns:ui="http://schemas.lepo.co/wpfui/2022/xaml"> packageUpdates, System.Action callback) { - ConfirmCallback = callback; + _confirmCallback = callback; PackageUpdateItems = new ObservableCollection(packageUpdates); ShowOverlay(); } @@ -38,6 +37,6 @@ public void ShowPackageUpdateOverlay(List packageUpdates, Sys private void Confirm() { CloseOverlay(); - ConfirmCallback?.Invoke(); + _confirmCallback?.Invoke(); } } diff --git a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs index dc1b727..b5c71e0 100644 --- a/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs +++ b/src/PipManager/ViewModels/Pages/Search/SearchDetailViewModel.cs @@ -13,7 +13,6 @@ using Microsoft.Win32; using PipManager.Models.Action; using PipManager.Services.Action; -using PipManager.Services.Mask; using Wpf.Ui; using Wpf.Ui.Appearance; using Wpf.Ui.Controls; @@ -28,7 +27,6 @@ public record SearchDetailMessage(QueryListItemModel Package); private readonly HttpClient _httpClient; private readonly IThemeService _themeService; private readonly IToastService _toastService; - private readonly IMaskService _maskService; private readonly IActionService _actionService; private readonly IEnvironmentService _environmentService; @@ -61,14 +59,13 @@ public record SearchDetailMessage(QueryListItemModel Package); [ObservableProperty] private QueryListItemModel? _package; - public SearchDetailViewModel(INavigationService navigationService, HttpClient httpClient, IThemeService themeService, IToastService toastService, IEnvironmentService environmentService, IMaskService maskService, IActionService actionService) + public SearchDetailViewModel(INavigationService navigationService, HttpClient httpClient, IThemeService themeService, IToastService toastService, IEnvironmentService environmentService, IActionService actionService) { _navigationService = navigationService; _httpClient = httpClient; _themeService = themeService; _toastService = toastService; _environmentService = environmentService; - _maskService = maskService; _actionService = actionService; WeakReferenceMessenger.Default.Register(this, Receive); diff --git a/src/PipManager/Views/Pages/Lab/LabPage.xaml b/src/PipManager/Views/Pages/Lab/LabPage.xaml index f151b16..09b4493 100644 --- a/src/PipManager/Views/Pages/Lab/LabPage.xaml +++ b/src/PipManager/Views/Pages/Lab/LabPage.xaml @@ -18,6 +18,5 @@ mc:Ignorable="d"> - \ No newline at end of file diff --git a/src/PipManager/Views/Pages/Library/LibraryDetailPage.xaml b/src/PipManager/Views/Pages/Library/LibraryDetailPage.xaml index a57af06..4029612 100644 --- a/src/PipManager/Views/Pages/Library/LibraryDetailPage.xaml +++ b/src/PipManager/Views/Pages/Library/LibraryDetailPage.xaml @@ -1,4 +1,5 @@ - + + + xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">