1
mirror of https://github.com/monero-project/monero-gui synced 2024-12-29 23:26:24 +01:00

DaemonManager: implement async sendCommand

This commit is contained in:
xiphon 2019-09-27 10:56:42 +00:00
parent d3b81cb6f8
commit 32257c8fab
4 changed files with 24 additions and 15 deletions

View File

@ -178,7 +178,11 @@ Window {
onAccepted: { onAccepted: {
if(text.length > 0) { if(text.length > 0) {
textArea.logCommand(">>> " + text) textArea.logCommand(">>> " + text)
daemonManager.sendCommand(text, currentWallet.nettype); daemonManager.sendCommandAsync(text.split(" "), currentWallet.nettype, function(result) {
if (!result) {
appWindow.showStatusMessage(qsTr("Failed to send command"), 3);
}
});
} }
text = "" text = ""
} }

View File

@ -216,7 +216,11 @@ Rectangle {
onAccepted: { onAccepted: {
if(text.length > 0) { if(text.length > 0) {
consoleArea.logCommand(">>> " + text) consoleArea.logCommand(">>> " + text)
daemonManager.sendCommand(text, currentWallet.nettype); daemonManager.sendCommandAsync(text.split(" "), currentWallet.nettype, function(result) {
if (!result) {
appWindow.showStatusMessage(qsTr("Failed to send command"), 3);
}
});
} }
text = "" text = ""
} }

View File

@ -150,7 +150,7 @@ bool DaemonManager::start(const QString &flags, NetworkType::Type nettype, const
bool DaemonManager::stop(NetworkType::Type nettype) bool DaemonManager::stop(NetworkType::Type nettype)
{ {
QString message; QString message;
sendCommand("exit", nettype, message); sendCommand({"exit"}, nettype, message);
qDebug() << message; qDebug() << message;
// Start stop watcher - Will kill if not shutting down // Start stop watcher - Will kill if not shutting down
@ -240,7 +240,7 @@ void DaemonManager::printError()
bool DaemonManager::running(NetworkType::Type nettype) const bool DaemonManager::running(NetworkType::Type nettype) const
{ {
QString status; QString status;
sendCommand("sync_info", nettype, status); sendCommand({"sync_info"}, nettype, status);
qDebug() << status; qDebug() << status;
return status.contains("Height:"); return status.contains("Height:");
} }
@ -257,17 +257,10 @@ void DaemonManager::runningAsync(NetworkType::Type nettype, const QJSValue& call
}, callback); }, callback);
} }
bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype) const bool DaemonManager::sendCommand(const QStringList &cmd, NetworkType::Type nettype, QString &message) const
{
QString message;
return sendCommand(cmd, nettype, message);
}
bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype, QString &message) const
{ {
QProcess p; QProcess p;
QStringList external_cmd; QStringList external_cmd(cmd);
external_cmd << cmd;
// Add network type flag if needed // Add network type flag if needed
if (nettype == NetworkType::TESTNET) if (nettype == NetworkType::TESTNET)
@ -286,6 +279,14 @@ bool DaemonManager::sendCommand(const QString &cmd, NetworkType::Type nettype, Q
return started; return started;
} }
void DaemonManager::sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QJSValue& callback) const
{
m_scheduler.run([this, cmd, nettype] {
QString message;
return QJSValueList({sendCommand(cmd, nettype, message)});
}, callback);
}
void DaemonManager::exit() void DaemonManager::exit()
{ {
qDebug("DaemonManager: exit()"); qDebug("DaemonManager: exit()");

View File

@ -51,14 +51,14 @@ public:
// return true if daemon process is started // return true if daemon process is started
Q_INVOKABLE void runningAsync(NetworkType::Type nettype, const QJSValue& callback) const; Q_INVOKABLE void runningAsync(NetworkType::Type nettype, const QJSValue& callback) const;
// Send daemon command from qml and prints output in console window. // Send daemon command from qml and prints output in console window.
Q_INVOKABLE bool sendCommand(const QString &cmd, NetworkType::Type nettype) const; Q_INVOKABLE void sendCommandAsync(const QStringList &cmd, NetworkType::Type nettype, const QJSValue& callback) const;
Q_INVOKABLE void exit(); Q_INVOKABLE void exit();
Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const; Q_INVOKABLE QVariantMap validateDataDir(const QString &dataDir) const;
private: private:
bool running(NetworkType::Type nettype) const; bool running(NetworkType::Type nettype) const;
bool sendCommand(const QString &cmd, NetworkType::Type nettype, QString &message) const; bool sendCommand(const QStringList &cmd, NetworkType::Type nettype, QString &message) const;
bool startWatcher(NetworkType::Type nettype) const; bool startWatcher(NetworkType::Type nettype) const;
bool stopWatcher(NetworkType::Type nettype) const; bool stopWatcher(NetworkType::Type nettype) const;
signals: signals: