Browse Source

Fixed setting image as wallpaper not working, when the image is not a file.

Ruben 8 months ago
parent
commit
7b77d11128

+ 1 - 1
src/PicView.Avalonia/ImageHandling/ImageHelper.cs

@@ -21,7 +21,7 @@ public static class ImageHelper
     {
         Bitmap? source = null;
         
-        if (vm.EffectConfig is not null)
+        if (vm.EffectConfig is not null || string.IsNullOrWhiteSpace(path))
         {
             if (vm.ImageSource is Bitmap bmp)
             {

+ 5 - 41
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -1418,54 +1418,18 @@ public class MainViewModel : ViewModelBase
         });
     }
     
-    public async Task SetAsWallpaperTask(string path)
-    {
-        if (string.IsNullOrWhiteSpace(path))
-        {
-            return;
-        }
-        await SetAsWallpaperTask(path, WallpaperStyle.Fit).ConfigureAwait(false);
-    }
+    public async Task SetAsWallpaperTask(string path) => await SetAsWallpaperTask(path, WallpaperStyle.Fit).ConfigureAwait(false);
     
-    public async Task SetAsWallpaperFilledTask(string path)
-    {
-        if (string.IsNullOrWhiteSpace(path))
-        {
-            return;
-        }
-        await SetAsWallpaperTask(path, WallpaperStyle.Fill).ConfigureAwait(false);
-    }
+    public async Task SetAsWallpaperFilledTask(string path) => await SetAsWallpaperTask(path, WallpaperStyle.Fill).ConfigureAwait(false);
     
-    public async Task SetAsWallpaperTiledTask(string path)
-    {
-        if (string.IsNullOrWhiteSpace(path))
-        {
-            return;
-        }
-        await SetAsWallpaperTask(path, WallpaperStyle.Tile).ConfigureAwait(false);
-    }
+    public async Task SetAsWallpaperTiledTask(string path) => await SetAsWallpaperTask(path, WallpaperStyle.Tile).ConfigureAwait(false);
     
-    public async Task SetAsWallpaperStretchedTask(string path)
-    {
-        if (string.IsNullOrWhiteSpace(path))
-        {
-            return;
-        }
-        await SetAsWallpaperTask(path, WallpaperStyle.Stretch).ConfigureAwait(false);
-    }
+    public async Task SetAsWallpaperStretchedTask(string path) => await SetAsWallpaperTask(path, WallpaperStyle.Stretch).ConfigureAwait(false);
     
-    public async Task SetAsWallpaperCenteredTask(string path)
-    {
-        if (string.IsNullOrWhiteSpace(path))
-        {
-            return;
-        }
-        await SetAsWallpaperTask(path, WallpaperStyle.Center).ConfigureAwait(false);
-    }
+    public async Task SetAsWallpaperCenteredTask(string path) => await SetAsWallpaperTask(path, WallpaperStyle.Center).ConfigureAwait(false);
     
     public async Task SetAsWallpaperTask(string path, WallpaperStyle style)
     {
-
         if (PlatformService is null)
         {
             return;