Przeglądaj źródła

Update lockscreen, disable it, and add it to FunctionsHelper to allow hotkeys

Ruben 1 rok temu
rodzic
commit
567ab1f145

+ 9 - 0
src/PicView.Avalonia/UI/FunctionsHelper.cs

@@ -116,6 +116,15 @@ public static class FunctionsHelper
             "Set3Star" => Set3Star,
             "Set4Star" => Set4Star,
             "Set5Star" => Set5Star,
+            
+            // Background and lock screen image
+            "SetAsLockScreen" => SetAsLockScreen,
+            "SetAsLockscreenCentered" => SetAsLockscreenCentered,
+            "SetAsWallpaper" => SetAsWallpaper,
+            "SetAsWallpaperFitted" => SetAsWallpaperFitted,
+            "SetAsWallpaperFilled" => SetAsWallpaperFilled,
+            "SetAsWallpaperCentered" => SetAsWallpaperCentered,
+            "SetAsWallpaperTiled" => SetAsWallpaperTiled,
 
             // Misc
             "ChangeBackground" => ChangeBackground,

+ 1 - 1
src/PicView.Avalonia/ViewModels/MainViewModel.cs

@@ -1600,7 +1600,7 @@ public class MainViewModel : ViewModelBase
             }
         };
         process.Start();
-        await TooltipHelper.ShowTooltipMessageAsync(TranslationHelper.Translation.Applying);
+        await TooltipHelper.ShowTooltipMessageAsync(TranslationHelper.Translation.Applying, true);
         await process.WaitForExitAsync();
     }
 

+ 2 - 1
src/PicView.Avalonia/Views/MainView.axaml

@@ -423,7 +423,8 @@
                 CommandParameter="{CompiledBinding FileInfo.FullName,
                                                    FallbackValue=''}"
                 Header="{CompiledBinding SetAsLockScreenImage,
-                                         Mode=OneWay}">
+                                         Mode=OneWay}"
+                IsEnabled="False">
                 <MenuItem.Icon>
                     <Path
                         Data="{StaticResource PanoramaGeometry}"

+ 18 - 4
src/PicView.WindowsNT/Lockscreen/LockscreenHelper.cs

@@ -11,16 +11,30 @@ public static partial class LockscreenHelper
 
     public static bool SetLockScreenImage(string path)
     {
-        const string registryKey =
+        const string personalizationcsp =
             @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\Windows\CurrentVersion\PersonalizationCSP";
+        const string enforceLockScreenAndLogonImage =
+            @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\DeviceLock\EnforceLockScreenAndLogonImage";
+        const string enforcelockscreenprovider =
+            @"HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\PolicyManager\default\DeviceLock\EnforceLockScreenProvider";
         var ptr = new IntPtr();
         Wow64DisableWow64FsRedirection(ref ptr);
 
         try
         {
-            Registry.SetValue(registryKey, "LockScreenImageStatus", 1, RegistryValueKind.DWord);
-            Registry.SetValue(registryKey, "LockScreenImagePath", path, RegistryValueKind.String);
-            Registry.SetValue(registryKey, "LockScreenImageUrl", path, RegistryValueKind.String);
+            Registry.SetValue(personalizationcsp, "LockScreenImageStatus", 1, RegistryValueKind.DWord);
+            Registry.SetValue(personalizationcsp, "LockScreenImagePath", path, RegistryValueKind.String);
+            Registry.SetValue(personalizationcsp, "LockScreenImageUrl", path, RegistryValueKind.String);
+            
+            Registry.SetValue(enforceLockScreenAndLogonImage, "policytype", 0, RegistryValueKind.DWord);
+            Registry.SetValue(enforcelockscreenprovider, "policytype", 0, RegistryValueKind.DWord);
+            
+            // Seems to only work once, and then have to restart the machine to make it work again. 
+            // It seems to disable setting the lock screen image in the settings app with the text:
+            // *Some settings are managed by your organization
+            // enforceLockScreenAndLogonImage and enforcelockscreenprovider are both set to 0 to try to disable it,
+            // but it doesn't seem to work.
+            // Need to investigate further and disable it for now.
         }
         catch
         {