From bb2bb9fc266f14a401d11b97cc239cdffac22180 Mon Sep 17 00:00:00 2001 From: Aigio Liu Date: Mon, 28 Aug 2023 22:13:57 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20FilePicker2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ref/Common | 2 +- ref/DirectoryPackages | 2 +- .../AvaloniaFilePickerPlatformService.cs | 24 ++++++++++++++++++- .../UI/Views/Controls/CustomFilePicker.cs | 2 +- .../Models/PlatformAccount.cs | 7 +----- .../ViewModels/Pages/SettingsPageViewModel.cs | 13 +++++----- 6 files changed, 34 insertions(+), 16 deletions(-) diff --git a/ref/Common b/ref/Common index 5e73ea70e..a7b6b6581 160000 --- a/ref/Common +++ b/ref/Common @@ -1 +1 @@ -Subproject commit 5e73ea70e3a0400eaa96641d4cc9d84cf0d1e784 +Subproject commit a7b6b65810c2b3b14d1dd509aa12534d04d39721 diff --git a/ref/DirectoryPackages b/ref/DirectoryPackages index 222cdce33..7e9b98628 160000 --- a/ref/DirectoryPackages +++ b/ref/DirectoryPackages @@ -1 +1 @@ -Subproject commit 222cdce33d7bdcc4626f140e774723958913f8fe +Subproject commit 7e9b98628d74e00cfd4e81465047cf27a9a8c550 diff --git a/src/BD.WTTS.Client.Avalonia/Services.Implementation/UI/Widgets/AvaloniaFilePickerPlatformService.cs b/src/BD.WTTS.Client.Avalonia/Services.Implementation/UI/Widgets/AvaloniaFilePickerPlatformService.cs index 9fef5e163..2011d3845 100644 --- a/src/BD.WTTS.Client.Avalonia/Services.Implementation/UI/Widgets/AvaloniaFilePickerPlatformService.cs +++ b/src/BD.WTTS.Client.Avalonia/Services.Implementation/UI/Widgets/AvaloniaFilePickerPlatformService.cs @@ -25,7 +25,13 @@ sealed class AvaloniaFilePickerPlatformService : BaseService, IServiceBase, IOpe UTType.PNG, UTType.JPEG, "jpeg", }); #else - FilePickerFileType.Parse(FileEx.Images); + FilePickerFileType.Parse(new[] { + FileEx.WebP, + FileEx.Png, + FileEx.JPG, + FileEx.JPEG, + //FileEx.Gif, + }); #endif IFilePickerFileType IInternalFilePickerPlatformService.Png => FilePickerFileType.Parse(new string[] { @@ -80,6 +86,22 @@ sealed class AvaloniaFilePickerPlatformService : BaseService, IServiceBase, IOpe { #if IOS || MACOS || MACCATALYST AppleUniformTypeIdentifiers = extensions?.ToArray(), +#elif WINDOWS + Patterns = extensions?.Select(x => + { + if (x.StartsWith('.')) + { + return $"*{x}"; + } + else if (x.StartsWith('*')) + { + return x; + } + else + { + return $"*.{x}"; + } + }).ToArray(), #else Patterns = IServiceBase.FormatExtensions(extensions, trimLeadingPeriod: true).ToArray(), #endif diff --git a/src/BD.WTTS.Client.Avalonia/UI/Views/Controls/CustomFilePicker.cs b/src/BD.WTTS.Client.Avalonia/UI/Views/Controls/CustomFilePicker.cs index 44333aaa9..fb2851ef6 100644 --- a/src/BD.WTTS.Client.Avalonia/UI/Views/Controls/CustomFilePicker.cs +++ b/src/BD.WTTS.Client.Avalonia/UI/Views/Controls/CustomFilePicker.cs @@ -74,7 +74,7 @@ public sealed class CustomFilePicker : ContentControl this.Tapped += CustomFilePicker_Tapped; } - private async void CustomFilePicker_Tapped(object? sender, Avalonia.Interactivity.RoutedEventArgs e) + private async void CustomFilePicker_Tapped(object? sender, RoutedEventArgs e) { //if (string.IsNullOrEmpty(FileExtensions) || FileExtensions == "*") //{ diff --git a/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs b/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs index bb18f4639..184812e58 100644 --- a/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs +++ b/src/BD.WTTS.Client.Plugins.GameAccount/Models/PlatformAccount.cs @@ -41,11 +41,6 @@ public sealed partial class PlatformAccount SetAccountAvatarCommand = ReactiveCommand.Create(async acc => { - FilePickerFileType fileTypes = new ValueTuple[] - { - ("Image Files", FileEx.Images.Select(s => $"*{s}").ToArray()), - }; - await FilePicker2.PickAsync((path) => { if (!string.IsNullOrEmpty(path) && !string.IsNullOrEmpty(acc.AccountName)) @@ -54,7 +49,7 @@ public sealed partial class PlatformAccount File.Copy(path, imagePath, true); acc.ImagePath = imagePath; } - }, fileTypes); + }, IFilePickerFileType.Images()); }); EditRemarkCommand = ReactiveCommand.Create(async acc => { diff --git a/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs b/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs index 40b54af78..f190805ec 100644 --- a/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs +++ b/src/BD.WTTS.Client/UI/ViewModels/Pages/SettingsPageViewModel.cs @@ -41,12 +41,13 @@ public sealed partial class SettingsPageViewModel : TabItemViewModel SelectImage_Click = ReactiveCommand.CreateFromTask(async () => { - FilePickerFileType fileTypes = new ValueTuple[] - { - ("Image Files", FileEx.Images.Select(s => $"*{s}").ToArray()), - //("All Files", new[] { "*", }), - }; - await FilePicker2.PickAsync(SetBackgroundImagePath, fileTypes); + //FilePickerFileType fileTypes = new ValueTuple[] + //{ + // ("Image Files", FileEx.Images.Select(s => $"*{s}").ToArray()), + // //("All Files", new[] { "*", }), + //}; + //await FilePicker2.PickAsync(SetBackgroundImagePath, fileTypes); + await FilePicker2.PickAsync(SetBackgroundImagePath, IFilePickerFileType.Images()); }); ResetImage_Click = ReactiveCommand.Create(() => SetBackgroundImagePath(null));