Skip to content

Commit 4f8a11f

Browse files
committed
Move Night Light auto-suspend to Hyperion::start() to prevent LED flash
1 parent a94e90f commit 4f8a11f

2 files changed

Lines changed: 37 additions & 37 deletions

File tree

libsrc/hyperion/Hyperion.cpp

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,10 @@
77
#include <QThread>
88
#include <QVariantMap>
99

10+
#ifdef _WIN32
11+
#include <QSettings>
12+
#endif
13+
1014
// hyperion include
1115
#include <hyperion/Hyperion.h>
1216

@@ -102,6 +106,39 @@ void Hyperion::start()
102106
{
103107
Debug(_log, "Hyperion instance starting...");
104108

109+
#ifdef _WIN32
110+
// Auto-suspend if Windows Night Light is off (prevents LED flash on startup)
111+
QSettings nightLightReg(
112+
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\CloudStore\\Store\\Cache\\DefaultAccount\\"
113+
"$$windows.data.bluelightreduction.bluelightreductionstate\\Current",
114+
QSettings::NativeFormat
115+
);
116+
QByteArray nlData = nightLightReg.value("Data").toByteArray();
117+
if (!nlData.isEmpty())
118+
{
119+
QByteArray nlPattern = QByteArrayLiteral("\x69\x00\x73\x00\x45\x00\x6e\x00\x61\x00\x62\x00\x6c\x00\x65\x00\x64\x00");
120+
int nlIdx = nlData.indexOf(nlPattern);
121+
if (nlIdx >= 0)
122+
{
123+
int nlSearchEnd = qMin(nlIdx + nlPattern.size() + 64, nlData.size() - 4);
124+
bool nlActive = false;
125+
for (int j = nlIdx + nlPattern.size(); j < nlSearchEnd; ++j)
126+
{
127+
if (nlData[j] == '\x0b')
128+
{
129+
nlActive = (nlData[j + 4] == '\x01');
130+
break;
131+
}
132+
}
133+
if (!nlActive)
134+
{
135+
Info(_log, "Windows Night Light is off, suspending immediately");
136+
setSuspend(true);
137+
}
138+
}
139+
}
140+
#endif
141+
105142
_statisticsTimer.reset(new QTimer());
106143
_statisticsTimer->setTimerType(Qt::PreciseTimer);
107144
_statisticsTimer->setInterval(DEFAULT_STATISTICS_INTERVAL.count() * 1000);

src/hyperiond/systray.cpp

Lines changed: 0 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -43,37 +43,7 @@ namespace {
4343
return QIcon(QPixmap::fromImage(img));
4444
}
4545

46-
#ifdef _WIN32
47-
// CloudStore registry path for Night Light state
48-
// QSettings::NativeFormat reads directly from Windows registry
49-
bool isNightLightActive()
50-
{
51-
QSettings reg(
52-
"HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\CloudStore\\Store\\Cache\\DefaultAccount\\"
53-
"$$windows.data.bluelightreduction.bluelightreductionstate\\Current",
54-
QSettings::NativeFormat
55-
);
56-
QByteArray data = reg.value("Data").toByteArray();
57-
if (data.isEmpty())
58-
return false;
59-
60-
// Search for "isEnabled" UTF-16LE pattern in the serialized blob
61-
QByteArray pattern = QByteArrayLiteral("\x69\x00\x73\x00\x45\x00\x6e\x00\x61\x00\x62\x00\x6c\x00\x65\x00\x64\x00");
62-
int idx = data.indexOf(pattern);
63-
if (idx < 0)
64-
return false;
65-
66-
// After the key, search for VT_BOOL (0x0b) followed by the bool value
67-
int searchEnd = qMin(idx + pattern.size() + 64, data.size() - 4);
68-
for (int j = idx + pattern.size(); j < searchEnd; ++j)
69-
{
70-
if (data[j] == '\x0b')
71-
return (data[j + 4] == '\x01');
72-
}
73-
return false;
7446
}
75-
#endif
76-
}
7747

7848
SysTray::SysTray(HyperionDaemon* hyperiond)
7949
: QSystemTrayIcon(QIcon(":/hyperion-32px.png"), hyperiond)
@@ -469,13 +439,6 @@ void SysTray::handleInstanceStarted(quint8 instance)
469439
_trayMenu->insertAction(_settingsAction, _firstInstanceAction);
470440

471441
updateStartupSourceIndicator();
472-
473-
#ifdef _WIN32
474-
if (!isNightLightActive())
475-
{
476-
emit signalEvent(Event::Suspend);
477-
}
478-
#endif
479442
}
480443
else
481444
{

0 commit comments

Comments
 (0)