Show connection type/last seen
This commit is contained in:
@@ -82,20 +82,7 @@
|
||||
<string>ZecQT Wallet Companion App</string>
|
||||
</property>
|
||||
<layout class="QGridLayout" name="gridLayout_2">
|
||||
<item row="2" 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">
|
||||
<item row="5" column="0">
|
||||
<widget class="QPushButton" name="btnDisconnect">
|
||||
<property name="sizePolicy">
|
||||
<sizepolicy hsizetype="Preferred" vsizetype="Fixed">
|
||||
@@ -108,11 +95,61 @@
|
||||
</property>
|
||||
</widget>
|
||||
</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">
|
||||
<widget class="QLabel" name="lblRemoteName">
|
||||
<property name="text">
|
||||
<string notr="true">TextLabel</string>
|
||||
</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>
|
||||
</item>
|
||||
</layout>
|
||||
|
||||
@@ -12,7 +12,7 @@ WSServer::WSServer(quint16 port, bool debug, QObject *parent) :
|
||||
m_debug(debug)
|
||||
{
|
||||
m_mainWindow = (MainWindow *) parent;
|
||||
if (m_pWebSocketServer->listen(QHostAddress::AnyIPv4, port+100)) {
|
||||
if (m_pWebSocketServer->listen(QHostAddress::AnyIPv4, port)) {
|
||||
if (m_debug)
|
||||
qDebug() << "Echoserver listening on port" << port;
|
||||
connect(m_pWebSocketServer, &QWebSocketServer::newConnection,
|
||||
@@ -46,7 +46,7 @@ void WSServer::processTextMessage(QString message)
|
||||
qDebug() << "Message received:" << message;
|
||||
|
||||
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)
|
||||
{
|
||||
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();
|
||||
}
|
||||
|
||||
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) {
|
||||
QDialog d(parent);
|
||||
ui = new Ui_MobileAppConnector();
|
||||
@@ -170,6 +186,9 @@ void AppDataServer::connectAppDialog(MainWindow* parent) {
|
||||
updateConnectedUI();
|
||||
});
|
||||
|
||||
QObject::connect(ui->txtConnStr, &QLineEdit::cursorPositionChanged, [=](int, int) {
|
||||
ui->txtConnStr->selectAll();
|
||||
});
|
||||
|
||||
d.exec();
|
||||
|
||||
@@ -220,12 +239,25 @@ void AppDataServer::registerNewTempSecret(QString tmpSecretHex, MainWindow* main
|
||||
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() {
|
||||
if (ui == nullptr)
|
||||
return;
|
||||
|
||||
auto remoteName = QSettings().value("mobileapp/connectedname", "").toString();
|
||||
|
||||
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());
|
||||
}
|
||||
|
||||
@@ -360,6 +392,7 @@ QString AppDataServer::decryptMessage(QJsonDocument msg, QString secretHex, QStr
|
||||
} else {
|
||||
// Update the last seen remote hex
|
||||
saveNonceHex(NonceType::REMOTE, noncehex);
|
||||
saveLastSeenTime();
|
||||
|
||||
char* decryptedStr = new char[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)
|
||||
void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient) {
|
||||
void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient, AppConnectionType connType) {
|
||||
auto replyWithError = [=]() {
|
||||
auto r = QJsonDocument(QJsonObject{
|
||||
{"error", "Encryption error"}
|
||||
@@ -424,6 +457,9 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
||||
mainWindow->replaceWormholeClient(tempWormholeClient);
|
||||
tempWormholeClient = nullptr;
|
||||
|
||||
saveLastConnectedOver(connType);
|
||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||
|
||||
// If the Connection UI is showing, we have to update the UI as well
|
||||
if (ui != nullptr) {
|
||||
// Update the connected phone information
|
||||
@@ -433,7 +469,6 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
||||
updateUIWithNewQRCode(mainWindow);
|
||||
}
|
||||
|
||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -442,6 +477,7 @@ void AppDataServer::processMessage(QString message, MainWindow* mainWindow, QWeb
|
||||
return;
|
||||
}
|
||||
} else {
|
||||
saveLastConnectedOver(connType);
|
||||
processDecryptedMessage(decrypted, mainWindow, pClient);
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -60,6 +60,11 @@ enum NonceType {
|
||||
REMOTE
|
||||
};
|
||||
|
||||
enum AppConnectionType {
|
||||
DIRECT = 1,
|
||||
INTERNET
|
||||
};
|
||||
|
||||
class AppDataServer {
|
||||
public:
|
||||
static AppDataServer* getInstance() {
|
||||
@@ -74,7 +79,7 @@ public:
|
||||
void updateUIWithNewQRCode(MainWindow* mainwindow);
|
||||
|
||||
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 processDecryptedMessage(QString message, MainWindow* mainWindow, QWebSocket* pClient);
|
||||
void processGetTransactions(MainWindow* mainWindow, QWebSocket* pClient);
|
||||
@@ -91,6 +96,14 @@ public:
|
||||
QString getNonceHex(NonceType nt);
|
||||
void saveNonceHex(NonceType nt, QString noncehex);
|
||||
|
||||
void saveLastSeenTime();
|
||||
QDateTime getLastSeenTime();
|
||||
|
||||
QString connDesc(AppConnectionType t);
|
||||
|
||||
void saveLastConnectedOver(AppConnectionType type);
|
||||
AppConnectionType getLastConnectionType();
|
||||
|
||||
private:
|
||||
AppDataServer() = default;
|
||||
|
||||
|
||||
Reference in New Issue
Block a user