Skip to content

Commit 7e93094

Browse files
committed
Fix bugs when setting wallpaper image to None
1 parent 738bfee commit 7e93094

File tree

2 files changed

+20
-15
lines changed

2 files changed

+20
-15
lines changed

src/ThemeDialog.cs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,10 @@ private void ApplySelectedTheme()
120120
if (displayComboBox.SelectedIndex == 0)
121121
{
122122
activeThemes[0] = activeTheme;
123+
if (selectedIndex == 0)
124+
{
125+
activeThemes.RemoveRange(1, activeThemes.Count - 1);
126+
}
123127
}
124128
else if (IsLockScreenSelected)
125129
{

src/UwpHelper.cs

Lines changed: 16 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -72,38 +72,39 @@ public override async void OpenUpdateLink()
7272

7373
public override async void SetWallpaper(string imagePath, int displayIndex)
7474
{
75-
if (displayIndex != -1)
75+
if (displayIndex != -1 || !imagePath.StartsWith(Environment.CurrentDirectory))
7676
{
7777
WallpaperApi.SetWallpaper(imagePath, displayIndex);
7878
}
7979
else
8080
{
8181
WallpaperApi.EnableTransitions();
8282
var profileSettings = Windows.System.UserProfile.UserProfilePersonalizationSettings.Current;
83-
await profileSettings.TrySetWallpaperImageAsync(await LoadImageFile(imagePath));
83+
bool result = await profileSettings.TrySetWallpaperImageAsync(await LoadImageFile(imagePath));
84+
if (!result)
85+
{
86+
LoggingHandler.LogMessage("Failed to set wallpaper with UWP API: " + imagePath);
87+
}
8488
}
8589
}
8690

8791
public override async void SetLockScreen(string imagePath)
8892
{
8993
var profileSettings = Windows.System.UserProfile.UserProfilePersonalizationSettings.Current;
90-
await profileSettings.TrySetLockScreenImageAsync(await LoadImageFile(imagePath));
94+
bool result = await profileSettings.TrySetLockScreenImageAsync(await LoadImageFile(imagePath));
95+
if (!result)
96+
{
97+
LoggingHandler.LogMessage("Failed to set lock screen image with UWP API: " + imagePath);
98+
}
9199
}
92100

93101
private static Task<Windows.Storage.StorageFile> LoadImageFile(string imagePath)
94102
{
95-
if (imagePath.StartsWith(Environment.CurrentDirectory))
96-
{
97-
string[] pathSegments = imagePath.Split(Path.DirectorySeparatorChar);
98-
var uri = new Uri("ms-appdata:///local/themes/" +
99-
Uri.EscapeDataString(pathSegments[pathSegments.Length - 2]) + "/" +
100-
Uri.EscapeDataString(pathSegments[pathSegments.Length - 1]));
101-
return Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri).AsTask();
102-
}
103-
else
104-
{
105-
return Windows.Storage.StorageFile.GetFileFromPathAsync(imagePath).AsTask();
106-
}
103+
string[] pathSegments = imagePath.Split(Path.DirectorySeparatorChar);
104+
var uri = new Uri("ms-appdata:///local/themes/" +
105+
Uri.EscapeDataString(pathSegments[pathSegments.Length - 2]) + "/" +
106+
Uri.EscapeDataString(pathSegments[pathSegments.Length - 1]));
107+
return Windows.Storage.StorageFile.GetFileFromApplicationUriAsync(uri).AsTask();
107108
}
108109
}
109110
}

0 commit comments

Comments
 (0)