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 "Icons.h"
|
||||
#include "utils/WebsocketNotifier.h"
|
||||
|
||||
Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *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){
|
||||
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);
|
||||
|
||||
|
@ -58,6 +67,7 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
|||
ui->checkBox_disableLogging->setChecked(config()->get(Config::disableLogging).toBool());
|
||||
ui->checkBox_inactivityLockTimeout->setChecked(config()->get(Config::inactivityLockEnabled).toBool());
|
||||
ui->spinBox_inactivityLockTimeout->setValue(config()->get(Config::inactivityLockTimeout).toInt());
|
||||
ui->checkBox_disableWebsocket->setChecked(config()->get(Config::disableWebsocket).toBool());
|
||||
|
||||
// setup comboboxes
|
||||
this->setupSkinCombobox();
|
||||
|
|
|
@ -261,6 +261,43 @@
|
|||
</property>
|
||||
</widget>
|
||||
</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>
|
||||
<widget class="QCheckBox" name="checkBox_disableLogging">
|
||||
<property name="text">
|
||||
|
|
|
@ -522,6 +522,10 @@ void WindowManager::onTorSettingsChanged() {
|
|||
}
|
||||
|
||||
void WindowManager::initWS() {
|
||||
if (config()->get(Config::disableWebsocket).toBool()) {
|
||||
return;
|
||||
}
|
||||
|
||||
websocketNotifier()->websocketClient.start();
|
||||
}
|
||||
|
||||
|
|
|
@ -57,7 +57,11 @@ void DebugInfoDialog::updateInfo() {
|
|||
auto node = m_ctx->nodes->connection();
|
||||
ui->label_remoteNode->setText(node.toAddress());
|
||||
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_torLevel->setText(config()->get(Config::torPrivacyLevel).toString());
|
||||
|
||||
|
|
|
@ -38,15 +38,29 @@ void WebsocketClient::sendMsg(const QByteArray &data) {
|
|||
}
|
||||
|
||||
void WebsocketClient::start() {
|
||||
if (m_stopped) {
|
||||
return;
|
||||
}
|
||||
|
||||
// connect & reconnect on errors/close
|
||||
qDebug() << "WebSocket connect:" << m_url.url();
|
||||
|
||||
auto state = webSocket.state();
|
||||
if (state != QAbstractSocket::ConnectedState && state != QAbstractSocket::ConnectingState) {
|
||||
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() {
|
||||
qDebug() << "WebSocket connected";
|
||||
emit connectionEstablished();
|
||||
|
|
|
@ -16,6 +16,8 @@ class WebsocketClient : public QObject {
|
|||
public:
|
||||
explicit WebsocketClient(QObject *parent = nullptr);
|
||||
void start();
|
||||
void restart();
|
||||
void stop();
|
||||
void sendMsg(const QByteArray &data);
|
||||
|
||||
QWebSocket webSocket;
|
||||
|
@ -39,6 +41,7 @@ private:
|
|||
QTimer m_connectionTimeout;
|
||||
int m_timeout = 10;
|
||||
int m_websocketUrlIndex = 0;
|
||||
bool m_stopped = false;
|
||||
};
|
||||
|
||||
#endif //FEATHER_WEBSOCKETCLIENT_H
|
||||
|
|
|
@ -67,6 +67,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
|
|||
{Config::balanceDisplay, {QS("balanceDisplay"), Config::BalanceDisplay::spendablePlusUnconfirmed}},
|
||||
{Config::inactivityLockEnabled, {QS("inactivityLockEnabled"), false}},
|
||||
{Config::inactivityLockTimeout, {QS("inactivityLockTimeout"), 10}},
|
||||
{Config::disableWebsocket, {QS("disableWebsocket"), false}},
|
||||
|
||||
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
|
||||
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
balanceDisplay,
|
||||
inactivityLockEnabled,
|
||||
inactivityLockTimeout,
|
||||
disableWebsocket,
|
||||
|
||||
multiBroadcast,
|
||||
warnOnExternalLink,
|
||||
|
|
Loading…
Reference in a new issue