From 48ddffa2e86c622e55712de9c6e7485e5f1a7028 Mon Sep 17 00:00:00 2001 From: Jaylyn Barbee <51131738+Jaylyn-Barbee@users.noreply.github.com> Date: Fri, 7 Nov 2025 12:51:15 -0500 Subject: [PATCH] manual boxes should be working --- .../SettingsXAML/Views/LightSwitchPage.xaml | 1 + .../Views/LightSwitchPage.xaml.cs | 36 +++++++++++++++++-- 2 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml index 628ee065a7..66d2c37109 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml @@ -202,6 +202,7 @@ x:Uid="LightSwitch_LocationDialog" IsPrimaryButtonEnabled="False" IsSecondaryButtonEnabled="True" + Opened="LocationDialog_Opened" PrimaryButtonClick="LocationDialog_PrimaryButtonClick" PrimaryButtonStyle="{StaticResource AccentButtonStyle}"> 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 b9311d4c7e..016a173dfd 100644 --- a/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.cs +++ b/src/settings-ui/Settings.UI/SettingsXAML/Views/LightSwitchPage.xaml.cs @@ -38,6 +38,8 @@ namespace Microsoft.PowerToys.Settings.UI.Views private readonly DispatcherQueue _dispatcherQueue; private bool _suppressViewModelUpdates; private bool _suppressLatLonChange = true; + private bool _latLoaded; + private bool _lonLoaded; private LightSwitchViewModel ViewModel { get; set; } @@ -174,6 +176,13 @@ namespace Microsoft.PowerToys.Settings.UI.Views ViewModel.Longitude = longitude.ToString(CultureInfo.InvariantCulture); ViewModel.SyncButtonInformation = $"{ViewModel.Latitude}°, {ViewModel.Longitude}°"; + var result = SunCalc.CalculateSunriseSunset(latitude, longitude, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day); + + // Temporarily display these preview times + ViewModel.LightTime = (result.SunriseHour * 60) + result.SunriseMinute; + ViewModel.DarkTime = (result.SunsetHour * 60) + result.SunsetMinute; + + // Show the panel with these values LocationResultPanel.Visibility = Visibility.Visible; if (LocationDialog != null) { @@ -183,18 +192,41 @@ namespace Microsoft.PowerToys.Settings.UI.Views private void LocationDialog_PrimaryButtonClick(object sender, ContentDialogButtonClickEventArgs args) { - if (ViewModel.ScheduleMode == "SunriseToSunsetUser") + /* if (ViewModel.ScheduleMode == "SunriseToSunsetUser") { ViewModel.SyncButtonInformation = ViewModel.SelectedCity.City; } else if (ViewModel.ScheduleMode == "SunriseToSunsetGeo") { ViewModel.SyncButtonInformation = $"{ViewModel.Latitude}°, {ViewModel.Longitude}°"; - } + } */ SunriseModeChartState(); } + private void LocationDialog_Opened(ContentDialog sender, ContentDialogOpenedEventArgs args) + { + LatitudeBox.Loaded += LatLonBox_Loaded; + LongitudeBox.Loaded += LatLonBox_Loaded; + } + + private void LatLonBox_Loaded(object sender, RoutedEventArgs e) + { + if (sender as NumberBox == LatitudeBox) + { + _latLoaded = true; + } + else if (sender as NumberBox == LongitudeBox) + { + _lonLoaded = true; + } + + if (_latLoaded && _lonLoaded) + { + _suppressLatLonChange = false; + } + } + private void ViewModel_PropertyChanged(object sender, System.ComponentModel.PropertyChangedEventArgs e) { if (_suppressViewModelUpdates)