Show connection type/last seen
This commit is contained in:
@@ -82,20 +82,7 @@
|
|||||||
<string>ZecQT Wallet Companion App</string>
|
<string>ZecQT Wallet Companion App</string>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QGridLayout" name="gridLayout_2">
|
<layout class="QGridLayout" name="gridLayout_2">
|
||||||
<item row="2" column="0">
|
<item row="5" column="0">
|
||||||
<spacer name="verticalSpacer">
|
|
||||||
<property name="orientation">
|
|
||||||
<enum>Qt::Vertical</enum>
|
|
||||||
</property>
|
|
||||||
<property name="sizeHint" stdset="0">
|
|
||||||
<size>
|
|
||||||
<width>20</width>
|
|
||||||
<height>40</height>
|
|
||||||
</size>
|
|
||||||
</property>
|
|
||||||
</spacer>
|
|
||||||
</item>
|
|
||||||
<item row="1" column="0">
|
|
||||||
<widget class="QPushButton" name="btnDisconnect">
|
<widget class="QPushButton" name="btnDisconnect">
|
||||||
<property name="sizePolicy">
|
<property name="sizePolicy">
|
||||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||||
@@ -108,11 +95,61 @@
|
|||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="6" column="0">
|
||||||
|
<spacer name="verticalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Vertical</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>40</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<item row="2" column="0">
|
||||||
|
<widget class="QLabel" name="lblLastSeen">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="1" column="0">
|
||||||
|
<widget class="QLabel" name="label_3">
|
||||||
|
<property name="text">
|
||||||
|
<string>Last seen:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item row="0" column="0">
|
<item row="0" column="0">
|
||||||
<widget class="QLabel" name="lblRemoteName">
|
<widget class="QLabel" name="lblRemoteName">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string notr="true">TextLabel</string>
|
<string notr="true">TextLabel</string>
|
||||||
</property>
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="3" column="0">
|
||||||
|
<widget class="QLabel" name="label_4">
|
||||||
|
<property name="text">
|
||||||
|
<string>Connection type:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item row="4" column="0">
|
||||||
|
<widget class="QLabel" name="lblConnectionType">
|
||||||
|
<property name="text">
|
||||||
|
<string>TextLabel</string>
|
||||||
|
</property>
|
||||||
|
<property name="alignment">
|
||||||
|
<set>Qt::AlignRight|Qt::AlignTrailing|Qt::AlignVCenter</set>
|
||||||
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
|
|||||||
@@ -12,7 +12,7 @@ WSServer::WSServer(quint16 port, bool debug, QObject *parent) :
|
|||||||
m_debug(debug)
|
m_debug(debug)
|
||||||
{
|
{
|
||||||
m_mainWindow = (MainWindow *) parent;
|
m_mainWindow = (MainWindow *) parent;
|
||||||
if (m_pWebSocketServer->listen(QHostAddress::AnyIPv4, port+100)) {
|
if (m_pWebSocketServer->listen(QHostAddress::AnyIPv4, port)) {
|
||||||
if (m_debug)
|
if (m_debug)
|
||||||
qDebug() << "Echoserver listening on port" << port;
|
qDebug() << "Echoserver listening on port" << port;
|
||||||
connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
|
connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
|
||||||
@@ -46,7 +46,7 @@ void WSServer::processTextMessage(QString message)
|
|||||||
qDebug() << "Message received:" << message;
|
qDebug() << "Message received:" << message;
|
||||||
|
|
||||||
if (pClient) {
|
if (pClient) {
|
||||||
AppDataServer::getInstance()->processMessage(message, m_mainWindow, pClient);
|
AppDataServer::getInstance()->processMessage(message, m_mainWindow, pClient, AppConnectionType::DIRECT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -108,7 +108,7 @@ void WormholeClient::onConnected()
|
|||||||
void WormholeClient::onTextMessageReceived(QString message)
|
void WormholeClient::onTextMessageReceived(QString message)
|
||||||
{
|
{
|
||||||
qDebug() << "Message received:" << message;
|
qDebug() << "Message received:" << message;
|
||||||
AppDataServer::getInstance()->processMessage(message, parent, &m_webSocket);
|
AppDataServer::getInstance()->processMessage(message, parent, &m_webSocket, AppConnectionType::INTERNET);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -154,6 +154,22 @@ void AppDataServer::saveNewSecret(QString secretHex) {
|
|||||||
s.sync();
|
s.sync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void AppDataServer::saveLastConnectedOver(AppConnectionType type) {
|
||||||
|
QSettings().setValue("mobileapp/lastconnectedover", type);
|
||||||
|
}
|
||||||
|
|
||||||
|
AppConnectionType AppDataServer::getLastConnectionType() {
|
||||||
|
return (AppConnectionType) QSettings().value("mobileapp/lastconnectedover", AppConnectionType::DIRECT).toInt();
|
||||||
|
}
|
||||||
|
|
||||||
|
void AppDataServer::saveLastSeenTime() {
|
||||||
|
QSettings().setValue("mobileapp/lastseentime", QDateTime::currentSecsSinceEpoch());
|
||||||
|
}
|
||||||
|
|
||||||
|
QDateTime AppDataServer::getLastSeenTime() {
|
||||||
|
return QDateTime::fromSecsSinceEpoch(QSettings().value("mobileapp/lastseentime", 0).toLongLong());
|
||||||
|
}
|
||||||
|
|
||||||
void AppDataServer::connectAppDialog(MainWindow* parent) {
|
void AppDataServer::connectAppDialog(MainWindow* parent) {
|
||||||
QDialog d(parent);
|
QDialog d(parent);
|
||||||
ui = new Ui_MobileAppConnector();
|
ui = new Ui_MobileAppConnector();
|
||||||
@@ -170,6 +186,9 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
|
|||||||
updateConnectedUI();
|
updateConnectedUI();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
QObject::connect(ui->txtConnStr, &QLineEdit::cursorPositionChanged, [=](int, int) {
|
||||||
|
ui->txtConnStr->selectAll();
|
||||||
|
});
|
||||||
|
|
||||||
d.exec();
|
d.exec();
|
||||||
|
|
||||||
@@ -220,12 +239,25 @@ void AppDataServer::registerNewTempSecret(QString tmpSecretHex, MainWindow* main
|
|||||||
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret));
|
tempWormholeClient = new WormholeClient(main, getWormholeCode(tempSecret));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
QString AppDataServer::connDesc(AppConnectionType t) {
|
||||||
|
if (t == AppConnectionType::DIRECT) {
|
||||||
|
return QObject::tr("Connected directly");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
return QObject::tr("Connected over the internet via zec-qt-wallet service");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void AppDataServer::updateConnectedUI() {
|
void AppDataServer::updateConnectedUI() {
|
||||||
if (ui == nullptr)
|
if (ui == nullptr)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
auto remoteName = QSettings().value("mobileapp/connectedname", "").toString();
|
auto remoteName = QSettings().value("mobileapp/connectedname", "").toString();
|
||||||
|
|
||||||
ui->lblRemoteName->setText(remoteName.isEmpty() ? "(Not connected to any device)" : remoteName);
|
ui->lblRemoteName->setText(remoteName.isEmpty() ? "(Not connected to any device)" : remoteName);
|
||||||
|
ui->lblLastSeen->setText(remoteName.isEmpty() ? "" : getLastSeenTime().toString(Qt::SystemLocaleLongDate));
|
||||||
|
ui->lblConnectionType->setText(remoteName.isEmpty() ? "" : connDesc(getLastConnectionType()));
|
||||||
|
|
||||||
ui->btnDisconnect->setEnabled(!remoteName.isEmpty());
|
ui->btnDisconnect->setEnabled(!remoteName.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -360,6 +392,7 @@ QString AppDataServer::decryptMessage(QJsonDocument msg, QString secretHex, QStr
|
|||||||
} else {
|
} else {
|
||||||
// Update the last seen remote hex
|
// Update the last seen remote hex
|
||||||
saveNonceHex(NonceType::REMOTE, noncehex);
|
saveNonceHex(NonceType::REMOTE, noncehex);
|
||||||
|
saveLastSeenTime();
|
||||||
|
|
||||||
char* decryptedStr = new char[decryptedLen + 1];
|
char* decryptedStr = new char[decryptedLen + 1];
|
||||||
sodium_memzero(decryptedStr, decryptedLen + 1);
|
sodium_memzero(decryptedStr, decryptedLen + 1);
|
||||||
@@ -381,7 +414,7 @@ QString AppDataServer::decryptMessage(QJsonDocument msg, QString secretHex, QStr
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Process an incoming text message. The message has to be encrypted with the secret key (or the temporary secret key)
|
// Process an incoming text message. The message has to be encrypted with the secret key (or the temporary secret key)
|
||||||
void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient) {
|
void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient, AppConnectionType connType) {
|
||||||
auto replyWithError = [=]() {
|
auto replyWithError = [=]() {
|
||||||
auto r = QJsonDocument(QJsonObject{
|
auto r = QJsonDocument(QJsonObject{
|
||||||
{"error", "Encryption error"}
|
{"error", "Encryption error"}
|
||||||
@@ -424,6 +457,9 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
|||||||
mainWindow->replaceWormholeClient(tempWormholeClient);
|
mainWindow->replaceWormholeClient(tempWormholeClient);
|
||||||
tempWormholeClient = nullptr;
|
tempWormholeClient = nullptr;
|
||||||
|
|
||||||
|
saveLastConnectedOver(connType);
|
||||||
|
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||||
|
|
||||||
// If the Connection UI is showing, we have to update the UI as well
|
// If the Connection UI is showing, we have to update the UI as well
|
||||||
if (ui != nullptr) {
|
if (ui != nullptr) {
|
||||||
// Update the connected phone information
|
// Update the connected phone information
|
||||||
@@ -433,7 +469,6 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
|||||||
updateUIWithNewQRCode(mainWindow);
|
updateUIWithNewQRCode(mainWindow);
|
||||||
}
|
}
|
||||||
|
|
||||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -442,6 +477,7 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
saveLastConnectedOver(connType);
|
||||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -60,6 +60,11 @@ enum NonceType {
|
|||||||
REMOTE
|
REMOTE
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum AppConnectionType {
|
||||||
|
DIRECT = 1,
|
||||||
|
INTERNET
|
||||||
|
};
|
||||||
|
|
||||||
class AppDataServer {
|
class AppDataServer {
|
||||||
public:
|
public:
|
||||||
static AppDataServer* getInstance() {
|
static AppDataServer* getInstance() {
|
||||||
@@ -74,7 +79,7 @@ public:
|
|||||||
void updateUIWithNewQRCode(MainWindow* mainwindow);
|
void updateUIWithNewQRCode(MainWindow* mainwindow);
|
||||||
|
|
||||||
void processSendTx(QJsonObject sendTx, MainWindow* mainwindow, QWebSocket* pClient);
|
void processSendTx(QJsonObject sendTx, MainWindow* mainwindow, QWebSocket* pClient);
|
||||||
void processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
|
void processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient, AppConnectionType connType);
|
||||||
void processGetInfo(QJsonObject jobj, MainWindow* mainWindow, QWebSocket* pClient);
|
void processGetInfo(QJsonObject jobj, MainWindow* mainWindow, QWebSocket* pClient);
|
||||||
void processDecryptedMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
|
void processDecryptedMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
|
||||||
void processGetTransactions(MainWindow* mainWindow, QWebSocket* pClient);
|
void processGetTransactions(MainWindow* mainWindow, QWebSocket* pClient);
|
||||||
@@ -91,6 +96,14 @@ public:
|
|||||||
QString getNonceHex(NonceType nt);
|
QString getNonceHex(NonceType nt);
|
||||||
void saveNonceHex(NonceType nt, QString noncehex);
|
void saveNonceHex(NonceType nt, QString noncehex);
|
||||||
|
|
||||||
|
void saveLastSeenTime();
|
||||||
|
QDateTime getLastSeenTime();
|
||||||
|
|
||||||
|
QString connDesc(AppConnectionType t);
|
||||||
|
|
||||||
|
void saveLastConnectedOver(AppConnectionType type);
|
||||||
|
AppConnectionType getLastConnectionType();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
AppDataServer() = default;
|
AppDataServer() = default;
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user