gui: poll bypass file on session switch
Events can be missed if GUI wasn't connected when they were published. Now checkPendingBypass() reads the bypass file directly when switching agents/sessions to catch any pending requests.
This commit is contained in:
parent
f2f1f80e4e
commit
70c00541df
|
|
@ -250,8 +250,9 @@ void Ollie9pClient::handleEvent(const QString &eventLine)
|
|||
rest == QLatin1String("new") || rest == QLatin1String("kill") ||
|
||||
rest == QLatin1String("rename")) {
|
||||
refreshSessions();
|
||||
} else if (rest.startsWith(QLatin1String("bypass.request"))) {
|
||||
} else if (rest.startsWith(QLatin1String("bypass."))) {
|
||||
// Bypass event: payload is "id\tcmd\tcwd"
|
||||
qDebug() << "handleEvent: bypass event" << eventLine;
|
||||
if (payload.isEmpty()) return;
|
||||
const int tab1 = payload.indexOf(QLatin1Char('\t'));
|
||||
if (tab1 < 0) return;
|
||||
|
|
@ -261,6 +262,7 @@ void Ollie9pClient::handleEvent(const QString &eventLine)
|
|||
const QString id = payload.left(tab1).toString();
|
||||
const QString cmd = payload.mid(tab1 + 1, tab2 - tab1 - 1).toString();
|
||||
const QString cwd = payload.mid(tab2 + 1).toString();
|
||||
qDebug() << "handleEvent: emitting bypassRequested" << sessionId << id << cmd.left(50);
|
||||
emit bypassRequested(sessionId.toString(), id, cmd, cwd);
|
||||
}
|
||||
}
|
||||
|
|
@ -830,6 +832,33 @@ void Ollie9pClient::startActiveAgentStreams()
|
|||
|
||||
m_chat->start(agentPath() + "/chat.raw");
|
||||
m_state->start(agentPath() + "/statewait");
|
||||
|
||||
// Check for pending bypass request on this session
|
||||
checkPendingBypass();
|
||||
}
|
||||
|
||||
void Ollie9pClient::checkPendingBypass()
|
||||
{
|
||||
if (m_activeSessionId.isEmpty()) return;
|
||||
if (!m_9p || !m_9p->isConnected()) return;
|
||||
|
||||
QString path = "session/" + m_activeSessionId + "/bypass";
|
||||
QByteArray data = m_9p->read(path);
|
||||
if (data.isEmpty()) return;
|
||||
|
||||
// Parse JSON: {"id":"...","cmd":"...","cwd":"..."}
|
||||
QJsonDocument doc = QJsonDocument::fromJson(data);
|
||||
if (!doc.isObject()) return;
|
||||
|
||||
QJsonObject obj = doc.object();
|
||||
QString id = obj["id"].toString();
|
||||
QString cmd = obj["cmd"].toString();
|
||||
QString cwd = obj["cwd"].toString();
|
||||
|
||||
if (!id.isEmpty() && !cmd.isEmpty()) {
|
||||
qDebug() << "checkPendingBypass: found pending" << id << cmd.left(50);
|
||||
emit bypassRequested(m_activeSessionId, id, cmd, cwd);
|
||||
}
|
||||
}
|
||||
|
||||
void Ollie9pClient::stopAgentStreams()
|
||||
|
|
|
|||
|
|
@ -121,6 +121,7 @@ private:
|
|||
void startEventStream();
|
||||
void handleEvent(const QString &eventLine);
|
||||
void heartbeat();
|
||||
void checkPendingBypass();
|
||||
|
||||
Lib9pClient *m_9p = nullptr;
|
||||
QTimer *m_heartbeatTimer = nullptr;
|
||||
|
|
|
|||
Loading…
Reference in New Issue