mirror of
https://github.com/microsoft/PowerToys.git
synced 2026-04-05 02:36:19 +02:00
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:
@@ -9,7 +9,6 @@
|
||||
xmlns:local="using:Microsoft.PowerToys.Settings.UI.Helpers"
|
||||
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
|
||||
xmlns:tkcontrols="using:CommunityToolkit.WinUI.Controls"
|
||||
xmlns:tkconverters="using:CommunityToolkit.WinUI.Converters"
|
||||
xmlns:ui="using:CommunityToolkit.WinUI"
|
||||
xmlns:viewModels="using:Microsoft.PowerToys.Settings.UI.ViewModels"
|
||||
d:DataContext="{d:DesignInstance Type=viewModels:LightSwitchViewModel}"
|
||||
@@ -18,12 +17,6 @@
|
||||
<local:NavigablePage.Resources>
|
||||
<converters:TimeSpanToFriendlyTimeConverter x:Key="TimeSpanToFriendlyTimeConverter" />
|
||||
<converters:StringToDoubleConverter x:Key="StringToDoubleConverter" />
|
||||
<tkconverters:BoolNegationConverter x:Key="BoolNegationConverter" />
|
||||
<tkconverters:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />
|
||||
<tkconverters:BoolToVisibilityConverter
|
||||
x:Key="BoolToInvertedVisibilityConverter"
|
||||
FalseValue="Visible"
|
||||
TrueValue="Collapsed" />
|
||||
</local:NavigablePage.Resources>
|
||||
<Grid>
|
||||
<controls:SettingsPageControl
|
||||
@@ -218,124 +211,6 @@
|
||||
</tkcontrols:SettingsCard>
|
||||
</tkcontrols:SettingsExpander.Items>
|
||||
</tkcontrols:SettingsExpander>
|
||||
<tkcontrols:SettingsExpander
|
||||
x:Uid="LightSwitch_WallpaperExpander"
|
||||
HeaderIcon="{ui:FontIcon Glyph=}"
|
||||
IsExpanded="True">
|
||||
<ToggleSwitch AutomationProperties.AutomationId="Toggle_WallpaperSwitch" IsOn="{x:Bind ViewModel.IsWallpaperEnabled, Mode=TwoWay}" />
|
||||
<tkcontrols:SettingsExpander.Items>
|
||||
<tkcontrols:SettingsCard HorizontalContentAlignment="Stretch" ContentAlignment="Left">
|
||||
<Grid HorizontalAlignment="Stretch">
|
||||
<Grid.RowDefinitions>
|
||||
<RowDefinition Height="*" />
|
||||
</Grid.RowDefinitions>
|
||||
<Grid.ColumnDefinitions>
|
||||
<ColumnDefinition Width="*" />
|
||||
<ColumnDefinition Width="20px" />
|
||||
<ColumnDefinition Width="*" />
|
||||
</Grid.ColumnDefinitions>
|
||||
<TextBlock
|
||||
x:Uid="LightSwitch_WallpaperImageUnavailable"
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
TextWrapping="Wrap"
|
||||
Visibility="{x:Bind ViewModel.IsLightWallpaperValid, Converter={StaticResource BoolToInvertedVisibilityConverter}, Mode=OneWay}" />
|
||||
<Image
|
||||
Grid.Row="0"
|
||||
Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
Source="{x:Bind ViewModel.WallpaperSourceLight, Mode=OneWay}"
|
||||
Tag="Light" />
|
||||
<TextBlock
|
||||
x:Uid="LightSwitch_WallpaperImageUnavailable"
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}"
|
||||
TextWrapping="Wrap"
|
||||
Visibility="{x:Bind ViewModel.IsDarkWallpaperValid, Converter={StaticResource BoolToInvertedVisibilityConverter}, Mode=OneWay}" />
|
||||
<Image
|
||||
Grid.Row="0"
|
||||
Grid.Column="2"
|
||||
Source="{x:Bind ViewModel.WallpaperSourceDark, Mode=OneWay}"
|
||||
Tag="Dark" />
|
||||
</Grid>
|
||||
</tkcontrols:SettingsCard>
|
||||
<tkcontrols:SettingsCard x:Uid="LightSwitch_WallpaperSelect">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<TextBlock
|
||||
x:Uid="LightSwitch_WallpaperLight"
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
|
||||
<Button
|
||||
x:Uid="LightSwitch_WallpaperBrowse"
|
||||
Grid.Row="2"
|
||||
Grid.Column="0"
|
||||
AutomationProperties.AutomationId="Pick_ButtonLight"
|
||||
Click="PickWallpaper_Click"
|
||||
Tag="Light" />
|
||||
<TextBlock
|
||||
x:Uid="LightSwitch_WallpaperDark"
|
||||
Grid.Row="2"
|
||||
Grid.Column="2"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
|
||||
<Button
|
||||
x:Uid="LightSwitch_WallpaperBrowse"
|
||||
Grid.Row="2"
|
||||
Grid.Column="2"
|
||||
AutomationProperties.AutomationId="Pick_ButtonDark"
|
||||
Click="PickWallpaper_Click"
|
||||
Tag="Dark" />
|
||||
</StackPanel>
|
||||
</tkcontrols:SettingsCard>
|
||||
<tkcontrols:SettingsCard x:Uid="LightSwitch_WallpaperStyle">
|
||||
<StackPanel Orientation="Horizontal" Spacing="8">
|
||||
<TextBlock
|
||||
x:Uid="LightSwitch_WallpaperLight"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
|
||||
<ComboBox AutomationProperties.AutomationId="Toggle_WallpaperStyleSwitchLight" SelectedIndex="{x:Bind ViewModel.WallpaperStyleLight, Mode=TwoWay}">
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleCenter" AutomationProperties.AutomationId="CenterCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleTile" AutomationProperties.AutomationId="TileCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleStretch" AutomationProperties.AutomationId="StretchCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleFit" AutomationProperties.AutomationId="FitCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleFill" AutomationProperties.AutomationId="FillCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleSpan" AutomationProperties.AutomationId="SpanCBItem_StyleSwitch" />
|
||||
</ComboBox>
|
||||
<TextBlock
|
||||
x:Uid="LightSwitch_WallpaperDark"
|
||||
VerticalAlignment="Center"
|
||||
Foreground="{ThemeResource TextFillColorSecondaryBrush}" />
|
||||
<ComboBox AutomationProperties.AutomationId="Toggle_WallpaperStyleSwitchDark" SelectedIndex="{x:Bind ViewModel.WallpaperStyleDark, Mode=TwoWay}">
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleCenter" AutomationProperties.AutomationId="CenterCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleTile" AutomationProperties.AutomationId="TileCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleStretch" AutomationProperties.AutomationId="StretchCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleFit" AutomationProperties.AutomationId="FitCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleFill" AutomationProperties.AutomationId="FillCBItem_StyleSwitch" />
|
||||
<ComboBoxItem x:Uid="LightSwitch_StyleSpan" AutomationProperties.AutomationId="SpanCBItem_StyleSwitch" />
|
||||
</ComboBox>
|
||||
</StackPanel>
|
||||
</tkcontrols:SettingsCard>
|
||||
<tkcontrols:SettingsCard x:Uid="LightSwitch_WallpaperVirtualDesktop" Visibility="{x:Bind ViewModel.Is24H2OrLater, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneTime}">
|
||||
<ToggleSwitch AutomationProperties.AutomationId="Toggle_WallpaperVirtualDesktopSwitch" IsOn="{x:Bind ViewModel.IsVirtualDesktopEnabled, Mode=TwoWay}" />
|
||||
</tkcontrols:SettingsCard>
|
||||
<tkcontrols:SettingsCard Background="{ThemeResource SystemFillColorSuccessBackgroundBrush}" Visibility="{x:Bind ViewModel.Is24H2OrLater, Converter={StaticResource BoolToVisibilityConverter}, Mode=OneTime}">
|
||||
<tkcontrols:SettingsCard.Header>
|
||||
<TextBlock x:Uid="LightSwitch_VirtualDesktopInfo" TextWrapping="Wrap" />
|
||||
</tkcontrols:SettingsCard.Header>
|
||||
</tkcontrols:SettingsCard>
|
||||
<tkcontrols:SettingsCard Background="{ThemeResource SystemFillColorSuccessBackgroundBrush}" Visibility="{x:Bind ViewModel.Is24H2OrLater, Converter={StaticResource BoolToInvertedVisibilityConverter}, Mode=OneTime}">
|
||||
<tkcontrols:SettingsCard.Header>
|
||||
<TextBlock x:Uid="LightSwitch_DetectWindows24H2Info" TextWrapping="Wrap" />
|
||||
</tkcontrols:SettingsCard.Header>
|
||||
</tkcontrols:SettingsCard>
|
||||
</tkcontrols:SettingsExpander.Items>
|
||||
</tkcontrols:SettingsExpander>
|
||||
</controls:SettingsGroup>
|
||||
<!-- Force mode buttons -->
|
||||
<!--<tkcontrols:SettingsCard
|
||||
|
||||
@@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5456,54 +5456,6 @@ To record a specific window, enter the hotkey with the Alt key in the opposite m
|
||||
<data name="LightSwitch_SunsetTooltip.Text" xml:space="preserve">
|
||||
<value>Sunset</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperExpander.Header" xml:space="preserve">
|
||||
<value>Wallpaper changes with the color mode</value>
|
||||
</data>
|
||||
<data name="LightSwitch_StyleFill.Content" xml:space="preserve">
|
||||
<value>Fill</value>
|
||||
</data>
|
||||
<data name="LightSwitch_StyleFit.Content" xml:space="preserve">
|
||||
<value>Fit</value>
|
||||
</data>
|
||||
<data name="LightSwitch_StyleStretch.Content" xml:space="preserve">
|
||||
<value>Stretch</value>
|
||||
</data>
|
||||
<data name="LightSwitch_StyleTile.Content" xml:space="preserve">
|
||||
<value>Tile</value>
|
||||
</data>
|
||||
<data name="LightSwitch_StyleCenter.Content" xml:space="preserve">
|
||||
<value>Center</value>
|
||||
</data>
|
||||
<data name="LightSwitch_StyleSpan.Content" xml:space="preserve">
|
||||
<value>Span</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperBrowse.Content" xml:space="preserve">
|
||||
<value>Browse</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperLight.Text" xml:space="preserve">
|
||||
<value>Light:</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperDark.Text" xml:space="preserve">
|
||||
<value>Dark:</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperImageUnavailable.Text" xml:space="preserve">
|
||||
<value>Image preview unavailable, may not exist or is corrupted</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperSelect.Header" xml:space="preserve">
|
||||
<value>Choose images for different modes</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperStyle.Header" xml:space="preserve">
|
||||
<value>Choose fits for your desktop images</value>
|
||||
</data>
|
||||
<data name="LightSwitch_WallpaperVirtualDesktop.Header" xml:space="preserve">
|
||||
<value>Apply wallpaper to all virtual desktops</value>
|
||||
</data>
|
||||
<data name="LightSwitch_VirtualDesktopInfo.Text" xml:space="preserve">
|
||||
<value>Apply wallpaper to all virtual desktops is an experimental feature, only supported on Windows 24H2 and later versions. It may become unavailable or cause errors due to Windows updates. If you find that the LightSwitch service is not running properly after enabling this feature, please disable the feature and file a bug report with your Windows version.</value>
|
||||
</data>
|
||||
<data name="LightSwitch_DetectWindows24H2Info.Text" xml:space="preserve">
|
||||
<value>It has been detected that your Windows version is earlier than 24H2. On such versions, switching to another virtual desktop may cause the wallpaper to revert. If you are using virtual desktops, it is not recommended to enable this feature. Alternatively, upgrade your Windows version to 24H2 or later for the best experience.</value>
|
||||
</data>
|
||||
<data name="Close_NavViewItem.Content" xml:space="preserve">
|
||||
<value>Close PowerToys</value>
|
||||
<comment>Don't loc "PowerToys"</comment>
|
||||
|
||||
@@ -5,9 +5,7 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.Collections.ObjectModel;
|
||||
using System.ComponentModel;
|
||||
using System.Globalization;
|
||||
using System.IO;
|
||||
using System.Linq;
|
||||
using System.Runtime.CompilerServices;
|
||||
using System.Text.Json;
|
||||
@@ -17,12 +15,9 @@ using Microsoft.PowerToys.Settings.UI.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.Library;
|
||||
using Microsoft.PowerToys.Settings.UI.Library.Helpers;
|
||||
using Microsoft.PowerToys.Settings.UI.SerializationContext;
|
||||
using Microsoft.UI.Xaml.Media;
|
||||
using Microsoft.UI.Xaml.Media.Imaging;
|
||||
using Newtonsoft.Json.Linq;
|
||||
using Settings.UI.Library;
|
||||
using Settings.UI.Library.Helpers;
|
||||
using Windows.Storage;
|
||||
|
||||
namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
{
|
||||
@@ -51,7 +46,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
};
|
||||
|
||||
_toggleThemeHotkey = _moduleSettings.Properties.ToggleThemeHotkey.Value;
|
||||
PropertyChanged += WallpaperPath_Changed;
|
||||
}
|
||||
|
||||
public override Dictionary<string, HotkeySettings[]> GetAllHotkeySettings()
|
||||
@@ -530,11 +524,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
OnPropertyChanged(nameof(Latitude));
|
||||
OnPropertyChanged(nameof(Longitude));
|
||||
OnPropertyChanged(nameof(ScheduleMode));
|
||||
OnPropertyChanged(nameof(IsWallpaperEnabled));
|
||||
OnPropertyChanged(nameof(WallpaperPathLight));
|
||||
OnPropertyChanged(nameof(WallpaperPathDark));
|
||||
OnPropertyChanged(nameof(WallpaperStyleLight));
|
||||
OnPropertyChanged(nameof(WallpaperStyleDark));
|
||||
}
|
||||
|
||||
private void UpdateSunTimes(double latitude, double longitude, string city = "n/a")
|
||||
@@ -585,222 +574,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsWallpaperEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return ModuleSettings.Properties.WallpaperEnabled.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (ModuleSettings.Properties.WallpaperEnabled.Value != value)
|
||||
{
|
||||
ModuleSettings.Properties.WallpaperEnabled.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsVirtualDesktopEnabled
|
||||
{
|
||||
get
|
||||
{
|
||||
return ModuleSettings.Properties.WallpaperVirtualDesktopEnabled.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (ModuleSettings.Properties.WallpaperVirtualDesktopEnabled.Value != value)
|
||||
{
|
||||
ModuleSettings.Properties.WallpaperVirtualDesktopEnabled.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string WallpaperPathLight
|
||||
{
|
||||
get
|
||||
{
|
||||
return ModuleSettings.Properties.WallpaperPathLight.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (ModuleSettings.Properties.WallpaperPathLight.Value != value)
|
||||
{
|
||||
ModuleSettings.Properties.WallpaperPathLight.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public string WallpaperPathDark
|
||||
{
|
||||
get
|
||||
{
|
||||
return ModuleSettings.Properties.WallpaperPathDark.Value;
|
||||
}
|
||||
|
||||
set
|
||||
{
|
||||
if (ModuleSettings.Properties.WallpaperPathDark.Value != value)
|
||||
{
|
||||
ModuleSettings.Properties.WallpaperPathDark.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsLightWallpaperValid
|
||||
{
|
||||
get => _isLightWallpaperValid;
|
||||
|
||||
set
|
||||
{
|
||||
if (_isLightWallpaperValid != value)
|
||||
{
|
||||
_isLightWallpaperValid = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public bool IsDarkWallpaperValid
|
||||
{
|
||||
get => _isDarkWallpaperValid;
|
||||
set
|
||||
{
|
||||
if (_isDarkWallpaperValid != value)
|
||||
{
|
||||
_isDarkWallpaperValid = value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImageSource WallpaperSourceLight
|
||||
{
|
||||
get => _wallpaperSourceLight;
|
||||
set
|
||||
{
|
||||
if (_wallpaperSourceLight != value)
|
||||
{
|
||||
_wallpaperSourceLight = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public ImageSource WallpaperSourceDark
|
||||
{
|
||||
get => _wallpaperSourceDark;
|
||||
set
|
||||
{
|
||||
if (_wallpaperSourceDark != value)
|
||||
{
|
||||
_wallpaperSourceDark = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int WallpaperStyleLight
|
||||
{
|
||||
get => ModuleSettings.Properties.WallpaperStyleLight.Value;
|
||||
set
|
||||
{
|
||||
if (ModuleSettings.Properties.WallpaperStyleLight.Value != value)
|
||||
{
|
||||
ModuleSettings.Properties.WallpaperStyleLight.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public int WallpaperStyleDark
|
||||
{
|
||||
get => ModuleSettings.Properties.WallpaperStyleDark.Value;
|
||||
set
|
||||
{
|
||||
if (ModuleSettings.Properties.WallpaperStyleDark.Value != value)
|
||||
{
|
||||
ModuleSettings.Properties.WallpaperStyleDark.Value = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public static void DeleteFile(string path)
|
||||
{
|
||||
// Prevent attackers from damaging files through specially crafted JSON
|
||||
var dataPath = Environment.GetFolderPath(Environment.SpecialFolder.LocalApplicationData) + "\\Microsoft\\PowerToys\\LightSwitch";
|
||||
if (!string.IsNullOrEmpty(path) && path.StartsWith(dataPath, StringComparison.OrdinalIgnoreCase))
|
||||
{
|
||||
try
|
||||
{
|
||||
File.Delete(path);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private async void WallpaperPath_Changed(object sender, PropertyChangedEventArgs e)
|
||||
{
|
||||
if (e.PropertyName == nameof(WallpaperPathLight))
|
||||
{
|
||||
var lightImage = new BitmapImage();
|
||||
try
|
||||
{
|
||||
var lightFile = await StorageFile.GetFileFromPathAsync(WallpaperPathLight);
|
||||
await lightImage.SetSourceAsync(await lightFile.OpenReadAsync()); // thrown here when the image is invalid
|
||||
WallpaperSourceLight = lightImage;
|
||||
IsLightWallpaperValid = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DeleteFile(WallpaperPathLight);
|
||||
WallpaperPathLight = null;
|
||||
IsLightWallpaperValid = false;
|
||||
WallpaperSourceLight = null;
|
||||
IsWallpaperEnabled = false;
|
||||
}
|
||||
}
|
||||
else if (e.PropertyName == nameof(WallpaperPathDark))
|
||||
{
|
||||
var darkImage = new BitmapImage();
|
||||
try
|
||||
{
|
||||
var darkFile = await StorageFile.GetFileFromPathAsync(WallpaperPathDark);
|
||||
await darkImage.SetSourceAsync(await darkFile.OpenReadAsync());
|
||||
WallpaperSourceDark = darkImage;
|
||||
IsDarkWallpaperValid = true;
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
DeleteFile(WallpaperPathDark);
|
||||
WallpaperPathDark = null;
|
||||
IsDarkWallpaperValid = false;
|
||||
WallpaperSourceDark = null;
|
||||
IsWallpaperEnabled = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int GetRegistryBuildNumber()
|
||||
{
|
||||
var value = Win32.Registry.GetValue("HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion", "CurrentBuildNumber", string.Empty);
|
||||
#pragma warning disable CA1305
|
||||
return int.Parse(value as string);
|
||||
#pragma warning restore CA1305
|
||||
}
|
||||
|
||||
public bool Is24H2OrLater
|
||||
{
|
||||
get => GetRegistryBuildNumber() > 26100;
|
||||
}
|
||||
|
||||
private bool _enabledStateIsGPOConfigured;
|
||||
private bool _enabledGPOConfiguration;
|
||||
private LightSwitchSettings _moduleSettings;
|
||||
@@ -808,10 +581,6 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
private HotkeySettings _toggleThemeHotkey;
|
||||
private TimeSpan? _sunriseTimeSpan;
|
||||
private TimeSpan? _sunsetTimeSpan;
|
||||
private bool _isLightWallpaperValid;
|
||||
private bool _isDarkWallpaperValid;
|
||||
private ImageSource _wallpaperSourceLight;
|
||||
private ImageSource _wallpaperSourceDark;
|
||||
|
||||
public ICommand ForceLightCommand { get; }
|
||||
|
||||
|
||||
Reference in New Issue
Block a user