mirror of
https://github.com/feather-wallet/feather.git
synced 2025-01-22 02:34:30 +00:00
Settings: allow disabling websocket
This commit is contained in:
parent
7f73decc41
commit
07d7dfffcb
8 changed files with 76 additions and 2 deletions
|
@ -8,6 +8,7 @@
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
|
|
||||||
#include "Icons.h"
|
#include "Icons.h"
|
||||||
|
#include "utils/WebsocketNotifier.h"
|
||||||
|
|
||||||
Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
||||||
: QDialog(parent)
|
: QDialog(parent)
|
||||||
|
@ -43,6 +44,14 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
||||||
connect(ui->spinBox_inactivityLockTimeout, QOverload<int>::of(&QSpinBox::valueChanged), [](int value){
|
connect(ui->spinBox_inactivityLockTimeout, QOverload<int>::of(&QSpinBox::valueChanged), [](int value){
|
||||||
config()->set(Config::inactivityLockTimeout, value);
|
config()->set(Config::inactivityLockTimeout, value);
|
||||||
});
|
});
|
||||||
|
connect(ui->checkBox_disableWebsocket, &QCheckBox::toggled, [this](bool toggled){
|
||||||
|
config()->set(Config::disableWebsocket, toggled);
|
||||||
|
if (toggled) {
|
||||||
|
websocketNotifier()->websocketClient.stop();
|
||||||
|
} else {
|
||||||
|
websocketNotifier()->websocketClient.restart();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
connect(ui->closeButton, &QDialogButtonBox::accepted, this, &Settings::close);
|
connect(ui->closeButton, &QDialogButtonBox::accepted, this, &Settings::close);
|
||||||
|
|
||||||
|
@ -58,6 +67,7 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
||||||
ui->checkBox_disableLogging->setChecked(config()->get(Config::disableLogging).toBool());
|
ui->checkBox_disableLogging->setChecked(config()->get(Config::disableLogging).toBool());
|
||||||
ui->checkBox_inactivityLockTimeout->setChecked(config()->get(Config::inactivityLockEnabled).toBool());
|
ui->checkBox_inactivityLockTimeout->setChecked(config()->get(Config::inactivityLockEnabled).toBool());
|
||||||
ui->spinBox_inactivityLockTimeout->setValue(config()->get(Config::inactivityLockTimeout).toInt());
|
ui->spinBox_inactivityLockTimeout->setValue(config()->get(Config::inactivityLockTimeout).toInt());
|
||||||
|
ui->checkBox_disableWebsocket->setChecked(config()->get(Config::disableWebsocket).toBool());
|
||||||
|
|
||||||
// setup comboboxes
|
// setup comboboxes
|
||||||
this->setupSkinCombobox();
|
this->setupSkinCombobox();
|
||||||
|
|
|
@ -261,6 +261,43 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_10">
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBox_disableWebsocket">
|
||||||
|
<property name="text">
|
||||||
|
<string>Disable websocket</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="btn_disableWebsocket">
|
||||||
|
<property name="sizePolicy">
|
||||||
|
<sizepolicy hsizetype="Maximum" vsizetype="Fixed">
|
||||||
|
<horstretch>0</horstretch>
|
||||||
|
<verstretch>0</verstretch>
|
||||||
|
</sizepolicy>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>?</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer_5">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>40</width>
|
||||||
|
<height>20</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<widget class="QCheckBox" name="checkBox_disableLogging">
|
<widget class="QCheckBox" name="checkBox_disableLogging">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
|
|
|
@ -522,6 +522,10 @@ void WindowManager::onTorSettingsChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::initWS() {
|
void WindowManager::initWS() {
|
||||||
|
if (config()->get(Config::disableWebsocket).toBool()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
websocketNotifier()->websocketClient.start();
|
websocketNotifier()->websocketClient.start();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -57,7 +57,11 @@ void DebugInfoDialog::updateInfo() {
|
||||||
auto node = m_ctx->nodes->connection();
|
auto node = m_ctx->nodes->connection();
|
||||||
ui->label_remoteNode->setText(node.toAddress());
|
ui->label_remoteNode->setText(node.toAddress());
|
||||||
ui->label_walletStatus->setText(this->statusToString(m_ctx->wallet->connectionStatus()));
|
ui->label_walletStatus->setText(this->statusToString(m_ctx->wallet->connectionStatus()));
|
||||||
ui->label_websocketStatus->setText(Utils::QtEnumToString(websocketNotifier()->websocketClient.webSocket.state()).remove("State"));
|
QString websocketStatus = Utils::QtEnumToString(websocketNotifier()->websocketClient.webSocket.state()).remove("State");
|
||||||
|
if (config()->get(Config::disableWebsocket).toBool()) {
|
||||||
|
websocketStatus = "Disabled";
|
||||||
|
}
|
||||||
|
ui->label_websocketStatus->setText(websocketStatus);
|
||||||
ui->label_torStatus->setText(torStatus);
|
ui->label_torStatus->setText(torStatus);
|
||||||
ui->label_torLevel->setText(config()->get(Config::torPrivacyLevel).toString());
|
ui->label_torLevel->setText(config()->get(Config::torPrivacyLevel).toString());
|
||||||
|
|
||||||
|
|
|
@ -38,15 +38,29 @@ void WebsocketClient::sendMsg(const QByteArray &data) {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WebsocketClient::start() {
|
void WebsocketClient::start() {
|
||||||
|
if (m_stopped) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// connect & reconnect on errors/close
|
// connect & reconnect on errors/close
|
||||||
qDebug() << "WebSocket connect:" << m_url.url();
|
qDebug() << "WebSocket connect:" << m_url.url();
|
||||||
|
|
||||||
auto state = webSocket.state();
|
auto state = webSocket.state();
|
||||||
if (state != QAbstractSocket::ConnectedState && state != QAbstractSocket::ConnectingState) {
|
if (state != QAbstractSocket::ConnectedState && state != QAbstractSocket::ConnectingState) {
|
||||||
webSocket.open(m_url);
|
webSocket.open(m_url);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void WebsocketClient::restart() {
|
||||||
|
m_stopped = false;
|
||||||
|
this->start();
|
||||||
|
}
|
||||||
|
|
||||||
|
void WebsocketClient::stop() {
|
||||||
|
m_stopped = true;
|
||||||
|
webSocket.close();
|
||||||
|
m_connectionTimeout.stop();
|
||||||
|
}
|
||||||
|
|
||||||
void WebsocketClient::onConnected() {
|
void WebsocketClient::onConnected() {
|
||||||
qDebug() << "WebSocket connected";
|
qDebug() << "WebSocket connected";
|
||||||
emit connectionEstablished();
|
emit connectionEstablished();
|
||||||
|
|
|
@ -16,6 +16,8 @@ class WebsocketClient : public QObject {
|
||||||
public:
|
public:
|
||||||
explicit WebsocketClient(QObject *parent = nullptr);
|
explicit WebsocketClient(QObject *parent = nullptr);
|
||||||
void start();
|
void start();
|
||||||
|
void restart();
|
||||||
|
void stop();
|
||||||
void sendMsg(const QByteArray &data);
|
void sendMsg(const QByteArray &data);
|
||||||
|
|
||||||
QWebSocket webSocket;
|
QWebSocket webSocket;
|
||||||
|
@ -39,6 +41,7 @@ private:
|
||||||
QTimer m_connectionTimeout;
|
QTimer m_connectionTimeout;
|
||||||
int m_timeout = 10;
|
int m_timeout = 10;
|
||||||
int m_websocketUrlIndex = 0;
|
int m_websocketUrlIndex = 0;
|
||||||
|
bool m_stopped = false;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif //FEATHER_WEBSOCKETCLIENT_H
|
#endif //FEATHER_WEBSOCKETCLIENT_H
|
||||||
|
|
|
@ -67,6 +67,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
|
||||||
{Config::balanceDisplay, {QS("balanceDisplay"), Config::BalanceDisplay::spendablePlusUnconfirmed}},
|
{Config::balanceDisplay, {QS("balanceDisplay"), Config::BalanceDisplay::spendablePlusUnconfirmed}},
|
||||||
{Config::inactivityLockEnabled, {QS("inactivityLockEnabled"), false}},
|
{Config::inactivityLockEnabled, {QS("inactivityLockEnabled"), false}},
|
||||||
{Config::inactivityLockTimeout, {QS("inactivityLockTimeout"), 10}},
|
{Config::inactivityLockTimeout, {QS("inactivityLockTimeout"), 10}},
|
||||||
|
{Config::disableWebsocket, {QS("disableWebsocket"), false}},
|
||||||
|
|
||||||
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
|
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
|
||||||
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},
|
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},
|
||||||
|
|
|
@ -71,6 +71,7 @@ public:
|
||||||
balanceDisplay,
|
balanceDisplay,
|
||||||
inactivityLockEnabled,
|
inactivityLockEnabled,
|
||||||
inactivityLockTimeout,
|
inactivityLockTimeout,
|
||||||
|
disableWebsocket,
|
||||||
|
|
||||||
multiBroadcast,
|
multiBroadcast,
|
||||||
warnOnExternalLink,
|
warnOnExternalLink,
|
||||||
|
|
Loading…
Reference in a new issue