Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .github/actions/spell-check/allow/names.txt
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ Skia
Spotify
taskmgr
tldr
Troms
Vanara
wangyi
WEX
Expand Down
1 change: 1 addition & 0 deletions .github/actions/spell-check/expect.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2341,3 +2341,4 @@ YTimer
zamora
zonability
Zorder
Bluelight
1 change: 1 addition & 0 deletions PowerToys.slnx
Original file line number Diff line number Diff line change
Expand Up @@ -707,6 +707,7 @@
<Platform Solution="*|x64" Project="x64" />
<Deploy />
</Project>
<Project Path="src/modules/LightSwitch/UnitTests/UnitTests-LightSwitch.vcxproj" Id="b1a2c3d4-1111-2222-3333-444455556666" />
</Folder>
<Folder Name="/modules/PowerDisplay/">
<Project Path="src/modules/powerdisplay/PowerDisplay.Models/PowerDisplay.Models.csproj">
Expand Down
61 changes: 2 additions & 59 deletions src/modules/LightSwitch/LightSwitchService/LightSwitchSettings.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,66 +13,9 @@
#include <common/SettingsAPI/settings_objects.h>
#include <SettingsConstants.h>

class SettingsObserver;

enum class ScheduleMode
{
Off,
FixedHours,
SunsetToSunrise,
FollowNightLight,
// Add more in the future
};

inline std::wstring ToString(ScheduleMode mode)
{
switch (mode)
{
case ScheduleMode::FixedHours:
return L"FixedHours";
case ScheduleMode::SunsetToSunrise:
return L"SunsetToSunrise";
case ScheduleMode::FollowNightLight:
return L"FollowNightLight";
default:
return L"Off";
}
}

inline ScheduleMode FromString(const std::wstring& str)
{
if (str == L"SunsetToSunrise")
return ScheduleMode::SunsetToSunrise;
if (str == L"FixedHours")
return ScheduleMode::FixedHours;
if (str == L"FollowNightLight")
return ScheduleMode::FollowNightLight;
else
return ScheduleMode::Off;
}

struct LightSwitchConfig
{
ScheduleMode scheduleMode = ScheduleMode::FixedHours;

std::wstring latitude = L"0.0";
std::wstring longitude = L"0.0";

// Stored as minutes since midnight
int lightTime = 8 * 60; // 08:00 default
int darkTime = 20 * 60; // 20:00 default
#include "../LightSwitchTypes.h"

int sunrise_offset = 0;
int sunset_offset = 0;

bool changeSystem = false;
bool changeApps = false;

bool enableDarkModeProfile = false;
bool enableLightModeProfile = false;
std::wstring darkModeProfile = L"";
std::wstring lightModeProfile = L"";
};
class SettingsObserver;

class LightSwitchSettings
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,20 +94,7 @@ void LightSwitchStateManager::OnNightLightChange()
EvaluateAndApplyIfNeeded();
}

// Helpers
bool LightSwitchStateManager::CoordinatesAreValid(const std::wstring& lat, const std::wstring& lon)
{
try
{
double latVal = std::stod(lat);
double lonVal = std::stod(lon);
return !(latVal == 0 && lonVal == 0) && (latVal >= -90.0 && latVal <= 90.0) && (lonVal >= -180.0 && lonVal <= 180.0);
}
catch (...)
{
return false;
}
}
// CoordinatesAreValid is now a free function in LightSwitchUtils.h

void LightSwitchStateManager::SyncInitialThemeState()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ class LightSwitchStateManager
std::mutex _stateMutex;

void EvaluateAndApplyIfNeeded();
bool CoordinatesAreValid(const std::wstring& lat, const std::wstring& lon);

// Notify PowerDisplay module about theme change to apply display profiles
void NotifyPowerDisplay(bool isLight);
Expand Down
19 changes: 19 additions & 0 deletions src/modules/LightSwitch/LightSwitchService/LightSwitchUtils.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,24 @@
#pragma once
#include <windows.h>
#include <string>

// Validates that lat/lon strings represent non-sentinel, in-range coordinates.
// Rejects (0,0) as a sentinel for "not configured".
inline bool CoordinatesAreValid(const std::wstring& lat, const std::wstring& lon)
{
try
{
double latVal = std::stod(lat);
double lonVal = std::stod(lon);
return !(latVal == 0 && lonVal == 0) &&
(latVal >= -90.0 && latVal <= 90.0) &&
(lonVal >= -180.0 && lonVal <= 180.0);
}
catch (...)
{
return false;
}
}

constexpr bool ShouldBeLight(int nowMinutes, int lightTime, int darkTime)
{
Expand Down
68 changes: 68 additions & 0 deletions src/modules/LightSwitch/LightSwitchTypes.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
// Copyright (c) Microsoft Corporation
// The Microsoft Corporation licenses this file to you under the MIT license.
// See the LICENSE file in the project root for more information.

#pragma once

#include <string>

// Shared lightweight types for LightSwitch — no heavy dependencies.
// Consumed by both the service (LightSwitchSettings.h) and unit tests.

enum class ScheduleMode
{
Off,
FixedHours,
SunsetToSunrise,
FollowNightLight,
};

inline std::wstring ToString(ScheduleMode mode)
{
switch (mode)
{
case ScheduleMode::FixedHours:
return L"FixedHours";
case ScheduleMode::SunsetToSunrise:
return L"SunsetToSunrise";
case ScheduleMode::FollowNightLight:
return L"FollowNightLight";
default:
return L"Off";
}
}

inline ScheduleMode FromString(const std::wstring& str)
{
if (str == L"SunsetToSunrise")
return ScheduleMode::SunsetToSunrise;
if (str == L"FixedHours")
return ScheduleMode::FixedHours;
if (str == L"FollowNightLight")
return ScheduleMode::FollowNightLight;
else
return ScheduleMode::Off;
}

struct LightSwitchConfig
{
ScheduleMode scheduleMode = ScheduleMode::FixedHours;

std::wstring latitude = L"0.0";
std::wstring longitude = L"0.0";

// Stored as minutes since midnight
int lightTime = 8 * 60; // 08:00 default
int darkTime = 20 * 60; // 20:00 default

int sunrise_offset = 0;
int sunset_offset = 0;

bool changeSystem = false;
bool changeApps = false;

bool enableDarkModeProfile = false;
bool enableLightModeProfile = false;
std::wstring darkModeProfile = L"";
std::wstring lightModeProfile = L"";
};
Loading
Loading