]> Nutra Git (v1) - gamesguru/feather.git/commitdiff
Settings: allow disabling websocket
authortobtoht <thotbot@protonmail.com>
Fri, 4 Mar 2022 21:55:29 +0000 (22:55 +0100)
committertobtoht <thotbot@protonmail.com>
Fri, 4 Mar 2022 21:55:29 +0000 (22:55 +0100)
src/SettingsDialog.cpp
src/SettingsDialog.ui
src/WindowManager.cpp
src/dialog/DebugInfoDialog.cpp
src/utils/WebsocketClient.cpp
src/utils/WebsocketClient.h
src/utils/config.cpp
src/utils/config.h

index d8153b089d886a0fc72d20fbe5fe2b0fb238452a..d8c77f90b9488455d7c383c7f067601277cb9211 100644 (file)
@@ -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();
index 75385eb887f23645b4ebb038861757aaedc437a5..6eb3635f31b446a3e5ae9586ab363670e7886fb6 100644 (file)
          </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">
index 47f1866c2a6837a5fcd34d96ed7cc26eaaf79e9c..437695a49542e2084647aab5bde2d3d39572e40a 100644 (file)
@@ -522,6 +522,10 @@ void WindowManager::onTorSettingsChanged() {
 }
 
 void WindowManager::initWS() {
+    if (config()->get(Config::disableWebsocket).toBool()) {
+        return;
+    }
+
     websocketNotifier()->websocketClient.start();
 }
 
index bdc957cba0a0818faed16e1494fc622092756768..2b071b20f003ec84c834779167969b342224616f 100644 (file)
@@ -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());
 
index ff915e3f36ebd65e0f9d928b155d41104c0bc627..948954a44fd9b40e93461e3bc7d9b3242456579a 100644 (file)
@@ -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();
index d2479a34d8b5470067ff3f6769c2758091880b41..ca53be602377845458658c2b73741c525de0a8e6 100644 (file)
@@ -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
index 5157ee9396b37126731c26e83bfd2791e84bf9b5..3026592fea1373aa4de97df7c306b509bab409ef 100644 (file)
@@ -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}},
index 7c2a360163e87afba9e857e18f4edaf6c665ebf7..63271751346f86fe16e7321b746b873db9ba9f85 100644 (file)
@@ -71,6 +71,7 @@ public:
         balanceDisplay,
         inactivityLockEnabled,
         inactivityLockTimeout,
+        disableWebsocket,
 
         multiBroadcast,
         warnOnExternalLink,