diff --git a/sources/scripting/assistantinfo.cpp b/sources/scripting/assistantinfo.cpp index 97d236722..96d032d97 100644 --- a/sources/scripting/assistantinfo.cpp +++ b/sources/scripting/assistantinfo.cpp @@ -102,6 +102,7 @@ void write() {QStringLiteral("scripting_available"), false}, #endif {QStringLiteral("scripting_enabled"), QetSettings::scriptingEnabled()}, + {QStringLiteral("live_mode_setting"), QetSettings::liveAssistantEnabled()}, {QStringLiteral("live_mode_open"), !s_live.isEmpty()}}}, {QStringLiteral("script_api"), QJsonArray::fromStringList(QetScriptApi::signatures())}, {QStringLiteral("stored_scripts"), scripts}, diff --git a/sources/scripting/liveserver.cpp b/sources/scripting/liveserver.cpp index 1b9ab2995..1d14179f6 100644 --- a/sources/scripting/liveserver.cpp +++ b/sources/scripting/liveserver.cpp @@ -17,6 +17,7 @@ */ #include "liveserver.h" +#include "assistantinfo.h" #include "qetscripting.h" #include "scriptlibrary.h" #include "../diagram.h" @@ -67,17 +68,6 @@ LiveServer::LiveServer() LiveServer::~LiveServer() { - QFile::remove(sessionFile()); -} - -/** - @brief LiveServer::sessionFile - Where the channel's name and token are written for the MCP server: - next to the stored scripts, in the user's data folder. -*/ -QString LiveServer::sessionFile() -{ - return QETApp::dataDir() + QStringLiteral("/live-session.json"); } /** @@ -135,19 +125,12 @@ bool LiveServer::start() } m_token = randomHex(16); - const QJsonObject session{ - {QStringLiteral("version"), 1}, + //Where the MCP server finds the channel: the "live" part of + //qet-assistant.json, the one file it reads about this QElectroTech + AssistantInfo::setLive(QJsonObject{ {QStringLiteral("socket"), m_server->fullServerName()}, {QStringLiteral("token"), m_token}, - {QStringLiteral("pid"), QCoreApplication::applicationPid()}}; - QSaveFile file(sessionFile()); - if (!file.open(QIODevice::WriteOnly) - || file.write(QJsonDocument(session).toJson(QJsonDocument::Compact)) < 0 - || !file.commit()) { - stop(); - return false; - } - QFile::setPermissions(sessionFile(), QFile::ReadOwner | QFile::WriteOwner); + {QStringLiteral("pid"), QCoreApplication::applicationPid()}}); connect(m_server, &QLocalServer::newConnection, this, &LiveServer::newConnection); setState(Waiting); @@ -169,7 +152,7 @@ void LiveServer::stop() m_server->deleteLater(); m_server = nullptr; } - QFile::remove(sessionFile()); + if (!m_token.isEmpty()) AssistantInfo::setLive(QJsonObject()); m_token.clear(); m_buffer.clear(); setState(Off); diff --git a/sources/scripting/liveserver.h b/sources/scripting/liveserver.h index 60f47e8c7..24f098ea4 100644 --- a/sources/scripting/liveserver.h +++ b/sources/scripting/liveserver.h @@ -38,9 +38,9 @@ class QWidget; class opens nothing and QElectroTech behaves as if it did not exist. The channel is a QLocalServer only the user's own account can open, - with a random name and token written to live-session.json in the data - folder, which the MCP server reads; the file goes when the channel - closes. One JSON request per connection, one JSON answer back, then + with a random name and token written to the "live" part of + qet-assistant.json (AssistantInfo), which the MCP server reads, and + cleared when the channel closes. One JSON request per connection, one JSON answer back, then the server closes the connection; every request carries the token. Requests are never handled inside the socket's readyRead: each is @@ -56,7 +56,6 @@ class LiveServer : public QObject enum State { Off, Waiting, Connected }; static LiveServer &instance(); - static QString sessionFile(); void askAndStart(QWidget *parent); void stop();