From 36d574179b514d9762c83dab478a626605631bd5 Mon Sep 17 00:00:00 2001 From: ispyisail Date: Mon, 5 Oct 2026 18:35:38 +1300 Subject: [PATCH] Assistant house style: rewrite qet-assistant.json when the style changes qet.setHouseStyle() only saved the setting, so an assistant reading qet-assistant.json saw the old text until QElectroTech restarted. AssistantInfo::refresh() writes the file again, but only in a QElectroTech that writes it at all: a headless --run would otherwise replace the open QElectroTech's live channel with its own empty one. Co-Authored-By: Claude Opus 5.5 --- sources/scripting/assistantinfo.cpp | 18 +++++++++++++++--- sources/scripting/assistantinfo.h | 1 + sources/scripting/qetscriptapi.cpp | 4 ++++ 3 files changed, 20 insertions(+), 3 deletions(-) diff --git a/sources/scripting/assistantinfo.cpp b/sources/scripting/assistantinfo.cpp index a6a81eab8..f35e8c9f1 100644 --- a/sources/scripting/assistantinfo.cpp +++ b/sources/scripting/assistantinfo.cpp @@ -36,6 +36,7 @@ namespace { QJsonObject s_live; ///< empty while live mode is closed bool s_running = true; + bool s_watching = false; ///< this QElectroTech writes the file (an editor opened) } namespace AssistantInfo { @@ -54,14 +55,25 @@ QString path() */ void watch() { - static bool watching = false; - if (watching) return; - watching = true; + if (s_watching) return; + s_watching = true; QObject::connect(&ScriptLibrary::instance(), &ScriptLibrary::changed, &write); QObject::connect(qApp, &QCoreApplication::aboutToQuit, &markStopped); write(); } +/** + @brief refresh + Write the file again after a setting it carries changed, but only in a + QElectroTech that writes it at all: a headless --run never opened an + editor, and writing from it would replace the open QElectroTech's live + channel with its own empty one. +*/ +void refresh() +{ + if (s_watching) write(); +} + void write() { QJsonArray scripts, refused; diff --git a/sources/scripting/assistantinfo.h b/sources/scripting/assistantinfo.h index 2243b3deb..02248d9a6 100644 --- a/sources/scripting/assistantinfo.h +++ b/sources/scripting/assistantinfo.h @@ -43,6 +43,7 @@ namespace AssistantInfo QString path(); void watch(); void write(); + void refresh(); void setLive(const QJsonObject &live); void markStopped(); } diff --git a/sources/scripting/qetscriptapi.cpp b/sources/scripting/qetscriptapi.cpp index e8bdddf9d..87894037d 100644 --- a/sources/scripting/qetscriptapi.cpp +++ b/sources/scripting/qetscriptapi.cpp @@ -45,6 +45,7 @@ #include "../conductorrouter.h" #include "../qetgraphicsitem/diagramimageitem.h" #include "../utils/qetsettings.h" +#include "assistantinfo.h" // See diagrameventaddpdf.h: a missing QtPdf module (or Qt < 6.4) is not // fatal at build time, so addPdfPage() is always declared -- a script @@ -4224,6 +4225,9 @@ QString QetScriptApi::houseStyle() const bool QetScriptApi::setHouseStyle(const QString &text) { QetSettings::setHouseStyle(text); + //qet-assistant.json carries it: an assistant reading the file + //now must see the new text, not the one from the last start + AssistantInfo::refresh(); return true; }