state indicator: simple forever-loop via statewait subprocess
This commit is contained in:
parent
de835e9e6e
commit
1aa1455f33
|
|
@ -61,6 +61,12 @@ void Ollie9pClient::setActiveSessionId(const QString &id)
|
|||
m_agentId = "0";
|
||||
}
|
||||
|
||||
// Read initial state immediately (state, not statewait)
|
||||
QByteArray stateOut = run9p({"read", agentPath() + "/state"});
|
||||
QString stateStr = QString::fromUtf8(stateOut).trimmed();
|
||||
if (!stateStr.isEmpty())
|
||||
m_activeState = stateStr;
|
||||
|
||||
emit activeSessionIdChanged();
|
||||
emit activeStateChanged();
|
||||
|
||||
|
|
@ -195,25 +201,17 @@ void Ollie9pClient::onChatReadyRead()
|
|||
|
||||
void Ollie9pClient::onStateReadyRead()
|
||||
{
|
||||
// statewait returns the state string on stdout. Parse it and update.
|
||||
QByteArray data = m_stateProc->readAllStandardOutput();
|
||||
QString state = QString::fromUtf8(data).trimmed();
|
||||
if (!state.isEmpty()) {
|
||||
// statewait returns one line per state change; take the last one
|
||||
QStringList lines = state.split('\n', Qt::SkipEmptyParts);
|
||||
if (!lines.isEmpty()) {
|
||||
m_activeState = lines.last().trimmed();
|
||||
emit activeStateChanged();
|
||||
}
|
||||
m_activeState = state;
|
||||
emit activeStateChanged();
|
||||
}
|
||||
// statewait exits after one read — restart it for continuous monitoring
|
||||
m_stateProc->deleteLater();
|
||||
m_stateProc = nullptr;
|
||||
startStateStream();
|
||||
}
|
||||
|
||||
void Ollie9pClient::onChatFinished(int, QProcess::ExitStatus)
|
||||
{
|
||||
// Chat stream ended — session was killed or connection lost
|
||||
m_chatProc->deleteLater();
|
||||
m_chatProc = nullptr;
|
||||
emit streamingDone();
|
||||
|
|
@ -221,11 +219,9 @@ void Ollie9pClient::onChatFinished(int, QProcess::ExitStatus)
|
|||
|
||||
void Ollie9pClient::onStateFinished(int, QProcess::ExitStatus)
|
||||
{
|
||||
// State process exited unexpectedly (not via onStateReadyRead restart)
|
||||
if (m_stateProc) {
|
||||
m_stateProc->deleteLater();
|
||||
m_stateProc = nullptr;
|
||||
}
|
||||
m_stateProc->deleteLater();
|
||||
m_stateProc = nullptr;
|
||||
startStateStream();
|
||||
}
|
||||
|
||||
// --- Helpers ---
|
||||
|
|
|
|||
Reference in New Issue