Refactor extensions to Constants class

This commit is contained in:
2026-02-25 07:35:51 +09:00
parent f927667732
commit dfc1c557e0
2 changed files with 6 additions and 15 deletions
+3
View File
@@ -7,6 +7,9 @@ class Constants
{ {
public static string AppVersion = "1.2.0"; public static string AppVersion = "1.2.0";
public static string[] AllowedFileExtensionPatterns = [ "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.webp", "*.pdf", "*.heic", ];
public static string[] AllowedFileExtensionsNoStar = [ "png", "jpg", "jpeg", "gif", "bmp", "webp", "pdf", "heic", ];
public static string[] GetQuotes() public static string[] GetQuotes()
{ {
// sources: // sources:
+3 -15
View File
@@ -280,18 +280,6 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
} }
} }
private string[] GetAllowedFileExtensionPatterns()
{
// update GetAllowedFileExtensionPatternsWithoutStar if this is edited
return [ "*.png", "*.jpg", "*.jpeg", "*.gif", "*.bmp", "*.webp", "*.pdf", "*.heic", ];
}
private string[] GetAllowedFileExtensionPatternsWithoutStar()
{
// update GetAllowedFileExtensionPatterns if this is edited
return [ "png", "jpg", "jpeg", "gif", "bmp", "webp", "pdf", "heic", ];
}
public async void AddItem() public async void AddItem()
{ {
var topLevel = TopLevelGrabber?.GetTopLevel(); var topLevel = TopLevelGrabber?.GetTopLevel();
@@ -304,7 +292,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
FileTypeFilter = [ FileTypeFilter = [
new FilePickerFileType("All Types") new FilePickerFileType("All Types")
{ {
Patterns = GetAllowedFileExtensionPatterns(), Patterns = Constants.AllowedFileExtensionPatterns,
AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ], AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ],
MimeTypes = [ "image/*", "application/pdf", "image/heic" ] MimeTypes = [ "image/*", "application/pdf", "image/heic" ]
}, },
@@ -334,7 +322,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath) && !filePath.EndsWith(".DS_Store")) if (!string.IsNullOrWhiteSpace(filePath) && File.Exists(filePath) && !filePath.EndsWith(".DS_Store"))
{ {
// make sure extensions are OK // make sure extensions are OK
var fileExtensions = GetAllowedFileExtensionPatternsWithoutStar(); var fileExtensions = Constants.AllowedFileExtensionsNoStar;
var didMatch = false; var didMatch = false;
foreach (var fileExtension in fileExtensions) foreach (var fileExtension in fileExtensions)
{ {
@@ -390,7 +378,7 @@ class MainViewModel : BaseViewModel, IFontResolver, ICanCheckShutdown
FileTypeFilter = [ FileTypeFilter = [
new FilePickerFileType("All Types") new FilePickerFileType("All Types")
{ {
Patterns = GetAllowedFileExtensionPatterns(), Patterns = Constants.AllowedFileExtensionPatterns,
AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ], AppleUniformTypeIdentifiers = [ "public.image", "com.adobe.pdf", "public.heic" ],
MimeTypes = [ "image/*", "application/pdf", "image/heic" ] MimeTypes = [ "image/*", "application/pdf", "image/heic" ]
}, },