diff --git a/src/mobileappconnector.ui b/src/mobileappconnector.ui
index 89209c8..ff5fe53 100644
--- a/src/mobileappconnector.ui
+++ b/src/mobileappconnector.ui
@@ -78,21 +78,7 @@
ZecQT Wallet Companion App
- -
-
-
- Disconnect
-
-
-
- -
-
-
- Connected Phone Name and Description
-
-
-
- -
+
-
Qt::Vertical
@@ -106,14 +92,20 @@
-
-
+
+
+
+ 0
+ 0
+
+
- TextLabel
+ Disconnect
- -
-
+
-
+
TextLabel
diff --git a/src/websockets.cpp b/src/websockets.cpp
index 8647529..48183b8 100644
--- a/src/websockets.cpp
+++ b/src/websockets.cpp
@@ -86,12 +86,13 @@ void AppDataServer::saveNewSecret(QString secretHex) {
s.sync();
}
-QString AppDataServer::tempSecret;
+QString AppDataServer::tempSecret = "";
+Ui_MobileAppConnector* AppDataServer::ui = nullptr;
void AppDataServer::connectAppDialog(QWidget* parent) {
QDialog d(parent);
- Ui_MobileAppConnector con;
- con.setupUi(&d);
+ ui = new Ui_MobileAppConnector();
+ ui->setupUi(&d);
Settings::saveRestore(&d);
// Get the address of the localhost
@@ -123,13 +124,34 @@ void AppDataServer::connectAppDialog(QWidget* parent) {
QString codeStr = uri + "," + secretStr;
- con.lblConnStr->setText(codeStr);
- con.qrcode->setQrcodeString(codeStr);
- con.lblRemoteNonce->setText(AppDataServer::getNonceHex(NonceType::REMOTE));
- con.lblLocalNonce->setText(AppDataServer::getNonceHex(NonceType::LOCAL));
+ ui->lblConnStr->setText(codeStr);
+ ui->qrcode->setQrcodeString(codeStr);
+
+ updateConnectedUI();
+
+ QObject::connect(ui->btnDisconnect, &QPushButton::clicked, [=] () {
+ QSettings().setValue("mobileapp/connectedname", "");
+ saveNewSecret("");
+
+ updateConnectedUI();
+ });
+
d.exec();
+
+ // Cleanup
tempSecret = "";
+ delete ui;
+ ui = nullptr;
+}
+
+void AppDataServer::updateConnectedUI() {
+ if (ui == nullptr)
+ return;
+
+ auto remoteName = QSettings().value("mobileapp/connectedname", "").toString();
+ ui->lblRemoteName->setText(remoteName.isEmpty() ? "(Not connected to any device)" : remoteName);
+ ui->btnDisconnect->setEnabled(!remoteName.isEmpty());
}
QString AppDataServer::getNonceHex(NonceType nt) {
@@ -311,17 +333,20 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
saveNewSecret(tempSecret);
AppDataServer::saveNonceHex(NonceType::REMOTE, QString("00").repeated(24));
- // Fall through to processDecryptedMessage
+ processDecryptedMessage(decrypted, mainWindow, pClient);
+
+ // If the Connection UI is showing, we have to update the UI as well
+ if (ui != nullptr) {
+ updateConnectedUI();
+ }
}
}
else {
replyWithError();
- return;
}
-
+ } else {
+ processDecryptedMessage(decrypted, mainWindow, pClient);
}
-
- processDecryptedMessage(decrypted, mainWindow, pClient);
}
void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient) {
@@ -338,7 +363,7 @@ void AppDataServer::processDecryptedMessage(QString message, MainWindow* mainWin
}
if (msg.object()["command"] == "getInfo") {
- processGetInfo(mainWindow, pClient);
+ processGetInfo(msg.object(), mainWindow, pClient);
}
else if (msg.object()["command"] == "getTransactions") {
processGetTransactions(mainWindow, pClient);
@@ -434,7 +459,14 @@ void AppDataServer::processSendTx(QJsonObject sendTx, MainWindow* mainwindow, QW
pClient->sendTextMessage(encryptOutgoing(r));
}
-void AppDataServer::processGetInfo(MainWindow* mainWindow, QWebSocket* pClient) {
+void AppDataServer::processGetInfo(QJsonObject jobj, MainWindow* mainWindow, QWebSocket* pClient) {
+ auto connectedName = jobj["name"].toString();
+
+ {
+ QSettings s;
+ s.setValue("mobileapp/connectedname", connectedName);
+ }
+
auto r = QJsonDocument(QJsonObject{
{"version", 1.0},
{"command", "getInfo"},
diff --git a/src/websockets.h b/src/websockets.h
index 624bb3d..13d0c86 100644
--- a/src/websockets.h
+++ b/src/websockets.h
@@ -1,9 +1,11 @@
#ifndef WEBSOCKETS_H
#define WEBSOCKETS_H
-#include "mainwindow.h"
#include "precompiled.h"
+#include "mainwindow.h"
+#include "ui_mobileappconnector.h"
+
QT_FORWARD_DECLARE_CLASS(QWebSocketServer)
QT_FORWARD_DECLARE_CLASS(QWebSocket)
@@ -39,11 +41,12 @@ enum NonceType {
class AppDataServer {
public:
static void connectAppDialog(QWidget* parent);
+ static void updateConnectedUI();
static void processSendTx(QJsonObject sendTx, MainWindow* mainwindow, QWebSocket* pClient);
static void processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
static void processDecryptedMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
- static void processGetInfo(MainWindow* mainWindow, QWebSocket* pClient);
+ static void processGetInfo(QJsonObject jobj, MainWindow* mainWindow, QWebSocket* pClient);
static void processGetTransactions(MainWindow* mainWindow, QWebSocket* pClient);
static QString decryptMessage(QJsonDocument msg, QString secretHex, bool skipNonceCheck = false);
@@ -57,6 +60,7 @@ public:
private:
static QString tempSecret;
+ static Ui_MobileAppConnector* ui;
};
class AppDataModel {