From 2dc4e49f02daa36551ea72c04717c3780487a957 Mon Sep 17 00:00:00 2001 From: Timothy Johnson Date: Sat, 1 Jun 2019 21:10:30 -0400 Subject: [PATCH] Remove actions from UWP app that require editing registry keys --- src/DesktopHelper.cs | 8 ++++++++ src/SystemThemeChanger.cs | 2 +- src/UwpDesktop.cs | 2 ++ src/UwpHelper.cs | 11 +++++++++++ src/WallpaperChangeScheduler.cs | 2 +- 5 files changed, 23 insertions(+), 2 deletions(-) diff --git a/src/DesktopHelper.cs b/src/DesktopHelper.cs index abc7abf..8f3feb3 100644 --- a/src/DesktopHelper.cs +++ b/src/DesktopHelper.cs @@ -57,5 +57,13 @@ public override void OpenUpdateLink() { System.Diagnostics.Process.Start(updateLink); } + + public override void SetWallpaper(string imageFilename) + { + string imagePath = Path.Combine(Directory.GetCurrentDirectory(), "themes", + ThemeManager.currentTheme.themeId, imageFilename); + + WallpaperApi.SetWallpaper(imagePath); + } } } diff --git a/src/SystemThemeChanger.cs b/src/SystemThemeChanger.cs index 4b2c2e4..670db64 100644 --- a/src/SystemThemeChanger.cs +++ b/src/SystemThemeChanger.cs @@ -23,7 +23,7 @@ public static List GetMenuItems() { RegistryKey themeKey = Registry.CurrentUser.OpenSubKey(registryThemeLocation); - if (themeKey != null) + if (!UwpDesktop.IsRunningAsUwp() && (themeKey != null)) { themeKey.Close(); diff --git a/src/UwpDesktop.cs b/src/UwpDesktop.cs index 21607ae..be73ea2 100644 --- a/src/UwpDesktop.cs +++ b/src/UwpDesktop.cs @@ -20,6 +20,8 @@ abstract class PlatformHelper public abstract void ToggleStartOnBoot(); public abstract void OpenUpdateLink(); + + public abstract void SetWallpaper(string imageFilename); } class UwpDesktop diff --git a/src/UwpHelper.cs b/src/UwpHelper.cs index 1d18aca..a1c261f 100644 --- a/src/UwpHelper.cs +++ b/src/UwpHelper.cs @@ -75,6 +75,17 @@ await Windows.System.Launcher.LaunchUriAsync( new Uri("ms-windows-store://downloadsandupdates")); } + public override async void SetWallpaper(string imageFilename) + { + var uri = new Uri("ms-appdata:///local/themes/" + ThemeManager.currentTheme.themeId + + "/" + imageFilename); + var file = await Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri); + + var profileSettings = + Windows.System.UserProfile.UserProfilePersonalizationSettings.Current; + await profileSettings.TrySetWallpaperImageAsync(file); + } + public static async void SetLockScreenImage(string imageFilename) { var uri = new Uri("ms-appdata:///local/themes/" + ThemeManager.currentTheme.themeId + diff --git a/src/WallpaperChangeScheduler.cs b/src/WallpaperChangeScheduler.cs index 4dd8616..5332a38 100644 --- a/src/WallpaperChangeScheduler.cs +++ b/src/WallpaperChangeScheduler.cs @@ -227,7 +227,7 @@ private void SetWallpaper(int imageId) return; } - WallpaperApi.SetWallpaper(imagePath); + UwpDesktop.GetHelper().SetWallpaper(imageFilename); if (UwpDesktop.IsRunningAsUwp() && JsonConfig.settings.changeLockScreen) {