Add option to connect automatically on startup
This commit is contained in:
parent
287ec5542b
commit
309ff054a0
|
@ -22,6 +22,7 @@ struct LIB_SYNCTHING_CONNECTOR_EXPORT SyncthingConnectionSettings {
|
||||||
int reconnectInterval = defaultReconnectInterval;
|
int reconnectInterval = defaultReconnectInterval;
|
||||||
QString httpsCertPath;
|
QString httpsCertPath;
|
||||||
QList<QSslError> expectedSslErrors;
|
QList<QSslError> expectedSslErrors;
|
||||||
|
bool autoConnect = false;
|
||||||
bool loadHttpsCert();
|
bool loadHttpsCert();
|
||||||
|
|
||||||
static constexpr int defaultTrafficPollInterval = 5000;
|
static constexpr int defaultTrafficPollInterval = 5000;
|
||||||
|
|
|
@ -428,21 +428,21 @@
|
||||||
</item>
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</item>
|
</item>
|
||||||
<item row="14" column="0">
|
<item row="15" column="0">
|
||||||
<widget class="QLabel" name="statusTextLabel">
|
<widget class="QLabel" name="statusTextLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Status</string>
|
<string>Status</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="14" column="1">
|
<item row="15" column="1">
|
||||||
<widget class="QLabel" name="statusLabel">
|
<widget class="QLabel" name="statusLabel">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>disconnected</string>
|
<string>disconnected</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
<item row="17" column="1">
|
<item row="18" column="1">
|
||||||
<widget class="QPushButton" name="connectPushButton">
|
<widget class="QPushButton" name="connectPushButton">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Apply connection settings and try to reconnect with the currently selected config</string>
|
<string>Apply connection settings and try to reconnect with the currently selected config</string>
|
||||||
|
@ -453,6 +453,16 @@
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item row="14" column="1">
|
||||||
|
<widget class="QCheckBox" name="autoConnectCheckBox">
|
||||||
|
<property name="toolTip">
|
||||||
|
<string>Whether to connect automatically on startup. This setting might be overruled by systemd and launcher settings.</string>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Connect automatically on startup</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<customwidgets>
|
<customwidgets>
|
||||||
|
|
|
@ -136,8 +136,15 @@ Launcher::LauncherStatus Launcher::apply(
|
||||||
const auto consideredForReconnect = considerForReconnect && isRelevant;
|
const auto consideredForReconnect = considerForReconnect && isRelevant;
|
||||||
|
|
||||||
if (currentConnectionSettings && (!considerForReconnect || !isRelevant || isRunning)) {
|
if (currentConnectionSettings && (!considerForReconnect || !isRelevant || isRunning)) {
|
||||||
// ensure auto-reconnect is configured according to settings
|
// ensure auto-reconnect is configured according to settings and connect if auto-connect is configured
|
||||||
connection.setAutoReconnectInterval(currentConnectionSettings->reconnectInterval);
|
connection.setAutoReconnectInterval(currentConnectionSettings->reconnectInterval);
|
||||||
|
if (currentConnectionSettings->autoConnect) {
|
||||||
|
if (reconnectRequired) {
|
||||||
|
connection.reconnect();
|
||||||
|
} else {
|
||||||
|
connection.connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// disable auto-reconnect regardless of the overall settings
|
// disable auto-reconnect regardless of the overall settings
|
||||||
connection.setAutoReconnectInterval(0);
|
connection.setAutoReconnectInterval(0);
|
||||||
|
@ -227,6 +234,8 @@ void restore()
|
||||||
= settings.value(QStringLiteral("errorsPollInterval"), connectionSettings->errorsPollInterval).toInt();
|
= settings.value(QStringLiteral("errorsPollInterval"), connectionSettings->errorsPollInterval).toInt();
|
||||||
connectionSettings->reconnectInterval
|
connectionSettings->reconnectInterval
|
||||||
= settings.value(QStringLiteral("reconnectInterval"), connectionSettings->reconnectInterval).toInt();
|
= settings.value(QStringLiteral("reconnectInterval"), connectionSettings->reconnectInterval).toInt();
|
||||||
|
connectionSettings->autoConnect
|
||||||
|
= settings.value(QStringLiteral("autoConnect"), connectionSettings->autoConnect).toBool();
|
||||||
connectionSettings->httpsCertPath = settings.value(QStringLiteral("httpsCertPath")).toString();
|
connectionSettings->httpsCertPath = settings.value(QStringLiteral("httpsCertPath")).toString();
|
||||||
if (!connectionSettings->loadHttpsCert()) {
|
if (!connectionSettings->loadHttpsCert()) {
|
||||||
QMessageBox::critical(nullptr, QCoreApplication::applicationName(),
|
QMessageBox::critical(nullptr, QCoreApplication::applicationName(),
|
||||||
|
@ -336,6 +345,7 @@ void save()
|
||||||
settings.setValue(QStringLiteral("devStatsPollInterval"), connectionSettings->devStatsPollInterval);
|
settings.setValue(QStringLiteral("devStatsPollInterval"), connectionSettings->devStatsPollInterval);
|
||||||
settings.setValue(QStringLiteral("errorsPollInterval"), connectionSettings->errorsPollInterval);
|
settings.setValue(QStringLiteral("errorsPollInterval"), connectionSettings->errorsPollInterval);
|
||||||
settings.setValue(QStringLiteral("reconnectInterval"), connectionSettings->reconnectInterval);
|
settings.setValue(QStringLiteral("reconnectInterval"), connectionSettings->reconnectInterval);
|
||||||
|
settings.setValue(QStringLiteral("autoConnect"), connectionSettings->autoConnect);
|
||||||
settings.setValue(QStringLiteral("httpsCertPath"), connectionSettings->httpsCertPath);
|
settings.setValue(QStringLiteral("httpsCertPath"), connectionSettings->httpsCertPath);
|
||||||
}
|
}
|
||||||
settings.endArray();
|
settings.endArray();
|
||||||
|
@ -468,8 +478,15 @@ Systemd::ServiceStatus Systemd::apply(
|
||||||
const auto consideredForReconnect = considerForReconnect && isRelevant && unitAvailable;
|
const auto consideredForReconnect = considerForReconnect && isRelevant && unitAvailable;
|
||||||
|
|
||||||
if (currentConnectionSettings && (!considerForReconnect || !isRelevant || isRunning)) {
|
if (currentConnectionSettings && (!considerForReconnect || !isRelevant || isRunning)) {
|
||||||
// ensure auto-reconnect is configured according to settings
|
// ensure auto-reconnect is configured according to settings and connect if auto-connect is configured
|
||||||
connection.setAutoReconnectInterval(currentConnectionSettings->reconnectInterval);
|
connection.setAutoReconnectInterval(currentConnectionSettings->reconnectInterval);
|
||||||
|
if (currentConnectionSettings->autoConnect) {
|
||||||
|
if (reconnectRequired) {
|
||||||
|
connection.reconnect();
|
||||||
|
} else {
|
||||||
|
connection.connect();
|
||||||
|
}
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
// disable auto-reconnect regardless of the overall settings
|
// disable auto-reconnect regardless of the overall settings
|
||||||
connection.setAutoReconnectInterval(0);
|
connection.setAutoReconnectInterval(0);
|
||||||
|
|
|
@ -176,6 +176,7 @@ bool ConnectionOptionPage::showConnectionSettings(int index)
|
||||||
ui()->pollDevStatsSpinBox->setValue(connectionSettings.devStatsPollInterval);
|
ui()->pollDevStatsSpinBox->setValue(connectionSettings.devStatsPollInterval);
|
||||||
ui()->pollErrorsSpinBox->setValue(connectionSettings.errorsPollInterval);
|
ui()->pollErrorsSpinBox->setValue(connectionSettings.errorsPollInterval);
|
||||||
ui()->reconnectSpinBox->setValue(connectionSettings.reconnectInterval);
|
ui()->reconnectSpinBox->setValue(connectionSettings.reconnectInterval);
|
||||||
|
ui()->autoConnectCheckBox->setChecked(connectionSettings.autoConnect);
|
||||||
setCurrentIndex(index);
|
setCurrentIndex(index);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
@ -199,6 +200,7 @@ bool ConnectionOptionPage::cacheCurrentSettings(bool applying)
|
||||||
connectionSettings.devStatsPollInterval = ui()->pollDevStatsSpinBox->value();
|
connectionSettings.devStatsPollInterval = ui()->pollDevStatsSpinBox->value();
|
||||||
connectionSettings.errorsPollInterval = ui()->pollErrorsSpinBox->value();
|
connectionSettings.errorsPollInterval = ui()->pollErrorsSpinBox->value();
|
||||||
connectionSettings.reconnectInterval = ui()->reconnectSpinBox->value();
|
connectionSettings.reconnectInterval = ui()->reconnectSpinBox->value();
|
||||||
|
connectionSettings.autoConnect = ui()->autoConnectCheckBox->isChecked();
|
||||||
if (!connectionSettings.loadHttpsCert()) {
|
if (!connectionSettings.loadHttpsCert()) {
|
||||||
const QString errorMessage = QCoreApplication::translate("QtGui::ConnectionOptionPage", "Unable to load specified certificate \"%1\".")
|
const QString errorMessage = QCoreApplication::translate("QtGui::ConnectionOptionPage", "Unable to load specified certificate \"%1\".")
|
||||||
.arg(connectionSettings.httpsCertPath);
|
.arg(connectionSettings.httpsCertPath);
|
||||||
|
|
Loading…
Reference in New Issue