Persist Framework power-button lighting across reboots
This commit is contained in:
1 parent
ddb912d4ba
commit
dc2372ef3f
10 files changed
+142
-5
No files matched your search
@@ -0,0 +1,32 @@
|
||||
// SPDX-License-Identifier: MIT
|
||||
#include "lighting.h"
|
||||
#include <QFile>
|
||||
#include <QJsonDocument>
|
||||
#include <cmath>
|
||||
|
||||
QString validatePowerButtonConfig(const QVariantMap &config)
|
||||
{
|
||||
const auto operation = config.value("operation").toString();
|
||||
if (operation == "powerAuto") return {};
|
||||
bool valid;
|
||||
const double value = config.value("value").toDouble(&valid);
|
||||
if (operation == "powerBrightness" && valid && value >= 1 && value <= 100 && std::floor(value) == value)
|
||||
return {};
|
||||
return "Invalid power-button setting: choose Auto or a whole-number brightness from 1 to 100%.";
|
||||
}
|
||||
|
||||
QVariantMap readPowerButtonConfig(QString &error, const QString &path)
|
||||
{
|
||||
error.clear();
|
||||
QFile file(path);
|
||||
if (!file.open(QIODevice::ReadOnly)) { error = file.errorString(); return {}; }
|
||||
QJsonParseError parseError;
|
||||
const auto document = QJsonDocument::fromJson(file.readAll(), &parseError);
|
||||
if (parseError.error != QJsonParseError::NoError || !document.isObject()) {
|
||||
error = "Invalid power-button settings file.";
|
||||
return {};
|
||||
}
|
||||
const auto config = document.toVariant().toMap();
|
||||
error = validatePowerButtonConfig(config);
|
||||
return error.isEmpty() ? config : QVariantMap{};
|
||||
}
|
||||
Reference in new issue
Block a user