diff --git a/src/PicView.Avalonia/Navigation/ErrorHandling.cs b/src/PicView.Avalonia/Navigation/ErrorHandling.cs index 9d3e1c49d..20203e00e 100644 --- a/src/PicView.Avalonia/Navigation/ErrorHandling.cs +++ b/src/PicView.Avalonia/Navigation/ErrorHandling.cs @@ -58,6 +58,7 @@ void Start() vm.GalleryMargin = new Thickness(0, 0, 0, 0); vm.GetIndex = 0; vm.PlatformService.StopTaskbarProgress(); + vm.IsLoading = false; } } diff --git a/src/PicView.Avalonia/Navigation/ImageIterator.cs b/src/PicView.Avalonia/Navigation/ImageIterator.cs index 8ed6e9210..d6474b13e 100644 --- a/src/PicView.Avalonia/Navigation/ImageIterator.cs +++ b/src/PicView.Avalonia/Navigation/ImageIterator.cs @@ -584,7 +584,6 @@ void TryShowPreview(PreLoader.PreLoadValue preloadValue) return; } - SetTitleHelper.SetLoadingTitle(_vm); _vm.IsLoading = true; _vm.ImageSource = null; _vm.SecondaryImageSource = null; diff --git a/src/PicView.Avalonia/Navigation/NavigationHelper.cs b/src/PicView.Avalonia/Navigation/NavigationHelper.cs index d573ad558..420270b39 100644 --- a/src/PicView.Avalonia/Navigation/NavigationHelper.cs +++ b/src/PicView.Avalonia/Navigation/NavigationHelper.cs @@ -463,13 +463,38 @@ await Task.Run(async () => /// A task representing the asynchronous operation. public static async Task LoadPicFromDirectoryAsync(string file, MainViewModel vm, FileInfo? fileInfo = null) { + vm.IsLoading = true; + SetTitleHelper.SetLoadingTitle(vm); + if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled) { vm.PlatformService.StopTaskbarProgress(); } + fileInfo ??= new FileInfo(file); vm.ImageIterator?.Dispose(); - vm.ImageIterator = new ImageIterator(fileInfo, vm); + var fileList = await Task.FromResult(vm.PlatformService.GetFiles(fileInfo)).ConfigureAwait(false); + if (fileList.Count <= 0) + { + // Attempt to reload with subdirectories and reset the setting + if (!SettingsHelper.Settings.Sorting.IncludeSubDirectories) + { + SettingsHelper.Settings.Sorting.IncludeSubDirectories = true; + fileList = await Task.FromResult(vm.PlatformService.GetFiles(fileInfo)).ConfigureAwait(false); + if (fileList.Count <= 0) + { + await ErrorHandling.ReloadAsync(vm).ConfigureAwait(false); + return; + } + SettingsHelper.Settings.Sorting.IncludeSubDirectories = false; + } + else + { + await ErrorHandling.ReloadAsync(vm).ConfigureAwait(false); + return; + } + } + vm.ImageIterator = new ImageIterator(fileInfo, fileList, 0, vm); await vm.ImageIterator.IterateToIndex(0); await CheckAndReloadGallery(fileInfo, vm); }