From a51b2647d97893b19c306562bbafc9a4cf389b60 Mon Sep 17 00:00:00 2001 From: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Date: Wed, 12 Nov 2025 20:51:34 -0500 Subject: [PATCH] [Light Switch] Fixed issue where number boxes in select location dialog were sometimes not updating (#43514) ## Summary of the Pull Request Ensure that even if the user enters the same values the correct buttons are enabled and the dialog shows the correct info. ## PR Checklist - [x] Closes: #43511 - [x] **Communication:** I've discussed this with core contributors already. If the work hasn't been agreed, this work might be rejected - [x] **Localization:** All end-user-facing strings can be localized --- .../SettingsXAML/Views/LightSwitchPage.xaml | 2 - .../Views/LightSwitchPage.xaml.cs | 52 +------------------ .../ViewModels/LightSwitchViewModel.cs | 2 +- 3 files changed, 2 insertions(+), 54 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml index 29885d564c..ec61a0fcd5 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml @@ -199,10 +199,8 @@ diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.cs b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.cs index c61b5c5dd8..974447a20e 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.cs @@ -35,9 +35,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views private readonly IFileSystemWatcher fileSystemWatcher; private readonly DispatcherQueue dispatcherQueue; private bool suppressViewModelUpdates; - private bool suppressLatLonChange = true; - private bool latBoxLoaded; - private bool lonBoxLoaded; private LightSwitchViewModel ViewModel { get; set; } @@ -132,8 +129,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views // Since we use this mode, we can remove the selected city data. this.ViewModel.SelectedCity = null; - this.suppressLatLonChange = false; - // ViewModel.CityTimesText = $"Sunrise: {result.SunriseHour}:{result.SunriseMinute:D2}\n" + $"Sunset: {result.SunsetHour}:{result.SunsetMinute:D2}"; this.SyncButton.IsEnabled = true; this.SyncLoader.IsActive = false; @@ -157,23 +152,10 @@ namespace Microsoft.PowerToys.Settings.UI.Views private void LatLonBox_ValueChanged(NumberBox sender, NumberBoxValueChangedEventArgs args) { - if (this.suppressLatLonChange) - { - return; - } - double latitude = this.LatitudeBox.Value; double longitude = this.LongitudeBox.Value; - if (double.IsNaN(latitude) || double.IsNaN(longitude)) - { - return; - } - - double viewModelLatitude = double.TryParse(this.ViewModel.Latitude, out var lat) ? lat : 0.0; - double viewModelLongitude = double.TryParse(this.ViewModel.Longitude, out var lon) ? lon : 0.0; - - if (Math.Abs(latitude - viewModelLatitude) < 0.0001 && Math.Abs(longitude - viewModelLongitude) < 0.0001) + if (double.IsNaN(latitude) || double.IsNaN(longitude) || (latitude == 0 && longitude == 0)) { return; } @@ -183,7 +165,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views this.ViewModel.LocationPanelLightTimeMinutes = (result.SunriseHour * 60) + result.SunriseMinute; this.ViewModel.LocationPanelDarkTimeMinutes = (result.SunsetHour * 60) + result.SunsetMinute; - // Show the panel with these values this.LocationResultPanel.Visibility = Visibility.Visible; if (this.LocationDialog != null) { @@ -214,37 +195,6 @@ namespace Microsoft.PowerToys.Settings.UI.Views this.SunriseModeChartState(); } - private void LocationDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args) - { - this.LatitudeBox.Loaded += LatLonBox_Loaded; - this.LongitudeBox.Loaded += LatLonBox_Loaded; - } - - private void LocationDialog_Closed(ContentDialog sender, ContentDialogClosedEventArgs args) - { - this.LatitudeBox.Loaded -= LatLonBox_Loaded; - this.LongitudeBox.Loaded -= LatLonBox_Loaded; - this.latBoxLoaded = false; - this.lonBoxLoaded = false; - } - - private void LatLonBox_Loaded(object sender, RoutedEventArgs e) - { - if (sender is NumberBox numberBox && numberBox == this.LatitudeBox && this.LatitudeBox.IsLoaded) - { - this.latBoxLoaded = true; - } - else if (sender is NumberBox numberBox2 && numberBox2 == this.LongitudeBox && this.LongitudeBox.IsLoaded) - { - this.lonBoxLoaded = true; - } - - if (this.latBoxLoaded && this.lonBoxLoaded) - { - this.suppressLatLonChange = false; - } - } - private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (this.suppressViewModelUpdates) diff --git a/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs b/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs index 911ec81aa2..621fa91d43 100644 --- a/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs +++ b/src/settings-ui/Settings.UI/ViewModels/LightSwitchViewModel.cs @@ -562,7 +562,7 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels SyncButtonInformation = SelectedCity != null ? SelectedCity.City - : $"{Latitude},{Longitude}"; + : $"{Latitude}°,{Longitude}°"; double lat = double.Parse(ModuleSettings.Properties.Latitude.Value, CultureInfo.InvariantCulture); double lon = double.Parse(ModuleSettings.Properties.Longitude.Value, CultureInfo.InvariantCulture);