Browse Source

Fix handling of nullable `EffectConfig` and add window parameter to `CenterWindowOnScreen`

- Update `ImageFormatConverter` to properly check `EffectConfig?.Value` for null.
- Overload `CenterWindowOnScreen` to accept a `Window` parameter for better flexibility.
Ruben 1 week ago
parent
commit
2ddb2e6e27

+ 2 - 2
src/PicView.Avalonia/ImageHandling/ImageFormatConverter.cs

@@ -26,7 +26,7 @@ public static class ImageFormatConverter
         Bitmap? source = null;
 
         // Primary case: Handle effect applied or empty path by saving current ImageSource
-        if (vm.PicViewer.EffectConfig is not null || string.IsNullOrWhiteSpace(path))
+        if (vm.PicViewer.EffectConfig?.Value is not null || string.IsNullOrWhiteSpace(path))
         {
             if (vm.PicViewer.ImageSource.CurrentValue is Bitmap bmp)
             {
@@ -36,7 +36,7 @@ public static class ImageFormatConverter
         else if (NavigationManager.CanNavigate(vm) && !string.IsNullOrEmpty(path))
         {
             // Handle effects for the current file
-            if (vm.PicViewer.EffectConfig is not null && vm.PicViewer.FileInfo?.CurrentValue.FullName == path)
+            if (vm.PicViewer.EffectConfig?.Value is not null && vm.PicViewer.FileInfo?.CurrentValue.FullName == path)
             {
                 if (vm.PicViewer.ImageSource.CurrentValue is Bitmap bmp)
                 {

+ 7 - 2
src/PicView.Avalonia/WindowBehavior/WindowFunctions.cs

@@ -328,7 +328,12 @@ public static class WindowFunctions
 
     #region Window Size and Position
 
-    public static void CenterWindowOnScreen(bool horizontal = true, bool top = false)
+    public static void CenterWindowOnScreen(Window window)
+    {
+        CenterWindowOnScreen(horizontal: true, top: false, window: window);
+    }
+
+    public static void CenterWindowOnScreen(bool horizontal = true, bool top = false, Window? window = null)
     {
         if (Application.Current?.ApplicationLifetime is not IClassicDesktopStyleApplicationLifetime desktop)
         {
@@ -337,7 +342,7 @@ public static class WindowFunctions
 
         Dispatcher.UIThread.Post(() =>
         {
-            var window = desktop.MainWindow;
+            window ??= desktop.MainWindow;
             if (window.WindowState is WindowState.Maximized or WindowState.FullScreen)
             {
                 return;