Browse Source

[Avalonia] Fix Windows Taskbar progress not resetting when changing directory

Ruben 1 year ago
parent
commit
d7c4ab21f7

+ 2 - 0
src/PicView.Avalonia.Win32/App.axaml.cs

@@ -101,6 +101,8 @@ public class App : Application, IPlatformSpecificService
             return;
         }
         _taskbarProgress?.StopProgress();
+        
+        _taskbarProgress = null;
     }
 
     public void SetCursorPos(int x, int y)

+ 21 - 1
src/PicView.Avalonia/Navigation/NavigationHelper.cs

@@ -152,6 +152,7 @@ public static class NavigationHelper
         }
         else
         {
+            vm.PlatformService.StopTaskbarProgress();
             await PreviewPicAndLoadGallery(new FileInfo(fileList[0]), vm, fileList);
         }
     }
@@ -241,6 +242,10 @@ public static class NavigationHelper
         {
             return;
         }
+        if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled)
+        {
+            vm.PlatformService.StopTaskbarProgress();
+        }
         if (vm.ImageIterator is not null)
         {
             if (fileInfo.DirectoryName == vm.ImageIterator.InitialFileInfo.DirectoryName)
@@ -308,19 +313,28 @@ public static class NavigationHelper
 
         try
         {
+            vm.PlatformService.StopTaskbarProgress();
+
             var httpDownload = HttpNavigation.GetDownloadClient(url);
             using var client = httpDownload.Client;
             client.ProgressChanged += (totalFileSize, totalBytesDownloaded, progressPercentage) => 
             {
+                if (totalFileSize is null || totalBytesDownloaded is null || progressPercentage is null)
+                {
+                    return;
+                }
                 var displayProgress = HttpNavigation.GetProgressDisplay(totalFileSize, totalBytesDownloaded,
                     progressPercentage);
                 vm.Title = displayProgress;
                 vm.TitleTooltip = displayProgress;
                 vm.WindowTitle = displayProgress;
+                if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled)
+                {
+                    vm.PlatformService.SetTaskbarProgress((ulong)totalBytesDownloaded, (ulong)totalFileSize);
+                }
             };
             await client.StartDownloadAsync().ConfigureAwait(false);
             destination = httpDownload.DownloadPath;
-            // TODO add `destination` to be cleared at application exit
         }
         catch (Exception e)
         {
@@ -411,6 +425,10 @@ public static class NavigationHelper
     /// <returns>A task representing the asynchronous operation.</returns>
     public static async Task LoadPicFromDirectoryAsync(string file, MainViewModel vm, FileInfo? fileInfo = null)
     {
+        if (SettingsHelper.Settings.UIProperties.IsTaskbarProgressEnabled)
+        {
+            vm.PlatformService.StopTaskbarProgress();
+        }
         fileInfo ??= new FileInfo(file);
         vm.ImageIterator?.Dispose();
         vm.ImageIterator = new ImageIterator(fileInfo, vm);
@@ -480,6 +498,8 @@ public static class NavigationHelper
         vm.Title = titleString[1];
         vm.TitleTooltip = titleString[1];
         vm.GalleryMargin = new Thickness(0, 0, 0, 0);
+        
+        vm.PlatformService.StopTaskbarProgress();
     }
     
     #endregion