mirror of
https://github.com/microsoft/PowerToys.git
synced 2025-12-14 18:57:55 +01:00
Everything working as expected
This commit is contained in:
@@ -120,6 +120,7 @@ static std::pair<int, int> update_sun_times(auto& settings)
|
||||
// Internal: decide what should happen now
|
||||
void LightSwitchStateManager::EvaluateAndApplyIfNeeded()
|
||||
{
|
||||
LightSwitchSettings::instance().LoadSettings();
|
||||
const auto& _currentSettings = LightSwitchSettings::settings();
|
||||
auto now = GetNowMinutes();
|
||||
|
||||
@@ -150,6 +151,11 @@ void LightSwitchStateManager::EvaluateAndApplyIfNeeded()
|
||||
_state.effectiveLightMinutes = newLightTime + _currentSettings.sunrise_offset;
|
||||
_state.effectiveDarkMinutes = newDarkTime + _currentSettings.sunset_offset;
|
||||
}
|
||||
else
|
||||
{
|
||||
_state.effectiveLightMinutes = _currentSettings.lightTime + _currentSettings.sunrise_offset;
|
||||
_state.effectiveDarkMinutes = _currentSettings.darkTime + _currentSettings.sunset_offset;
|
||||
}
|
||||
}
|
||||
else if (_currentSettings.scheduleMode == ScheduleMode::FixedHours)
|
||||
{
|
||||
@@ -200,6 +206,17 @@ void LightSwitchStateManager::EvaluateAndApplyIfNeeded()
|
||||
bool appsNeedsToChange = _currentSettings.changeApps && (_state.isAppsLightActive != shouldBeLight);
|
||||
bool systemNeedsToChange = _currentSettings.changeSystem && (_state.isSystemLightActive != shouldBeLight);
|
||||
|
||||
Logger::debug(
|
||||
L"[LightSwitchStateManager] now = {:02d}:{:02d}, light boundary = {:02d}:{:02d} ({}), dark boundary = {:02d}:{:02d} ({})",
|
||||
now / 60,
|
||||
now % 60,
|
||||
_state.effectiveLightMinutes / 60,
|
||||
_state.effectiveLightMinutes % 60,
|
||||
_state.effectiveLightMinutes,
|
||||
_state.effectiveDarkMinutes / 60,
|
||||
_state.effectiveDarkMinutes % 60,
|
||||
_state.effectiveDarkMinutes);
|
||||
|
||||
Logger::debug("should be light = {}, apps needs change = {}, system needs change = {}",
|
||||
shouldBeLight ? "true" : "false",
|
||||
appsNeedsToChange ? "true" : "false",
|
||||
|
||||
@@ -259,7 +259,7 @@
|
||||
Maximum="90"
|
||||
Minimum="-90"
|
||||
ValueChanged="LatLonBox_ValueChanged"
|
||||
Value="{x:Bind ViewModel.Latitude, Mode=TwoWay, Converter={StaticResource StringToDoubleConverter}}" />
|
||||
Value="{x:Bind ViewModel.LocationPanelLatitude, Mode=TwoWay}" />
|
||||
<NumberBox
|
||||
x:Name="LongitudeBox"
|
||||
x:Uid="LightSwitch_LongitudeBox"
|
||||
@@ -268,7 +268,7 @@
|
||||
Maximum="180"
|
||||
Minimum="-180"
|
||||
ValueChanged="LatLonBox_ValueChanged"
|
||||
Value="{x:Bind ViewModel.Longitude, Mode=TwoWay, Converter={StaticResource StringToDoubleConverter}}" />
|
||||
Value="{x:Bind ViewModel.LocationPanelLongitude, Mode=TwoWay}" />
|
||||
<Button
|
||||
x:Name="SyncButton"
|
||||
x:Uid="LightSwitch_FindLocationAutomation"
|
||||
|
||||
@@ -56,7 +56,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
this.ViewModel = new LightSwitchViewModel(darkSettings, this.sendConfigMsg);
|
||||
this.ViewModel.PropertyChanged += ViewModel_PropertyChanged;
|
||||
|
||||
this.LoadSettings();
|
||||
this.LoadSettings(this.generalSettingsRepository, this.moduleSettingsRepository);
|
||||
|
||||
DataContext = this.ViewModel;
|
||||
|
||||
@@ -121,6 +121,9 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
double latitude = Math.Round(pos.Coordinate.Point.Position.Latitude);
|
||||
double longitude = Math.Round(pos.Coordinate.Point.Position.Longitude);
|
||||
|
||||
ViewModel.LocationPanelLatitude = latitude;
|
||||
ViewModel.LocationPanelLongitude = longitude;
|
||||
|
||||
var result = SunCalc.CalculateSunriseSunset(latitude, longitude, DateTime.Now.Year, DateTime.Now.Month, DateTime.Now.Day);
|
||||
|
||||
this.ViewModel.LocationPanelLightTimeMinutes = (result.SunriseHour * 60) + result.SunriseMinute;
|
||||
@@ -284,22 +287,22 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
}
|
||||
}
|
||||
|
||||
private void LoadSettings()
|
||||
private void LoadSettings(SettingsRepository<GeneralSettings> generalSettingsRepository, SettingsRepository<LightSwitchSettings> moduleSettingsRepository)
|
||||
{
|
||||
if (this.generalSettingsRepository != null)
|
||||
if (generalSettingsRepository != null)
|
||||
{
|
||||
if (this.moduleSettingsRepository != null)
|
||||
if (moduleSettingsRepository != null)
|
||||
{
|
||||
UpdateViewModelSettings(this.moduleSettingsRepository.SettingsConfig, this.generalSettingsRepository.SettingsConfig);
|
||||
UpdateViewModelSettings(moduleSettingsRepository.SettingsConfig, generalSettingsRepository.SettingsConfig);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentNullException(nameof(this.moduleSettingsRepository));
|
||||
throw new ArgumentNullException(nameof(moduleSettingsRepository));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new ArgumentNullException(nameof(this.generalSettingsRepository));
|
||||
throw new ArgumentNullException(nameof(generalSettingsRepository));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -332,7 +335,7 @@ namespace Microsoft.PowerToys.Settings.UI.Views
|
||||
this.suppressViewModelUpdates = true;
|
||||
|
||||
this.moduleSettingsRepository.ReloadSettings();
|
||||
this.LoadSettings();
|
||||
this.LoadSettings(this.generalSettingsRepository, this.moduleSettingsRepository);
|
||||
|
||||
this.suppressViewModelUpdates = false;
|
||||
});
|
||||
|
||||
@@ -407,6 +407,36 @@ namespace Microsoft.PowerToys.Settings.UI.ViewModels
|
||||
}
|
||||
}
|
||||
|
||||
private double _locationPanelLatitude;
|
||||
private double _locationPanelLongitude;
|
||||
|
||||
public double LocationPanelLatitude
|
||||
{
|
||||
get => _locationPanelLatitude;
|
||||
set
|
||||
{
|
||||
if (_locationPanelLatitude != value)
|
||||
{
|
||||
_locationPanelLatitude = value;
|
||||
NotifyPropertyChanged();
|
||||
NotifyPropertyChanged(nameof(LocationPanelLightTime));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public double LocationPanelLongitude
|
||||
{
|
||||
get => _locationPanelLongitude;
|
||||
set
|
||||
{
|
||||
if (_locationPanelLongitude != value)
|
||||
{
|
||||
_locationPanelLongitude = value;
|
||||
NotifyPropertyChanged();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private int _locationPanelLightTime;
|
||||
private int _locationPanelDarkTime;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user