Settings: offline mode

This commit is contained in:
tobtoht 2022-03-14 22:36:58 +01:00
parent 87e46fc961
commit 54140df597
No known key found for this signature in database
GPG key ID: 1CADD27F41F45C3C
13 changed files with 71 additions and 15 deletions

View file

@ -451,8 +451,6 @@ void MainWindow::onWalletOpened() {
this->bringToFront();
this->setEnabled(true);
if (!torManager()->torConnected)
this->setStatusText("Starting Tor (may take a while)");
// receive page
m_ctx->wallet->subaddress()->refresh(m_ctx->wallet->currentSubaddressAccount());

View file

@ -9,6 +9,7 @@
#include "Icons.h"
#include "utils/WebsocketNotifier.h"
#include "utils/NetworkManager.h"
Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
: QDialog(parent)
@ -48,13 +49,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->checkBox_disableWebsocket, &QCheckBox::toggled, [this](bool checked){
config()->set(Config::disableWebsocket, checked);
this->enableWebsocket(checked);
});
connect(ui->checkBox_offlineMode, &QCheckBox::toggled, [this](bool checked){
config()->set(Config::offlineMode, checked);
m_ctx->wallet->setOffline(checked);
this->enableWebsocket(checked);
});
connect(ui->closeButton, &QDialogButtonBox::accepted, this, &Settings::close);
@ -72,6 +74,7 @@ Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
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());
ui->checkBox_offlineMode->setChecked(config()->get(Config::offlineMode).toBool());
// setup comboboxes
this->setupSkinCombobox();
@ -226,4 +229,12 @@ void Settings::setupLocalMoneroFrontendCombobox() {
ui->combo_localMoneroFrontend->setCurrentIndex(ui->combo_localMoneroFrontend->findData(config()->get(Config::localMoneroFrontend).toString()));
}
void Settings::enableWebsocket(bool enabled) {
if (enabled && !config()->get(Config::offlineMode).toBool() && !config()->get(Config::disableWebsocket).toBool()) {
websocketNotifier()->websocketClient.restart();
} else {
websocketNotifier()->websocketClient.stop();
}
}
Settings::~Settings() = default;

View file

@ -49,6 +49,7 @@ public slots:
private:
void setupSkinCombobox();
void setupLocalMoneroFrontendCombobox();
void enableWebsocket(bool enabled);
QScopedPointer<Ui::Settings> ui;
QSharedPointer<AppContext> m_ctx;

View file

@ -17,7 +17,7 @@
<item>
<widget class="QTabWidget" name="tabWidget">
<property name="currentIndex">
<number>0</number>
<number>1</number>
</property>
<widget class="QWidget" name="tab_general">
<attribute name="title">
@ -346,6 +346,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBox_offlineMode">
<property name="text">
<string>Offline mode</string>
</property>
</widget>
</item>
<item>
<spacer name="verticalSpacer_4">
<property name="orientation">

View file

@ -489,6 +489,7 @@ void WindowManager::onInitialNetworkConfigured() {
if (!m_initialNetworkConfigured) {
m_initialNetworkConfigured = true;
appData();
this->initTor();
this->initWS();
}
@ -522,6 +523,10 @@ void WindowManager::onTorSettingsChanged() {
}
void WindowManager::initWS() {
if (config()->get(Config::offlineMode).toBool()) {
return;
}
if (config()->get(Config::disableWebsocket).toBool()) {
return;
}

View file

@ -88,7 +88,11 @@ void DebugInfoDialog::updateInfo() {
}
}();
ui->label_netType->setText(Utils::QtEnumToString(m_ctx->wallet->nettype()));
QString networkType = Utils::QtEnumToString(m_ctx->wallet->nettype());
if (config()->get(Config::offlineMode).toBool()) {
networkType += " (offline)";
}
ui->label_netType->setText(networkType);
ui->label_seedType->setText(seedType);
ui->label_deviceType->setText(deviceType);
ui->label_viewOnly->setText(m_ctx->wallet->viewOnly() ? "True" : "False");

View file

@ -148,6 +148,11 @@ bool Wallet::isConnected() const
return status == ConnectionStatus_Synchronizing || status == ConnectionStatus_Synchronized;
}
void Wallet::setOffline(bool offline) const
{
return m_walletImpl->setOffline(offline);
}
QString Wallet::errorString() const
{
return QString::fromStdString(m_walletImpl->errorString());

View file

@ -127,6 +127,8 @@ public:
//! return true if wallet is connected to a node
bool isConnected() const;
void setOffline(bool offline) const;
//! returns last operation's error message
QString errorString() const;

View file

@ -238,7 +238,11 @@ bool xdgDesktopEntryRegister() {
return true;
}
bool portOpen(const QString &hostname, quint16 port){
bool portOpen(const QString &hostname, quint16 port) { // TODO: this call should be async
if (config()->get(Config::offlineMode).toBool()) {
return false;
}
QTcpSocket socket;
socket.connectToHost(hostname, port);
return socket.waitForConnected(600);

View file

@ -69,6 +69,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
{Config::inactivityLockEnabled, {QS("inactivityLockEnabled"), false}},
{Config::inactivityLockTimeout, {QS("inactivityLockTimeout"), 10}},
{Config::disableWebsocket, {QS("disableWebsocket"), false}},
{Config::offlineMode, {QS("offlineMode"), false}},
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},

View file

@ -73,6 +73,7 @@ public:
inactivityLockEnabled,
inactivityLockTimeout,
disableWebsocket,
offlineMode,
multiBroadcast,
warnOnExternalLink,

View file

@ -6,16 +6,21 @@
#include "utils/Utils.h"
#include "utils/networking.h"
#include "config.h"
UtilsNetworking::UtilsNetworking(QNetworkAccessManager *networkAccessManager, QObject *parent) :
QObject(parent),
m_networkAccessManager(networkAccessManager) {}
UtilsNetworking::UtilsNetworking(QNetworkAccessManager *networkAccessManager, QObject *parent)
: QObject(parent)
, m_networkAccessManager(networkAccessManager) {}
void UtilsNetworking::setUserAgent(const QString &userAgent) {
this->m_userAgent = userAgent;
}
QNetworkReply* UtilsNetworking::get(const QString &url) {
if (config()->get(Config::offlineMode).toBool()) {
return nullptr;
}
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
@ -24,6 +29,10 @@ QNetworkReply* UtilsNetworking::get(const QString &url) {
}
QNetworkReply* UtilsNetworking::getJson(const QString &url) {
if (config()->get(Config::offlineMode).toBool()) {
return nullptr;
}
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
@ -33,6 +42,10 @@ QNetworkReply* UtilsNetworking::getJson(const QString &url) {
}
QNetworkReply* UtilsNetworking::postJson(const QString &url, const QJsonObject &data) {
if (config()->get(Config::offlineMode).toBool()) {
return nullptr;
}
QNetworkRequest request;
request.setUrl(QUrl(url));
request.setRawHeader("User-Agent", m_userAgent.toUtf8());

View file

@ -192,6 +192,10 @@ void Nodes::connectToNode(const FeatherNode &node) {
if (!node.isValid())
return;
if (config()->get(Config::offlineMode).toBool()) {
return;
}
emit updateStatus(QString("Connecting to %1").arg(node.toAddress()));
qInfo() << QString("Attempting to connect to %1 (%2)").arg(node.toAddress()).arg(node.custom ? "custom" : "ws");