#include <QMessageBox>
#include "Icons.h"
+#include "utils/WebsocketNotifier.h"
Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
: QDialog(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);
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();
</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">
}
void WindowManager::initWS() {
+ if (config()->get(Config::disableWebsocket).toBool()) {
+ return;
+ }
+
websocketNotifier()->websocketClient.start();
}
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());
}
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();
public:
explicit WebsocketClient(QObject *parent = nullptr);
void start();
+ void restart();
+ void stop();
void sendMsg(const QByteArray &data);
QWebSocket webSocket;
QTimer m_connectionTimeout;
int m_timeout = 10;
int m_websocketUrlIndex = 0;
+ bool m_stopped = false;
};
#endif //FEATHER_WEBSOCKETCLIENT_H
{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}},
balanceDisplay,
inactivityLockEnabled,
inactivityLockTimeout,
+ disableWebsocket,
multiBroadcast,
warnOnExternalLink,