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