mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Custom Effects - Clean-ups and Enhancements (#1163)
* Cleanup EffectFileHandler * Support Custom Effect Schemas and align EffectFileHandler * Change back to colon prefix for system effects * WebSockets - Fix error in handling fragmented frames * Correct missing colon updates * Update json with image file location for custom gif effects * Image effect deletion - considere full filename is stored in JSON * Correct selection lists indentions
This commit is contained in:
parent
9475b93d9f
commit
90d05e6c54
@ -821,7 +821,9 @@
|
|||||||
"remote_maptype_label": "Mapping type",
|
"remote_maptype_label": "Mapping type",
|
||||||
"remote_maptype_label_multicolor_mean": "Multicolor",
|
"remote_maptype_label_multicolor_mean": "Multicolor",
|
||||||
"remote_maptype_label_unicolor_mean": "Unicolor",
|
"remote_maptype_label_unicolor_mean": "Unicolor",
|
||||||
"remote_optgroup_syseffets": "Provided Effects",
|
"remote_optgroup_syseffets": "System Effects",
|
||||||
|
"remote_optgroup_templates_custom": "User Templates",
|
||||||
|
"remote_optgroup_templates_system": "System Templates",
|
||||||
"remote_optgroup_usreffets": "User Effects",
|
"remote_optgroup_usreffets": "User Effects",
|
||||||
"remote_videoMode_2D": "2D",
|
"remote_videoMode_2D": "2D",
|
||||||
"remote_videoMode_3DSBS": "3DSBS",
|
"remote_videoMode_3DSBS": "3DSBS",
|
||||||
|
@ -4,7 +4,7 @@ $(document).ready( function() {
|
|||||||
var effectName = "";
|
var effectName = "";
|
||||||
var imageData = "";
|
var imageData = "";
|
||||||
var effects_editor = null;
|
var effects_editor = null;
|
||||||
var effectPy = "";
|
var effectPyScript = "";
|
||||||
var testrun;
|
var testrun;
|
||||||
|
|
||||||
if (window.showOptHelp)
|
if (window.showOptHelp)
|
||||||
@ -12,27 +12,46 @@ $(document).ready( function() {
|
|||||||
|
|
||||||
function updateDelEffectlist() {
|
function updateDelEffectlist() {
|
||||||
var newDelList = window.serverInfo.effects;
|
var newDelList = window.serverInfo.effects;
|
||||||
if(newDelList.length != oldDelList.length)
|
if (newDelList.length != oldDelList.length) {
|
||||||
{
|
|
||||||
$('#effectsdellist').html("");
|
$('#effectsdellist').html("");
|
||||||
var usrEffArr = [];
|
var usrEffArr = [];
|
||||||
var sysEffArr = [];
|
var sysEffArr = [];
|
||||||
for(var idx=0; idx<newDelList.length; idx++)
|
for (var idx = 0; idx < newDelList.length; idx++) {
|
||||||
{
|
if (newDelList[idx].file.startsWith(":")) {
|
||||||
if(!/^\:/.test(newDelList[idx].file))
|
sysEffArr.push(idx);
|
||||||
usrEffArr.push('ext_'+newDelList[idx].name+':'+newDelList[idx].name);
|
|
||||||
else
|
|
||||||
sysEffArr.push('int_'+newDelList[idx].name+':'+newDelList[idx].name);
|
|
||||||
}
|
}
|
||||||
$('#effectsdellist').append(createSel(usrEffArr, $.i18n('remote_optgroup_usreffets'), true)).append(createSel(sysEffArr, $.i18n('remote_optgroup_syseffets'), true)).trigger('change');
|
else {
|
||||||
|
usrEffArr.push(idx);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (usrEffArr.length > 0) {
|
||||||
|
var usrEffGrp = createSelGroup($.i18n('remote_optgroup_usreffets'));
|
||||||
|
for (var idx = 0; idx < usrEffArr.length; idx++)
|
||||||
|
{
|
||||||
|
usrEffGrp.appendChild(createSelOpt('ext_' + newDelList[usrEffArr[idx]].name, newDelList[usrEffArr[idx]].name));
|
||||||
|
}
|
||||||
|
$('#effectsdellist').append(usrEffGrp);
|
||||||
|
}
|
||||||
|
|
||||||
|
var sysEffGrp = createSelGroup($.i18n('remote_optgroup_syseffets'));
|
||||||
|
for (var idx = 0; idx < sysEffArr.length; idx++)
|
||||||
|
{
|
||||||
|
sysEffGrp.appendChild(createSelOpt('int_' + newDelList[sysEffArr[idx]].name, newDelList[sysEffArr[idx]].name));
|
||||||
|
}
|
||||||
|
$('#effectsdellist').append(sysEffGrp);
|
||||||
|
|
||||||
|
$("#effectsdellist").trigger("change");
|
||||||
|
|
||||||
oldDelList = newDelList;
|
oldDelList = newDelList;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function triggerTestEffect() {
|
function triggerTestEffect() {
|
||||||
testrun = true;
|
testrun = true;
|
||||||
|
|
||||||
var args = effects_editor.getEditor('root.args');
|
var args = effects_editor.getEditor('root.args');
|
||||||
requestTestEffect(effectName, ":/effects/" + effectPy.slice(1), JSON.stringify(args.getValue()), imageData);
|
requestTestEffect(effectName, effectPyScript, JSON.stringify(args.getValue()), imageData);
|
||||||
};
|
};
|
||||||
|
|
||||||
// Specify upload handler for image files
|
// Specify upload handler for image files
|
||||||
@ -61,33 +80,35 @@ $(document).ready( function() {
|
|||||||
effects_editor.destroy();
|
effects_editor.destroy();
|
||||||
|
|
||||||
for (var idx = 0; idx < effects.length; idx++) {
|
for (var idx = 0; idx < effects.length; idx++) {
|
||||||
if (effects[idx].schemaContent.script == this.value)
|
if (effects[idx].script == this.value) {
|
||||||
{
|
|
||||||
effects_editor = createJsonEditor('editor_container', {
|
effects_editor = createJsonEditor('editor_container', {
|
||||||
args: effects[idx].schemaContent,
|
args: effects[idx].schemaContent,
|
||||||
}, false, true, false);
|
}, false, true, false);
|
||||||
|
|
||||||
effectPy = ':';
|
effectPyScript = effects[idx].script;
|
||||||
effectPy += effects[idx].schemaContent.script;
|
|
||||||
imageData = "";
|
imageData = "";
|
||||||
$("#name-input").trigger("change");
|
$("#name-input").trigger("change");
|
||||||
|
|
||||||
$("#eff_desc").html(createEffHint($.i18n(effects[idx].schemaContent.title),$.i18n(effects[idx].schemaContent.title+'_desc')));
|
var desc = $.i18n(effects[idx].schemaContent.title + '_desc');
|
||||||
|
if (desc === effects[idx].schemaContent.title + '_desc') {
|
||||||
|
desc = ""
|
||||||
|
}
|
||||||
|
|
||||||
|
$("#eff_desc").html(createEffHint($.i18n(effects[idx].schemaContent.title), desc));
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
effects_editor.on('change', function () {
|
effects_editor.on('change', function () {
|
||||||
if ($("#btn_cont_test").hasClass("btn-success") && effects_editor.validate().length == 0 && effectName != "")
|
if ($("#btn_cont_test").hasClass("btn-success") && effects_editor.validate().length == 0 && effectName != "") {
|
||||||
{
|
|
||||||
triggerTestEffect();
|
triggerTestEffect();
|
||||||
}
|
}
|
||||||
if( effects_editor.validate().length == 0 && effectName != "")
|
if (effects_editor.validate().length == 0 && effectName != "") {
|
||||||
{
|
|
||||||
$('#btn_start_test').attr('disabled', false);
|
$('#btn_start_test').attr('disabled', false);
|
||||||
!window.readOnlyMode ? $('#btn_write').attr('disabled', false) : $('#btn_write').attr('disabled', true);
|
!window.readOnlyMode ? $('#btn_write').attr('disabled', false) : $('#btn_write').attr('disabled', true);
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
$('#btn_start_test, #btn_write').attr('disabled', true);
|
$('#btn_start_test, #btn_write').attr('disabled', true);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
@ -108,7 +129,7 @@ $(document).ready( function() {
|
|||||||
|
|
||||||
// Save Effect
|
// Save Effect
|
||||||
$('#btn_write').off().on('click', function () {
|
$('#btn_write').off().on('click', function () {
|
||||||
requestWriteEffect(effectName,effectPy,JSON.stringify(effects_editor.getValue()),imageData);
|
requestWriteEffect(effectName, effectPyScript, JSON.stringify(effects_editor.getValue()), imageData);
|
||||||
$(window.hyperion).one("cmd-create-effect", function (event) {
|
$(window.hyperion).one("cmd-create-effect", function (event) {
|
||||||
if (event.response.success)
|
if (event.response.success)
|
||||||
showInfoDialog('success', "", $.i18n('infoDialog_effconf_created_text', effectName));
|
showInfoDialog('success', "", $.i18n('infoDialog_effconf_created_text', effectName));
|
||||||
@ -116,7 +137,6 @@ $(document).ready( function() {
|
|||||||
|
|
||||||
if (testrun)
|
if (testrun)
|
||||||
setTimeout(requestPriorityClear, 100);
|
setTimeout(requestPriorityClear, 100);
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
// Start test
|
// Start test
|
||||||
@ -145,7 +165,7 @@ $(document).ready( function() {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
// disable or enable Delete Effect Button
|
// Disable or enable Delete Effect Button
|
||||||
$('#effectsdellist').off().on('change', function () {
|
$('#effectsdellist').off().on('change', function () {
|
||||||
$(this).val() == null ? $('#btn_edit, #btn_delete').prop('disabled', true) : "";
|
$(this).val() == null ? $('#btn_edit, #btn_delete').prop('disabled', true) : "";
|
||||||
$(this).val().startsWith("int_") ? $('#btn_delete').prop('disabled', true) : $('#btn_delete').prop('disabled', false);
|
$(this).val().startsWith("int_") ? $('#btn_delete').prop('disabled', true) : $('#btn_delete').prop('disabled', false);
|
||||||
@ -153,28 +173,24 @@ $(document).ready( function() {
|
|||||||
|
|
||||||
// Load Effect
|
// Load Effect
|
||||||
$('#btn_edit').off().on('click', function () {
|
$('#btn_edit').off().on('click', function () {
|
||||||
var name = $("#effectsdellist").val().replace("ext_","");
|
|
||||||
|
|
||||||
if(name.startsWith("int_"))
|
var name = $("#effectsdellist").val().replace("ext_", "");
|
||||||
{ name = name.split("_").pop();
|
if (name.startsWith("int_")) {
|
||||||
|
name = name.split("_").pop();
|
||||||
$("#name-input").val("My Modded Effect");
|
$("#name-input").val("My Modded Effect");
|
||||||
}
|
}
|
||||||
else
|
else {
|
||||||
{
|
|
||||||
name = name.split("_").pop();
|
name = name.split("_").pop();
|
||||||
$("#name-input").val(name);
|
$("#name-input").val(name);
|
||||||
}
|
}
|
||||||
|
|
||||||
var efx = window.serverInfo.effects;
|
var efx = window.serverInfo.effects;
|
||||||
for(var i = 0; i<efx.length; i++)
|
for (var i = 0; i < efx.length; i++) {
|
||||||
{
|
if (efx[i].name == name) {
|
||||||
if(efx[i].name == name)
|
var py = efx[i].script;
|
||||||
{
|
|
||||||
var py = efx[i].script.split("/").pop();
|
|
||||||
$("#effectslist").val(py).trigger("change");
|
$("#effectslist").val(py).trigger("change");
|
||||||
|
|
||||||
for(var key in efx[i].args)
|
for (var key in efx[i].args) {
|
||||||
{
|
|
||||||
var ed = effects_editor.getEditor('root.args.' + [key]);
|
var ed = effects_editor.getEditor('root.args.' + [key]);
|
||||||
if (ed)
|
if (ed)
|
||||||
ed.setValue(efx[i].args[key]);
|
ed.setValue(efx[i].args[key]);
|
||||||
@ -184,12 +200,37 @@ $(document).ready( function() {
|
|||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
//create basic effect list
|
//Create effect template list
|
||||||
var effects = window.serverSchema.properties.effectSchemas.internal;
|
var effects = window.serverSchema.properties.effectSchemas;
|
||||||
for(var idx=0; idx<effects.length; idx++)
|
|
||||||
{
|
$('#effectslist').html("");
|
||||||
$("#effectslist").append(createSelOpt(effects[idx].schemaContent.script, $.i18n(effects[idx].schemaContent.title)));
|
var custTemplatesIDs = [];
|
||||||
|
var sysTemplatesIDs = [];
|
||||||
|
|
||||||
|
for (var idx = 0; idx < effects.length; idx++) {
|
||||||
|
if (effects[idx].type === "custom")
|
||||||
|
custTemplatesIDs.push(idx);
|
||||||
|
else
|
||||||
|
sysTemplatesIDs.push(idx);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Cannot use createSel(), as Windows filenames include colons ":"
|
||||||
|
if (custTemplatesIDs.length > 0) {
|
||||||
|
var custTmplGrp = createSelGroup($.i18n('remote_optgroup_templates_custom'));
|
||||||
|
for (var idx = 0; idx < custTemplatesIDs.length; idx++)
|
||||||
|
{
|
||||||
|
custTmplGrp.appendChild(createSelOpt(effects[custTemplatesIDs[idx]].script, $.i18n(effects[custTemplatesIDs[idx]].schemaContent.title)));
|
||||||
|
}
|
||||||
|
$('#effectslist').append(custTmplGrp);
|
||||||
|
}
|
||||||
|
|
||||||
|
var sysTmplGrp = createSelGroup($.i18n('remote_optgroup_templates_system'));
|
||||||
|
for (var idx = 0; idx < sysTemplatesIDs.length; idx++)
|
||||||
|
{
|
||||||
|
sysTmplGrp.appendChild(createSelOpt(effects[sysTemplatesIDs[idx]].script, $.i18n(effects[sysTemplatesIDs[idx]].schemaContent.title)));
|
||||||
|
}
|
||||||
|
$('#effectslist').append(sysTmplGrp);
|
||||||
|
|
||||||
$("#effectslist").trigger("change");
|
$("#effectslist").trigger("change");
|
||||||
|
|
||||||
updateDelEffectlist();
|
updateDelEffectlist();
|
||||||
@ -202,3 +243,4 @@ $(document).ready( function() {
|
|||||||
|
|
||||||
removeOverlay();
|
removeOverlay();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
@ -923,36 +923,25 @@ void JsonAPI::handleSchemaGetCommand(const QJsonObject &message, const QString &
|
|||||||
properties.insert("alldevices", alldevices);
|
properties.insert("alldevices", alldevices);
|
||||||
|
|
||||||
// collect all available effect schemas
|
// collect all available effect schemas
|
||||||
QJsonObject pyEffectSchemas, pyEffectSchema;
|
QJsonArray schemaList;
|
||||||
QJsonArray in, ex;
|
|
||||||
const std::list<EffectSchema>& effectsSchemas = _hyperion->getEffectSchemas();
|
const std::list<EffectSchema>& effectsSchemas = _hyperion->getEffectSchemas();
|
||||||
for (const EffectSchema& effectSchema : effectsSchemas)
|
for (const EffectSchema& effectSchema : effectsSchemas)
|
||||||
{
|
{
|
||||||
if (effectSchema.pyFile.mid(0, 1) == ":")
|
QJsonObject schema;
|
||||||
|
schema.insert("script", effectSchema.pyFile);
|
||||||
|
schema.insert("schemaLocation", effectSchema.schemaFile);
|
||||||
|
schema.insert("schemaContent", effectSchema.pySchema);
|
||||||
|
if (effectSchema.pyFile.startsWith(':'))
|
||||||
{
|
{
|
||||||
QJsonObject internal;
|
schema.insert("type", "system");
|
||||||
internal.insert("script", effectSchema.pyFile);
|
|
||||||
internal.insert("schemaLocation", effectSchema.schemaFile);
|
|
||||||
internal.insert("schemaContent", effectSchema.pySchema);
|
|
||||||
in.append(internal);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
QJsonObject external;
|
schema.insert("type", "custom");
|
||||||
external.insert("script", effectSchema.pyFile);
|
|
||||||
external.insert("schemaLocation", effectSchema.schemaFile);
|
|
||||||
external.insert("schemaContent", effectSchema.pySchema);
|
|
||||||
ex.append(external);
|
|
||||||
}
|
}
|
||||||
|
schemaList.append(schema);
|
||||||
}
|
}
|
||||||
|
properties.insert("effectSchemas", schemaList);
|
||||||
if (!in.empty())
|
|
||||||
pyEffectSchema.insert("internal", in);
|
|
||||||
if (!ex.empty())
|
|
||||||
pyEffectSchema.insert("external", ex);
|
|
||||||
|
|
||||||
pyEffectSchemas = pyEffectSchema;
|
|
||||||
properties.insert("effectSchemas", pyEffectSchemas);
|
|
||||||
|
|
||||||
schemaJson.insert("properties", properties);
|
schemaJson.insert("properties", properties);
|
||||||
|
|
||||||
|
@ -14,7 +14,7 @@
|
|||||||
struct find_schema : std::unary_function<EffectSchema, bool>
|
struct find_schema : std::unary_function<EffectSchema, bool>
|
||||||
{
|
{
|
||||||
QString pyFile;
|
QString pyFile;
|
||||||
find_schema(QString pyFile):pyFile(pyFile) { }
|
find_schema(QString pyFile) :pyFile(std::move(pyFile)) { }
|
||||||
bool operator()(EffectSchema const& schema) const
|
bool operator()(EffectSchema const& schema) const
|
||||||
{
|
{
|
||||||
return schema.pyFile == pyFile;
|
return schema.pyFile == pyFile;
|
||||||
@ -25,7 +25,7 @@ struct find_schema: std::unary_function<EffectSchema, bool>
|
|||||||
struct find_effect : std::unary_function<EffectDefinition, bool>
|
struct find_effect : std::unary_function<EffectDefinition, bool>
|
||||||
{
|
{
|
||||||
QString effectName;
|
QString effectName;
|
||||||
find_effect(QString effectName) :effectName(effectName) { }
|
find_effect(QString effectName) :effectName(std::move(effectName)) { }
|
||||||
bool operator()(EffectDefinition const& effectDefinition) const
|
bool operator()(EffectDefinition const& effectDefinition) const
|
||||||
{
|
{
|
||||||
return effectDefinition.name == effectName;
|
return effectDefinition.name == effectName;
|
||||||
@ -36,7 +36,6 @@ EffectFileHandler* EffectFileHandler::efhInstance;
|
|||||||
|
|
||||||
EffectFileHandler::EffectFileHandler(const QString& rootPath, const QJsonDocument& effectConfig, QObject* parent)
|
EffectFileHandler::EffectFileHandler(const QString& rootPath, const QJsonDocument& effectConfig, QObject* parent)
|
||||||
: QObject(parent)
|
: QObject(parent)
|
||||||
, _effectConfig()
|
|
||||||
, _log(Logger::getInstance("EFFECTFILES"))
|
, _log(Logger::getInstance("EFFECTFILES"))
|
||||||
, _rootPath(rootPath)
|
, _rootPath(rootPath)
|
||||||
{
|
{
|
||||||
@ -67,31 +66,45 @@ QString EffectFileHandler::deleteEffect(const QString& effectName)
|
|||||||
if (it != effectsDefinition.end())
|
if (it != effectsDefinition.end())
|
||||||
{
|
{
|
||||||
QFileInfo effectConfigurationFile(it->file);
|
QFileInfo effectConfigurationFile(it->file);
|
||||||
if (effectConfigurationFile.absoluteFilePath().mid(0, 1) != ":" )
|
if (!effectConfigurationFile.absoluteFilePath().startsWith(':'))
|
||||||
{
|
{
|
||||||
if (effectConfigurationFile.exists())
|
if (effectConfigurationFile.exists())
|
||||||
{
|
{
|
||||||
if ((it->script == ":/effects/gif.py") && !it->args.value("image").toString("").isEmpty())
|
if ((it->script == ":/effects/gif.py") && !it->args.value("image").toString("").isEmpty())
|
||||||
{
|
{
|
||||||
QFileInfo effectImageFile(effectConfigurationFile.absolutePath() + "/" + it->args.value("image").toString());
|
QFileInfo effectImageFile(it->args.value("image").toString());
|
||||||
if (effectImageFile.exists())
|
if (effectImageFile.exists())
|
||||||
|
{
|
||||||
QFile::remove(effectImageFile.absoluteFilePath());
|
QFile::remove(effectImageFile.absoluteFilePath());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
bool result = QFile::remove(effectConfigurationFile.absoluteFilePath());
|
bool result = QFile::remove(effectConfigurationFile.absoluteFilePath());
|
||||||
|
|
||||||
if (result)
|
if (result)
|
||||||
{
|
{
|
||||||
updateEffects();
|
updateEffects();
|
||||||
return "";
|
resultMsg = "";
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resultMsg = "Can't delete effect configuration file: " + effectConfigurationFile.absoluteFilePath() + ". Please check permissions";
|
resultMsg = "Can't delete effect configuration file: " + effectConfigurationFile.absoluteFilePath() + ". Please check permissions";
|
||||||
} else
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resultMsg = "Can't find effect configuration file: " + effectConfigurationFile.absoluteFilePath();
|
resultMsg = "Can't find effect configuration file: " + effectConfigurationFile.absoluteFilePath();
|
||||||
} else
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resultMsg = "Can't delete internal effect: " + effectName;
|
resultMsg = "Can't delete internal effect: " + effectName;
|
||||||
} else
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resultMsg = "Effect " + effectName + " not found";
|
resultMsg = "Effect " + effectName + " not found";
|
||||||
|
}
|
||||||
|
|
||||||
return resultMsg;
|
return resultMsg;
|
||||||
}
|
}
|
||||||
@ -101,10 +114,7 @@ QString EffectFileHandler::saveEffect(const QJsonObject& message)
|
|||||||
QString resultMsg;
|
QString resultMsg;
|
||||||
if (!message["args"].toObject().isEmpty())
|
if (!message["args"].toObject().isEmpty())
|
||||||
{
|
{
|
||||||
QString scriptName;
|
QString scriptName = message["script"].toString();
|
||||||
(message["script"].toString().mid(0, 1) == ":" )
|
|
||||||
? scriptName = ":/effects//" + message["script"].toString().mid(1)
|
|
||||||
: scriptName = message["script"].toString();
|
|
||||||
|
|
||||||
std::list<EffectSchema> effectsSchemas = getEffectSchemas();
|
std::list<EffectSchema> effectsSchemas = getEffectSchemas();
|
||||||
std::list<EffectSchema>::iterator it = std::find_if(effectsSchemas.begin(), effectsSchemas.end(), find_schema(scriptName));
|
std::list<EffectSchema>::iterator it = std::find_if(effectsSchemas.begin(), effectsSchemas.end(), find_schema(scriptName));
|
||||||
@ -120,9 +130,9 @@ QString EffectFileHandler::saveEffect(const QJsonObject& message)
|
|||||||
QJsonArray effectArray;
|
QJsonArray effectArray;
|
||||||
effectArray = _effectConfig["paths"].toArray();
|
effectArray = _effectConfig["paths"].toArray();
|
||||||
|
|
||||||
if (effectArray.size() > 0)
|
if (!effectArray.empty())
|
||||||
{
|
{
|
||||||
if (message["name"].toString().trimmed().isEmpty() || message["name"].toString().trimmed().startsWith("."))
|
if (message["name"].toString().trimmed().isEmpty() || message["name"].toString().trimmed().startsWith(":"))
|
||||||
{
|
{
|
||||||
return "Can't save new effect. Effect name is empty or begins with a dot.";
|
return "Can't save new effect. Effect name is empty or begins with a dot.";
|
||||||
}
|
}
|
||||||
@ -138,25 +148,31 @@ QString EffectFileHandler::saveEffect(const QJsonObject& message)
|
|||||||
if (iter != availableEffects.end())
|
if (iter != availableEffects.end())
|
||||||
{
|
{
|
||||||
newFileName.setFile(iter->file);
|
newFileName.setFile(iter->file);
|
||||||
if (newFileName.absoluteFilePath().mid(0, 1) == ":")
|
if (newFileName.absoluteFilePath().startsWith(':'))
|
||||||
{
|
{
|
||||||
return "The effect name '" + message["name"].toString() + "' is assigned to an internal effect. Please rename your effekt.";
|
return "The effect name '" + message["name"].toString() + "' is assigned to an internal effect. Please rename your effect.";
|
||||||
}
|
}
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
{
|
{
|
||||||
// TODO global special keyword handling
|
QString f = effectArray[0].toString().replace("$ROOT", _rootPath) + '/' + message["name"].toString().replace(QString(" "), QString("")) + QString(".json");
|
||||||
QString f = effectArray[0].toString().replace("$ROOT",_rootPath) + "/" + message["name"].toString().replace(QString(" "), QString("")) + QString(".json");
|
|
||||||
newFileName.setFile(f);
|
newFileName.setFile(f);
|
||||||
}
|
}
|
||||||
|
|
||||||
//TODO check if filename exist
|
|
||||||
if (!message["imageData"].toString("").isEmpty() && !message["args"].toObject().value("image").toString("").isEmpty())
|
if (!message["imageData"].toString("").isEmpty() && !message["args"].toObject().value("image").toString("").isEmpty())
|
||||||
{
|
{
|
||||||
QFileInfo imageFileName(effectArray[0].toString().replace("$ROOT",_rootPath) + "/" + message["args"].toObject().value("image").toString());
|
QJsonObject args = message["args"].toObject();
|
||||||
|
QString imageFilePath = effectArray[0].toString().replace("$ROOT", _rootPath) + '/' + args.value("image").toString();
|
||||||
|
|
||||||
|
QFileInfo imageFileName(imageFilePath);
|
||||||
if (!FileUtils::writeFile(imageFileName.absoluteFilePath(), QByteArray::fromBase64(message["imageData"].toString("").toUtf8()), _log))
|
if (!FileUtils::writeFile(imageFileName.absoluteFilePath(), QByteArray::fromBase64(message["imageData"].toString("").toUtf8()), _log))
|
||||||
{
|
{
|
||||||
return "Error while saving image file '" + message["args"].toObject().value("image").toString() + ", please check the Hyperion Log";
|
return "Error while saving image file '" + message["args"].toObject().value("image").toString() + ", please check the Hyperion Log";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//Update json with image file location
|
||||||
|
args["image"] = imageFilePath;
|
||||||
|
effectJson["args"] = args;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!JsonUtils::write(newFileName.absoluteFilePath(), effectJson, _log))
|
if (!JsonUtils::write(newFileName.absoluteFilePath(), effectJson, _log))
|
||||||
@ -166,13 +182,22 @@ QString EffectFileHandler::saveEffect(const QJsonObject& message)
|
|||||||
|
|
||||||
Info(_log, "Reload effect list");
|
Info(_log, "Reload effect list");
|
||||||
updateEffects();
|
updateEffects();
|
||||||
return "";
|
resultMsg = "";
|
||||||
} else
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resultMsg = "Can't save new effect. Effect path empty";
|
resultMsg = "Can't save new effect. Effect path empty";
|
||||||
} else
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resultMsg = "Missing schema file for Python script " + message["script"].toString();
|
resultMsg = "Missing schema file for Python script " + message["script"].toString();
|
||||||
} else
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
resultMsg = "Missing or empty Object 'args'";
|
resultMsg = "Missing or empty Object 'args'";
|
||||||
|
}
|
||||||
|
|
||||||
return resultMsg;
|
return resultMsg;
|
||||||
}
|
}
|
||||||
@ -191,17 +216,23 @@ void EffectFileHandler::updateEffects()
|
|||||||
efxPathList << ":/effects/";
|
efxPathList << ":/effects/";
|
||||||
QStringList disableList;
|
QStringList disableList;
|
||||||
|
|
||||||
for(auto p : paths)
|
for (const auto& p : paths)
|
||||||
{
|
{
|
||||||
efxPathList << p.toString().replace("$ROOT",_rootPath);
|
QString effectPath = p.toString();
|
||||||
|
if (!effectPath.endsWith('/'))
|
||||||
|
{
|
||||||
|
effectPath.append('/');
|
||||||
}
|
}
|
||||||
for(auto efx : disabledEfx)
|
efxPathList << effectPath.replace("$ROOT", _rootPath);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (const auto& efx : disabledEfx)
|
||||||
{
|
{
|
||||||
disableList << efx.toString();
|
disableList << efx.toString();
|
||||||
}
|
}
|
||||||
|
|
||||||
QMap<QString, EffectDefinition> availableEffects;
|
QMap<QString, EffectDefinition> availableEffects;
|
||||||
for (const QString & path : efxPathList )
|
for (const QString& path : qAsConst(efxPathList))
|
||||||
{
|
{
|
||||||
QDir directory(path);
|
QDir directory(path);
|
||||||
if (!directory.exists())
|
if (!directory.exists())
|
||||||
@ -219,7 +250,7 @@ void EffectFileHandler::updateEffects()
|
|||||||
{
|
{
|
||||||
int efxCount = 0;
|
int efxCount = 0;
|
||||||
QStringList filenames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase);
|
QStringList filenames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase);
|
||||||
for (const QString & filename : filenames)
|
for (const QString& filename : qAsConst(filenames))
|
||||||
{
|
{
|
||||||
EffectDefinition def;
|
EffectDefinition def;
|
||||||
if (loadEffectDefinition(path, filename, def))
|
if (loadEffectDefinition(path, filename, def))
|
||||||
@ -242,64 +273,65 @@ void EffectFileHandler::updateEffects()
|
|||||||
|
|
||||||
// collect effect schemas
|
// collect effect schemas
|
||||||
efxCount = 0;
|
efxCount = 0;
|
||||||
directory.setPath(path.endsWith("/") ? (path + "schema/") : (path + "/schema/"));
|
|
||||||
QStringList pynames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase);
|
QString schemaPath = path + "schema" + '/';
|
||||||
for (const QString & pyname : pynames)
|
directory.setPath(schemaPath);
|
||||||
|
QStringList schemaFileNames = directory.entryList(QStringList() << "*.json", QDir::Files, QDir::Name | QDir::IgnoreCase);
|
||||||
|
for (const QString& schemaFileName : qAsConst(schemaFileNames))
|
||||||
{
|
{
|
||||||
EffectSchema pyEffect;
|
EffectSchema pyEffect;
|
||||||
if (loadEffectSchema(path, pyname, pyEffect))
|
if (loadEffectSchema(path, directory.filePath(schemaFileName), pyEffect))
|
||||||
{
|
{
|
||||||
_effectSchemas.push_back(pyEffect);
|
_effectSchemas.push_back(pyEffect);
|
||||||
efxCount++;
|
efxCount++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
InfoIf(efxCount > 0, _log, "%d effect schemas loaded from directory %s", efxCount, QSTRING_CSTR((path + "schema/")));
|
InfoIf(efxCount > 0, _log, "%d effect schemas loaded from directory %s", efxCount, QSTRING_CSTR(schemaPath));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
for(auto item : availableEffects)
|
for (const auto& item : qAsConst(availableEffects))
|
||||||
{
|
{
|
||||||
_availableEffects.push_back(item);
|
_availableEffects.push_back(item);
|
||||||
}
|
}
|
||||||
|
|
||||||
ErrorIf(_availableEffects.size()==0, _log, "no effects found, check your effect directories");
|
ErrorIf(_availableEffects.empty(), _log, "no effects found, check your effect directories");
|
||||||
|
|
||||||
emit effectListChanged();
|
emit effectListChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EffectFileHandler::loadEffectDefinition(const QString& path, const QString& effectConfigFile, EffectDefinition& effectDefinition)
|
bool EffectFileHandler::loadEffectDefinition(const QString& path, const QString& effectConfigFile, EffectDefinition& effectDefinition)
|
||||||
{
|
{
|
||||||
QString fileName = path + QDir::separator() + effectConfigFile;
|
QString fileName = path + effectConfigFile;
|
||||||
|
|
||||||
// Read and parse the effect json config file
|
// Read and parse the effect json config file
|
||||||
QJsonObject configEffect;
|
QJsonObject configEffect;
|
||||||
if(!JsonUtils::readFile(fileName, configEffect, _log))
|
if (!JsonUtils::readFile(fileName, configEffect, _log)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// validate effect config with effect schema(path)
|
// validate effect config with effect schema(path)
|
||||||
if(!JsonUtils::validate(fileName, configEffect, ":effect-schema", _log))
|
if (!JsonUtils::validate(fileName, configEffect, ":effect-schema", _log)) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// setup the definition
|
// setup the definition
|
||||||
effectDefinition.file = fileName;
|
effectDefinition.file = fileName;
|
||||||
QJsonObject config = configEffect;
|
QJsonObject config = configEffect;
|
||||||
QString scriptName = config["script"].toString();
|
QString scriptName = config["script"].toString();
|
||||||
effectDefinition.name = config["name"].toString();
|
effectDefinition.name = config["name"].toString();
|
||||||
if (scriptName.isEmpty())
|
if (scriptName.isEmpty()) {
|
||||||
return false;
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
QFile fileInfo(scriptName);
|
QFile fileInfo(scriptName);
|
||||||
|
if (!fileInfo.exists())
|
||||||
if (scriptName.mid(0, 1) == ":" )
|
|
||||||
{
|
{
|
||||||
(!fileInfo.exists())
|
effectDefinition.script = path + scriptName;
|
||||||
? effectDefinition.script = ":/effects/"+scriptName.mid(1)
|
}
|
||||||
: effectDefinition.script = scriptName;
|
else
|
||||||
} else
|
|
||||||
{
|
{
|
||||||
(!fileInfo.exists())
|
effectDefinition.script = scriptName;
|
||||||
? effectDefinition.script = path + QDir::separator() + scriptName
|
|
||||||
: effectDefinition.script = scriptName;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
effectDefinition.args = config["args"].toObject();
|
effectDefinition.args = config["args"].toObject();
|
||||||
@ -307,31 +339,31 @@ bool EffectFileHandler::loadEffectDefinition(const QString &path, const QString
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool EffectFileHandler::loadEffectSchema(const QString &path, const QString &effectSchemaFile, EffectSchema & effectSchema)
|
bool EffectFileHandler::loadEffectSchema(const QString& path, const QString& schemaFilePath, EffectSchema& effectSchema)
|
||||||
{
|
{
|
||||||
QString fileName = path + "schema/" + QDir::separator() + effectSchemaFile;
|
|
||||||
|
|
||||||
// Read and parse the effect schema file
|
// Read and parse the effect schema file
|
||||||
QJsonObject schemaEffect;
|
QJsonObject schemaEffect;
|
||||||
if(!JsonUtils::readFile(fileName, schemaEffect, _log))
|
if (!JsonUtils::readFile(schemaFilePath, schemaEffect, _log))
|
||||||
return false;
|
|
||||||
|
|
||||||
// setup the definition
|
|
||||||
QString scriptName = schemaEffect["script"].toString();
|
|
||||||
effectSchema.schemaFile = fileName;
|
|
||||||
fileName = path + QDir::separator() + scriptName;
|
|
||||||
QFile pyFile(fileName);
|
|
||||||
|
|
||||||
if (scriptName.isEmpty() || !pyFile.open(QIODevice::ReadOnly))
|
|
||||||
{
|
{
|
||||||
fileName = path + "schema/" + QDir::separator() + effectSchemaFile;
|
|
||||||
Error( _log, "Python script '%s' in effect schema '%s' could not be loaded", QSTRING_CSTR(scriptName), QSTRING_CSTR(fileName));
|
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
pyFile.close();
|
// setup the definition
|
||||||
|
QString scriptName = schemaEffect["script"].toString();
|
||||||
|
effectSchema.schemaFile = schemaFilePath;
|
||||||
|
|
||||||
effectSchema.pyFile = (scriptName.mid(0, 1) == ":" ) ? ":/effects/"+scriptName.mid(1) : path + QDir::separator() + scriptName;
|
QString scriptFilePath = path + scriptName;
|
||||||
|
QFile pyScriptFile(scriptFilePath);
|
||||||
|
|
||||||
|
if (scriptName.isEmpty() || !pyScriptFile.open(QIODevice::ReadOnly))
|
||||||
|
{
|
||||||
|
Error(_log, "Python script '%s' in effect schema '%s' could not be loaded", QSTRING_CSTR(scriptName), QSTRING_CSTR(schemaFilePath));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
pyScriptFile.close();
|
||||||
|
|
||||||
|
effectSchema.pyFile = scriptFilePath;
|
||||||
effectSchema.pySchema = schemaEffect;
|
effectSchema.pySchema = schemaEffect;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
@ -85,6 +85,17 @@ void WebSocketClient::handleWebSocketFrame()
|
|||||||
case OPCODE::BINARY:
|
case OPCODE::BINARY:
|
||||||
case OPCODE::TEXT:
|
case OPCODE::TEXT:
|
||||||
{
|
{
|
||||||
|
// A fragmented message consists of a single frame with the FIN bit
|
||||||
|
// clear and an opcode other than 0, followed by zero or more frames
|
||||||
|
// with the FIN bit clear and the opcode set to 0, and terminated by
|
||||||
|
// a single frame with the FIN bit set and an opcode of 0.
|
||||||
|
//
|
||||||
|
// Store frame type given by first frame
|
||||||
|
if (_wsh.opCode != OPCODE::CONTINUATION )
|
||||||
|
{
|
||||||
|
_frameOpCode = _wsh.opCode;
|
||||||
|
}
|
||||||
|
|
||||||
// check for protocol violations
|
// check for protocol violations
|
||||||
if (_onContinuation && !isContinuation)
|
if (_onContinuation && !isContinuation)
|
||||||
{
|
{
|
||||||
@ -117,9 +128,9 @@ void WebSocketClient::handleWebSocketFrame()
|
|||||||
if (_wsh.fin)
|
if (_wsh.fin)
|
||||||
{
|
{
|
||||||
_onContinuation = false;
|
_onContinuation = false;
|
||||||
if (_wsh.opCode == OPCODE::TEXT)
|
|
||||||
{
|
|
||||||
|
|
||||||
|
if (_frameOpCode == OPCODE::TEXT)
|
||||||
|
{
|
||||||
_jsonAPI->handleMessage(QString(_wsReceiveBuffer));
|
_jsonAPI->handleMessage(QString(_wsReceiveBuffer));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
|
@ -52,6 +52,9 @@ private:
|
|||||||
// websocket header store
|
// websocket header store
|
||||||
WebSocketHeader _wsh;
|
WebSocketHeader _wsh;
|
||||||
|
|
||||||
|
//opCode of first frame (in case of fragmented frames)
|
||||||
|
quint8 _frameOpCode;
|
||||||
|
|
||||||
// masks for fields in the basic header
|
// masks for fields in the basic header
|
||||||
static uint8_t const BHB0_OPCODE = 0x0F;
|
static uint8_t const BHB0_OPCODE = 0x0F;
|
||||||
static uint8_t const BHB0_RSV3 = 0x10;
|
static uint8_t const BHB0_RSV3 = 0x10;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user