mirror of
https://github.com/feather-wallet/feather.git
synced 2024-11-16 17:27:38 +00:00
Settings: offline mode
This commit is contained in:
parent
87e46fc961
commit
54140df597
13 changed files with 71 additions and 15 deletions
|
@ -451,8 +451,6 @@ void MainWindow::onWalletOpened() {
|
||||||
|
|
||||||
this->bringToFront();
|
this->bringToFront();
|
||||||
this->setEnabled(true);
|
this->setEnabled(true);
|
||||||
if (!torManager()->torConnected)
|
|
||||||
this->setStatusText("Starting Tor (may take a while)");
|
|
||||||
|
|
||||||
// receive page
|
// receive page
|
||||||
m_ctx->wallet->subaddress()->refresh(m_ctx->wallet->currentSubaddressAccount());
|
m_ctx->wallet->subaddress()->refresh(m_ctx->wallet->currentSubaddressAccount());
|
||||||
|
|
|
@ -9,6 +9,7 @@
|
||||||
|
|
||||||
#include "Icons.h"
|
#include "Icons.h"
|
||||||
#include "utils/WebsocketNotifier.h"
|
#include "utils/WebsocketNotifier.h"
|
||||||
|
#include "utils/NetworkManager.h"
|
||||||
|
|
||||||
Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
Settings::Settings(QSharedPointer<AppContext> ctx, QWidget *parent)
|
||||||
: QDialog(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){
|
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){
|
connect(ui->checkBox_disableWebsocket, &QCheckBox::toggled, [this](bool checked){
|
||||||
config()->set(Config::disableWebsocket, toggled);
|
config()->set(Config::disableWebsocket, checked);
|
||||||
if (toggled) {
|
this->enableWebsocket(checked);
|
||||||
websocketNotifier()->websocketClient.stop();
|
});
|
||||||
} else {
|
connect(ui->checkBox_offlineMode, &QCheckBox::toggled, [this](bool checked){
|
||||||
websocketNotifier()->websocketClient.restart();
|
config()->set(Config::offlineMode, checked);
|
||||||
}
|
m_ctx->wallet->setOffline(checked);
|
||||||
|
this->enableWebsocket(checked);
|
||||||
});
|
});
|
||||||
|
|
||||||
connect(ui->closeButton, &QDialogButtonBox::accepted, this, &Settings::close);
|
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->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());
|
ui->checkBox_disableWebsocket->setChecked(config()->get(Config::disableWebsocket).toBool());
|
||||||
|
ui->checkBox_offlineMode->setChecked(config()->get(Config::offlineMode).toBool());
|
||||||
|
|
||||||
// setup comboboxes
|
// setup comboboxes
|
||||||
this->setupSkinCombobox();
|
this->setupSkinCombobox();
|
||||||
|
@ -226,4 +229,12 @@ void Settings::setupLocalMoneroFrontendCombobox() {
|
||||||
ui->combo_localMoneroFrontend->setCurrentIndex(ui->combo_localMoneroFrontend->findData(config()->get(Config::localMoneroFrontend).toString()));
|
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;
|
Settings::~Settings() = default;
|
|
@ -49,6 +49,7 @@ public slots:
|
||||||
private:
|
private:
|
||||||
void setupSkinCombobox();
|
void setupSkinCombobox();
|
||||||
void setupLocalMoneroFrontendCombobox();
|
void setupLocalMoneroFrontendCombobox();
|
||||||
|
void enableWebsocket(bool enabled);
|
||||||
|
|
||||||
QScopedPointer<Ui::Settings> ui;
|
QScopedPointer<Ui::Settings> ui;
|
||||||
QSharedPointer<AppContext> m_ctx;
|
QSharedPointer<AppContext> m_ctx;
|
||||||
|
|
|
@ -17,7 +17,7 @@
|
||||||
<item>
|
<item>
|
||||||
<widget class="QTabWidget" name="tabWidget">
|
<widget class="QTabWidget" name="tabWidget">
|
||||||
<property name="currentIndex">
|
<property name="currentIndex">
|
||||||
<number>0</number>
|
<number>1</number>
|
||||||
</property>
|
</property>
|
||||||
<widget class="QWidget" name="tab_general">
|
<widget class="QWidget" name="tab_general">
|
||||||
<attribute name="title">
|
<attribute name="title">
|
||||||
|
@ -346,6 +346,13 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QCheckBox" name="checkBox_offlineMode">
|
||||||
|
<property name="text">
|
||||||
|
<string>Offline mode</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
<item>
|
<item>
|
||||||
<spacer name="verticalSpacer_4">
|
<spacer name="verticalSpacer_4">
|
||||||
<property name="orientation">
|
<property name="orientation">
|
||||||
|
|
|
@ -489,6 +489,7 @@ void WindowManager::onInitialNetworkConfigured() {
|
||||||
if (!m_initialNetworkConfigured) {
|
if (!m_initialNetworkConfigured) {
|
||||||
m_initialNetworkConfigured = true;
|
m_initialNetworkConfigured = true;
|
||||||
appData();
|
appData();
|
||||||
|
|
||||||
this->initTor();
|
this->initTor();
|
||||||
this->initWS();
|
this->initWS();
|
||||||
}
|
}
|
||||||
|
@ -522,6 +523,10 @@ void WindowManager::onTorSettingsChanged() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void WindowManager::initWS() {
|
void WindowManager::initWS() {
|
||||||
|
if (config()->get(Config::offlineMode).toBool()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
if (config()->get(Config::disableWebsocket).toBool()) {
|
if (config()->get(Config::disableWebsocket).toBool()) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
|
@ -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_seedType->setText(seedType);
|
||||||
ui->label_deviceType->setText(deviceType);
|
ui->label_deviceType->setText(deviceType);
|
||||||
ui->label_viewOnly->setText(m_ctx->wallet->viewOnly() ? "True" : "False");
|
ui->label_viewOnly->setText(m_ctx->wallet->viewOnly() ? "True" : "False");
|
||||||
|
|
|
@ -148,6 +148,11 @@ bool Wallet::isConnected() const
|
||||||
return status == ConnectionStatus_Synchronizing || status == ConnectionStatus_Synchronized;
|
return status == ConnectionStatus_Synchronizing || status == ConnectionStatus_Synchronized;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Wallet::setOffline(bool offline) const
|
||||||
|
{
|
||||||
|
return m_walletImpl->setOffline(offline);
|
||||||
|
}
|
||||||
|
|
||||||
QString Wallet::errorString() const
|
QString Wallet::errorString() const
|
||||||
{
|
{
|
||||||
return QString::fromStdString(m_walletImpl->errorString());
|
return QString::fromStdString(m_walletImpl->errorString());
|
||||||
|
|
|
@ -127,6 +127,8 @@ public:
|
||||||
//! return true if wallet is connected to a node
|
//! return true if wallet is connected to a node
|
||||||
bool isConnected() const;
|
bool isConnected() const;
|
||||||
|
|
||||||
|
void setOffline(bool offline) const;
|
||||||
|
|
||||||
//! returns last operation's error message
|
//! returns last operation's error message
|
||||||
QString errorString() const;
|
QString errorString() const;
|
||||||
|
|
||||||
|
|
|
@ -238,7 +238,11 @@ bool xdgDesktopEntryRegister() {
|
||||||
return true;
|
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;
|
QTcpSocket socket;
|
||||||
socket.connectToHost(hostname, port);
|
socket.connectToHost(hostname, port);
|
||||||
return socket.waitForConnected(600);
|
return socket.waitForConnected(600);
|
||||||
|
|
|
@ -69,6 +69,7 @@ static const QHash<Config::ConfigKey, ConfigDirective> configStrings = {
|
||||||
{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::disableWebsocket, {QS("disableWebsocket"), false}},
|
||||||
|
{Config::offlineMode, {QS("offlineMode"), false}},
|
||||||
|
|
||||||
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
|
{Config::multiBroadcast, {QS("multiBroadcast"), true}},
|
||||||
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},
|
{Config::warnOnExternalLink,{QS("warnOnExternalLink"), true}},
|
||||||
|
|
|
@ -73,6 +73,7 @@ public:
|
||||||
inactivityLockEnabled,
|
inactivityLockEnabled,
|
||||||
inactivityLockTimeout,
|
inactivityLockTimeout,
|
||||||
disableWebsocket,
|
disableWebsocket,
|
||||||
|
offlineMode,
|
||||||
|
|
||||||
multiBroadcast,
|
multiBroadcast,
|
||||||
warnOnExternalLink,
|
warnOnExternalLink,
|
||||||
|
|
|
@ -6,16 +6,21 @@
|
||||||
|
|
||||||
#include "utils/Utils.h"
|
#include "utils/Utils.h"
|
||||||
#include "utils/networking.h"
|
#include "utils/networking.h"
|
||||||
|
#include "config.h"
|
||||||
|
|
||||||
UtilsNetworking::UtilsNetworking(QNetworkAccessManager *networkAccessManager, QObject *parent) :
|
UtilsNetworking::UtilsNetworking(QNetworkAccessManager *networkAccessManager, QObject *parent)
|
||||||
QObject(parent),
|
: QObject(parent)
|
||||||
m_networkAccessManager(networkAccessManager) {}
|
, m_networkAccessManager(networkAccessManager) {}
|
||||||
|
|
||||||
void UtilsNetworking::setUserAgent(const QString &userAgent) {
|
void UtilsNetworking::setUserAgent(const QString &userAgent) {
|
||||||
this->m_userAgent = userAgent;
|
this->m_userAgent = userAgent;
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply* UtilsNetworking::get(const QString &url) {
|
QNetworkReply* UtilsNetworking::get(const QString &url) {
|
||||||
|
if (config()->get(Config::offlineMode).toBool()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(QUrl(url));
|
request.setUrl(QUrl(url));
|
||||||
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
|
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
|
||||||
|
@ -24,6 +29,10 @@ QNetworkReply* UtilsNetworking::get(const QString &url) {
|
||||||
}
|
}
|
||||||
|
|
||||||
QNetworkReply* UtilsNetworking::getJson(const QString &url) {
|
QNetworkReply* UtilsNetworking::getJson(const QString &url) {
|
||||||
|
if (config()->get(Config::offlineMode).toBool()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(QUrl(url));
|
request.setUrl(QUrl(url));
|
||||||
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
|
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) {
|
QNetworkReply* UtilsNetworking::postJson(const QString &url, const QJsonObject &data) {
|
||||||
|
if (config()->get(Config::offlineMode).toBool()) {
|
||||||
|
return nullptr;
|
||||||
|
}
|
||||||
|
|
||||||
QNetworkRequest request;
|
QNetworkRequest request;
|
||||||
request.setUrl(QUrl(url));
|
request.setUrl(QUrl(url));
|
||||||
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
|
request.setRawHeader("User-Agent", m_userAgent.toUtf8());
|
||||||
|
|
|
@ -192,6 +192,10 @@ void Nodes::connectToNode(const FeatherNode &node) {
|
||||||
if (!node.isValid())
|
if (!node.isValid())
|
||||||
return;
|
return;
|
||||||
|
|
||||||
|
if (config()->get(Config::offlineMode).toBool()) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
emit updateStatus(QString("Connecting to %1").arg(node.toAddress()));
|
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");
|
qInfo() << QString("Attempting to connect to %1 (%2)").arg(node.toAddress()).arg(node.custom ? "custom" : "ws");
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue