Revert "[Light Switch] Switch desktop wallpapers with the Light/Dark mode" (#44588)

This uses IVirtualDesktopManagerInternal*, which is an undocumented
Windows Shell internal API.
These interfaces are not stable and can change across Windows updates,
so using them in PowerToys carries some long-term risk
This commit is contained in:
Kai Tao
2026-01-08 10:14:43 +08:00
committed by GitHub
parent 08d4689ec5
commit 9c58574484
25 changed files with 310 additions and 1118 deletions

View File

@@ -16,13 +16,9 @@ using Microsoft.PowerToys.Settings.UI.ViewModels;
using Microsoft.UI.Dispatching;
using Microsoft.UI.Xaml;
using Microsoft.UI.Xaml.Controls;
using Microsoft.UI.Xaml.Media.Imaging;
using Microsoft.Windows.Storage.Pickers;
using PowerToys.GPOWrapper;
using Settings.UI.Library;
using Windows.Devices.Geolocation;
using Windows.Storage;
using Windows.Storage.Streams;
namespace Microsoft.PowerToys.Settings.UI.Views
{
@@ -189,7 +185,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
// need to save the values
this.ViewModel.Latitude = latitude.ToString(CultureInfo.InvariantCulture);
this.ViewModel.Longitude = longitude.ToString(CultureInfo.InvariantCulture);
this.ViewModel.SyncButtonInformation = $"{this.ViewModel.Latitude}<7D>, {this.ViewModel.Longitude}<7D>";
this.ViewModel.SyncButtonInformation = $"{this.ViewModel.Latitude}<7D>, {this.ViewModel.Longitude}<7D>";
var result = SunCalc.CalculateSunriseSunset(latitude, longitude, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
@@ -395,50 +391,5 @@ namespace Microsoft.PowerToys.Settings.UI.Views
this.LocationWarningBar.Visibility = Visibility.Visible;
}
}
private async void PickWallpaper_Click(object sender, RoutedEventArgs e)
{
var tag = (sender as Button).Tag as string;
var fileOpenPicker = new FileOpenPicker((sender as Button).XamlRoot.ContentIslandEnvironment.AppWindowId);
string[] extensions = { ".jpg", ".jpeg", ".bmp", ".dib", ".png", ".jfif", ".jpe", ".gif", ".tif", ".tiff", ".wdp", ".heic", ".heif", ".heics", ".heifs", ".hif", ".avci", ".avcs", ".avif", ".avifs", ".jxr", ".jxl", ".webp" };
foreach (var ext in extensions)
{
fileOpenPicker.FileTypeFilter.Add(ext);
}
fileOpenPicker.SuggestedStartLocation = PickerLocationId.PicturesLibrary;
var selectedFile = await fileOpenPicker.PickSingleFileAsync();
if (selectedFile == null)
{
return;
}
if (!string.IsNullOrEmpty(ViewModel.WallpaperPathLight) && tag == "Light")
{
LightSwitchViewModel.DeleteFile(ViewModel.WallpaperPathLight);
ViewModel.WallpaperPathLight = string.Empty;
}
else if (!string.IsNullOrEmpty(ViewModel.WallpaperPathDark) && tag == "Dark")
{
LightSwitchViewModel.DeleteFile(ViewModel.WallpaperPathDark);
ViewModel.WallpaperPathDark = string.Empty;
}
var srcFile = await StorageFile.GetFileFromPathAsync(selectedFile.Path);
var settingsFolder = await StorageFolder.GetFolderFromPathAsync(Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Microsoft\\PowerToys\\LightSwitch");
var dstFile = await settingsFolder.CreateFileAsync($"{tag}{DateTime.Now.ToFileTime()}{srcFile.FileType}", CreationCollisionOption.ReplaceExisting);
await FileIO.WriteBufferAsync(dstFile, await FileIO.ReadBufferAsync(srcFile));
if (tag == "Light")
{
ViewModel.WallpaperPathLight = dstFile.Path;
}
else if (tag == "Dark")
{
ViewModel.WallpaperPathDark = dstFile.Path;
}
}
}
}