embedded webui + config modification detection (#240)

* implement embedded webui

* add detection for changed config, later on used for restart hyperion
This commit is contained in:
redPanther
2016-09-14 13:51:28 +02:00
committed by GitHub
parent ccc50899fb
commit 1cc2f72fa2
16 changed files with 103 additions and 30 deletions

View File

@@ -10,6 +10,8 @@
#include <QRegExp>
#include <QString>
#include <QStringList>
#include <QCryptographicHash>
#include <QFile>
// JsonSchema include
#include <utils/jsonschema/JsonFactory.h>
@@ -575,6 +577,7 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
, _log(Logger::getInstance("Core"))
, _hwLedCount(_ledString.leds().size())
, _sourceAutoSelectEnabled(true)
, _configHash()
{
registerPriority("Off", PriorityMuxer::LOWEST_PRIORITY);
@@ -623,6 +626,9 @@ Hyperion::Hyperion(const Json::Value &jsonConfig, const std::string configFile)
Debug(_log,"configured leds: %d hw leds: %d", getLedCount(), _hwLedCount);
WarningIf(hwLedCount < getLedCount(), _log, "more leds configured than available. check 'ledCount' in 'device' section");
// initialize hash of current config
configModified();
// initialize the leds
update();
}
@@ -648,6 +654,29 @@ unsigned Hyperion::getLedCount() const
return _ledString.leds().size();
}
bool Hyperion::configModified()
{
QFile f(_configFile.c_str());
if (f.open(QFile::ReadOnly))
{
QCryptographicHash hash(QCryptographicHash::Sha1);
if (hash.addData(&f))
{
if (_configHash.size() == 0)
{
_configHash = hash.result();
qDebug(_configHash.toHex());
return false;
}
return _configHash != hash.result();
}
}
f.close();
return false;
}
void Hyperion::registerPriority(const std::string name, const int priority)
{
Info(_log, "Register new input source named '%s' for priority channel '%d'", name.c_str(), priority );

View File

@@ -1000,7 +1000,6 @@
{
"type" : "object",
"title" : "WebUI - DANGER CHANGES CAN MAKE THE WEBUI UNREACHABLE!",
"required" : true,
"properties" :
{
"enable" :
@@ -1009,21 +1008,18 @@
"format": "checkbox",
"title" : "Activate",
"default" : true,
"required" : true,
"propertyOrder" : 1
},
"document_root" :
{
"type" : "string",
"title" : "Document Root",
"required" : true
"title" : "Document Root"
},
"port" :
{
"type" : "integer",
"title" : "Port",
"default" : 8099,
"required" : true
"default" : 8099
}
},
"additionalProperties" : false