mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
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:
@@ -38,7 +38,7 @@ CONFIGURE_FILE(${CURRENT_SOURCE_DIR}/EffectEngine.qrc.in ${CMAKE_BINARY_DIR}/Eff
|
||||
SET(EffectEngine_RESOURCES ${CMAKE_BINARY_DIR}/EffectEngine.qrc)
|
||||
|
||||
QT5_WRAP_CPP(EffectEngineHEADERS_MOC ${EffectEngineQT_HEADERS})
|
||||
qt5_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} OPTIONS "-no-compress")
|
||||
qt5_add_resources(EffectEngine_RESOURCES_RCC ${EffectEngine_RESOURCES} ) # OPTIONS "-no-compress"
|
||||
|
||||
add_library(effectengine
|
||||
${EffectEngineHEADERS}
|
||||
|
@@ -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 );
|
||||
|
@@ -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
|
||||
|
@@ -669,9 +669,9 @@ void JsonClientConnection::handleServerInfoCommand(const Json::Value &, const st
|
||||
ver["version"] = HYPERION_VERSION;
|
||||
ver["build"] = HYPERION_BUILD_ID;
|
||||
ver["time"] = __DATE__ " " __TIME__;
|
||||
ver["config_modified"] = _hyperion->configModified();
|
||||
|
||||
info["hyperion"].append(ver);
|
||||
|
||||
// send the result
|
||||
sendMessage(result);
|
||||
}
|
||||
|
@@ -27,14 +27,23 @@ set(WebConfig_SOURCES
|
||||
${CURRENT_SOURCE_DIR}/StaticFileServing.cpp
|
||||
${CURRENT_SOURCE_DIR}/WebConfig.cpp
|
||||
)
|
||||
FILE ( GLOB_RECURSE webFiles RELATIVE ${CMAKE_BINARY_DIR} ${CMAKE_SOURCE_DIR}/assets/webconfig/* )
|
||||
FOREACH( f ${webFiles} )
|
||||
STRING ( REPLACE "../assets/webconfig/" "" fname ${f})
|
||||
SET(HYPERION_WEBCONFIG_RES "${HYPERION_WEBCONFIG_RES}\n\t\t<file alias=\"/webconfig/${fname}\">${f}</file>")
|
||||
ENDFOREACH()
|
||||
CONFIGURE_FILE(${CURRENT_SOURCE_DIR}/WebConfig.qrc.in ${CMAKE_BINARY_DIR}/WebConfig.qrc )
|
||||
SET(WebConfig_RESOURCES ${CMAKE_BINARY_DIR}/WebConfig.qrc)
|
||||
|
||||
qt5_wrap_cpp(WebConfig_HEADERS_MOC ${WebConfig_QT_HEADERS})
|
||||
qt5_add_resources(WebConfig_RESOURCES_RCC ${WebConfig_RESOURCES} ) #OPTIONS "-no-compress"
|
||||
|
||||
add_library(webconfig
|
||||
${WebConfig_HEADERS}
|
||||
${WebConfig_QT_HEADERS}
|
||||
${WebConfig_SOURCES}
|
||||
${WebConfig_HEADERS_MOC}
|
||||
${WebConfig_RESOURCES_RCC}
|
||||
)
|
||||
|
||||
qt5_use_modules(webconfig Network)
|
||||
|
@@ -7,14 +7,17 @@
|
||||
#include <QPair>
|
||||
#include <QFile>
|
||||
#include <QFileInfo>
|
||||
#include <QResource>
|
||||
|
||||
StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint16 port, QObject * parent)
|
||||
: QObject (parent)
|
||||
, _hyperion(hyperion)
|
||||
, _baseUrl (baseUrl)
|
||||
, _cgi(hyperion, baseUrl, this)
|
||||
, _log(Logger::getInstance("WEBSERVER"))
|
||||
: QObject (parent)
|
||||
, _hyperion(hyperion)
|
||||
, _baseUrl (baseUrl)
|
||||
, _cgi(hyperion, baseUrl, this)
|
||||
, _log(Logger::getInstance("WEBSERVER"))
|
||||
{
|
||||
Q_INIT_RESOURCE(WebConfig);
|
||||
|
||||
_mimeDb = new QMimeDatabase;
|
||||
|
||||
_server = new QtHttpServer (this);
|
||||
@@ -26,6 +29,7 @@ StaticFileServing::StaticFileServing (Hyperion *hyperion, QString baseUrl, quint
|
||||
connect (_server, &QtHttpServer::requestNeedsReply, this, &StaticFileServing::onRequestNeedsReply);
|
||||
|
||||
_server->start (port);
|
||||
|
||||
}
|
||||
|
||||
StaticFileServing::~StaticFileServing ()
|
||||
@@ -75,6 +79,7 @@ void StaticFileServing::onRequestNeedsReply (QtHttpRequest * request, QtHttpRepl
|
||||
}
|
||||
return;
|
||||
}
|
||||
Q_INIT_RESOURCE(WebConfig);
|
||||
|
||||
QFileInfo info(_baseUrl % "/" % path);
|
||||
if ( path == "/" || path.isEmpty() || ! info.exists() )
|
||||
|
@@ -1,17 +1,18 @@
|
||||
#include "webconfig/WebConfig.h"
|
||||
#include "StaticFileServing.h"
|
||||
|
||||
#include <QFileInfo>
|
||||
|
||||
WebConfig::WebConfig(QObject * parent)
|
||||
: QObject(parent)
|
||||
, _hyperion(Hyperion::getInstance())
|
||||
, _port(WEBCONFIG_DEFAULT_PORT)
|
||||
, _server(nullptr)
|
||||
{
|
||||
_port = WEBCONFIG_DEFAULT_PORT;
|
||||
_hyperion = Hyperion::getInstance();
|
||||
_baseUrl = WEBCONFIG_DEFAULT_PATH;
|
||||
const Json::Value &config = _hyperion->getJsonConfig();
|
||||
_baseUrl = QString::fromStdString(WEBCONFIG_DEFAULT_PATH);
|
||||
_port = WEBCONFIG_DEFAULT_PORT;
|
||||
|
||||
Logger* log = Logger::getInstance("WEBSERVER");
|
||||
|
||||
bool webconfigEnable = true;
|
||||
|
||||
if (config.isMember("webConfig"))
|
||||
@@ -19,11 +20,24 @@ WebConfig::WebConfig(QObject * parent)
|
||||
const Json::Value & webconfigConfig = config["webConfig"];
|
||||
webconfigEnable = webconfigConfig.get("enable", true).asBool();
|
||||
_port = webconfigConfig.get("port", WEBCONFIG_DEFAULT_PORT).asUInt();
|
||||
_baseUrl = QString::fromStdString( webconfigConfig.get("document_root", WEBCONFIG_DEFAULT_PATH).asString() );
|
||||
_baseUrl = QString::fromStdString( webconfigConfig.get("document_root", _baseUrl.toStdString()).asString() );
|
||||
}
|
||||
|
||||
if (_baseUrl != ":/webconfig")
|
||||
{
|
||||
QFileInfo info(_baseUrl);
|
||||
if (!info.exists() || !info.isDir())
|
||||
{
|
||||
Error(log, "document_root '%s' is invalid, set to default '%s'", _baseUrl.toUtf8().constData(), WEBCONFIG_DEFAULT_PATH.toUtf8().constData());
|
||||
_baseUrl = WEBCONFIG_DEFAULT_PATH;
|
||||
}
|
||||
}
|
||||
|
||||
Debug(log, "WebUI initialized, document root: %s", _baseUrl.toUtf8().constData());
|
||||
if ( webconfigEnable )
|
||||
{
|
||||
start();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
5
libsrc/webconfig/WebConfig.qrc.in
Normal file
5
libsrc/webconfig/WebConfig.qrc.in
Normal file
@@ -0,0 +1,5 @@
|
||||
<RCC>
|
||||
<qresource prefix="/">
|
||||
${HYPERION_WEBCONFIG_RES}
|
||||
</qresource>
|
||||
</RCC>
|
Reference in New Issue
Block a user