diff --git a/assignment-client/src/scripts/EntityScriptServer.cpp b/assignment-client/src/scripts/EntityScriptServer.cpp index f1ba93b68a..e64e2fe3ce 100644 --- a/assignment-client/src/scripts/EntityScriptServer.cpp +++ b/assignment-client/src/scripts/EntityScriptServer.cpp @@ -182,23 +182,21 @@ void EntityScriptServer::updateEntityPPS() { void EntityScriptServer::handleEntityServerScriptLogPacket(QSharedPointer message, SharedNodePointer senderNode) { // These are temporary checks until we can ensure that nodes eventually disconnect if the Domain Server stops telling them // about each other. - if (senderNode->getCanRez()) { - bool enable = false; - message->readPrimitive(&enable); + bool enable = false; + message->readPrimitive(&enable); - auto senderUUID = senderNode->getUUID(); - auto it = _logListeners.find(senderUUID); + auto senderUUID = senderNode->getUUID(); + auto it = _logListeners.find(senderUUID); - if (enable) { - if (it == std::end(_logListeners)) { - _logListeners.insert(senderUUID); - qInfo() << "Node" << senderUUID << "subscribed to log stream"; - } - } else { - if (it != std::end(_logListeners)) { - _logListeners.erase(it); - qInfo() << "Node" << senderUUID << "unsubscribed from log stream"; - } + if (enable && senderNode->getCanRez()) { + if (it == std::end(_logListeners)) { + _logListeners.insert(senderUUID); + qInfo() << "Node" << senderUUID << "subscribed to log stream"; + } + } else { + if (it != std::end(_logListeners)) { + _logListeners.erase(it); + qInfo() << "Node" << senderUUID << "unsubscribed from log stream"; } } } diff --git a/interface/src/EntityScriptServerLogClient.cpp b/interface/src/EntityScriptServerLogClient.cpp index 3a8e248499..e02bd6cb5c 100644 --- a/interface/src/EntityScriptServerLogClient.cpp +++ b/interface/src/EntityScriptServerLogClient.cpp @@ -22,17 +22,22 @@ EntityScriptServerLogClient::EntityScriptServerLogClient() { QObject::connect(nodeList.data(), &NodeList::canRezChanged, this, &EntityScriptServerLogClient::canRezChanged); } - void EntityScriptServerLogClient::connectNotify(const QMetaMethod& signal) { - auto numReceivers = receivers(SIGNAL(receivedNewLogLines(QString))); - if (!_subscribed && numReceivers > 0) { - enableToEntityServerScriptLog(DependencyManager::get()->getThisNodeCanRez()); - } + // This needs to be delayed or "receivers()" will return completely inconsistent values + QMetaObject::invokeMethod(this, "connectionsChanged", Qt::QueuedConnection); } void EntityScriptServerLogClient::disconnectNotify(const QMetaMethod& signal) { + // This needs to be delayed or "receivers()" will return completely inconsistent values + QMetaObject::invokeMethod(this, "connectionsChanged", Qt::QueuedConnection); +} + +void EntityScriptServerLogClient::connectionsChanged() { + qDebug() << Q_FUNC_INFO << _subscribed << receivers(SIGNAL(receivedNewLogLines(QString))); auto numReceivers = receivers(SIGNAL(receivedNewLogLines(QString))); - if (_subscribed && numReceivers == 0) { + if (!_subscribed && numReceivers > 0) { + enableToEntityServerScriptLog(DependencyManager::get()->getThisNodeCanRez()); + } else if (_subscribed && numReceivers == 0) { enableToEntityServerScriptLog(false); } } diff --git a/interface/src/EntityScriptServerLogClient.h b/interface/src/EntityScriptServerLogClient.h index 6fb0c9a3ce..22245e2a4e 100644 --- a/interface/src/EntityScriptServerLogClient.h +++ b/interface/src/EntityScriptServerLogClient.h @@ -37,6 +37,8 @@ private slots: void nodeKilled(SharedNodePointer killedNode); void canRezChanged(bool canRez); + void connectionsChanged(); + private: bool _subscribed { false }; }; diff --git a/interface/src/Menu.cpp b/interface/src/Menu.cpp index bc4de76f1c..acf97ad5f7 100644 --- a/interface/src/Menu.cpp +++ b/interface/src/Menu.cpp @@ -705,13 +705,11 @@ Menu::Menu() { qApp, SLOT(toggleLogDialog())); auto essLogAction = addActionToQMenuAndActionHash(developerMenu, MenuOption::EntityScriptServerLog, 0, qApp, SLOT(toggleEntityScriptServerLogDialog())); - auto shouldEnableLog = [essLogAction] { + QObject::connect(nodeList.data(), &NodeList::canRezChanged, essLogAction, [essLogAction] { auto nodeList = DependencyManager::get(); - essLogAction->setEnabled(nodeList->getThisNodeCanRez() || nodeList->getThisNodeCanRezTmp()); - }; - QObject::connect(nodeList.data(), &NodeList::canRezChanged, essLogAction, shouldEnableLog); - QObject::connect(nodeList.data(), &NodeList::canRezTmpChanged, essLogAction, shouldEnableLog); - shouldEnableLog(); + essLogAction->setEnabled(nodeList->getThisNodeCanRez()); + }); + essLogAction->setEnabled(nodeList->getThisNodeCanRez()); action = addActionToQMenuAndActionHash(developerMenu, "Script Log (HMD friendly)..."); connect(action, &QAction::triggered, [] { diff --git a/interface/src/ui/BaseLogDialog.cpp b/interface/src/ui/BaseLogDialog.cpp index c17ede4a56..47cea9c26a 100644 --- a/interface/src/ui/BaseLogDialog.cpp +++ b/interface/src/ui/BaseLogDialog.cpp @@ -111,7 +111,8 @@ void BaseLogDialog::handleSearchTextChanged(QString searchText) { } void BaseLogDialog::showLogData() { - _logTextBox->setPlainText(getCurrentLog()); + _logTextBox->clear(); + _logTextBox->appendPlainText(getCurrentLog()); _logTextBox->ensureCursorVisible(); } diff --git a/scripts/developer/debugging/essDebugWindow.js b/scripts/developer/debugging/essDebugWindow.js index 7622655d13..fbce09f93d 100644 --- a/scripts/developer/debugging/essDebugWindow.js +++ b/scripts/developer/debugging/essDebugWindow.js @@ -21,7 +21,7 @@ window.setPosition(25, 50); window.closed.connect(function() { Script.stop(); }); EntityScriptServerLog.receivedNewLogLines.connect(function(message) { - window.sendToQml(message); + window.sendToQml(message.trim()); });