Files
PowerToys/src/modules/LightSwitch/LightSwitchService/LightSwitchStateManager.h

52 lines
1.5 KiB
C
Raw Normal View History

#pragma once
#include "LightSwitchSettings.h"
#include <optional>
// Represents runtime-only information (not saved in settings.json)
struct LightSwitchState
{
ScheduleMode lastAppliedMode = ScheduleMode::Off;
bool isManualOverride = false;
bool isSystemLightActive = false;
bool isAppsLightActive = false;
2025-12-10 08:15:34 -05:00
bool isNightLightActive = false;
int lastEvaluatedDay = -1;
int lastTickMinutes = -1;
// Derived, runtime-resolved times
int effectiveLightMinutes = 0; // the boundary we actually act on
int effectiveDarkMinutes = 0; // includes offsets if needed
};
// The controller that reacts to settings changes, time ticks, and manual overrides.
class LightSwitchStateManager
{
public:
LightSwitchStateManager();
// Called when settings.json changes or stabilizes.
void OnSettingsChanged();
// Called every minute (from service worker tick).
void OnTick(int currentMinutes);
// Called when manual override is toggled (via shortcut or system change).
void OnManualOverride();
2025-12-10 08:15:34 -05:00
// Called when night light changes in windows settings
void OnNightLightChange();
// Initial sync at startup to align internal state with system theme
void SyncInitialThemeState();
// Accessor for current state (optional, for debugging or telemetry)
const LightSwitchState& GetState() const { return _state; }
private:
LightSwitchState _state;
std::mutex _stateMutex;
void EvaluateAndApplyIfNeeded();
bool CoordinatesAreValid(const std::wstring& lat, const std::wstring& lon);
};