diff --git a/tray/gui/traywidget.cpp b/tray/gui/traywidget.cpp index 4b58695..53f197e 100644 --- a/tray/gui/traywidget.cpp +++ b/tray/gui/traywidget.cpp @@ -381,7 +381,7 @@ void TrayWidget::applySettings(const QString &connectionConfig) // apply systemd and launcher settings enforcing a reconnect if required and possible #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD const auto systemdStatus = applySystemdSettings(reconnectRequired); - const auto launcherStatus = applyLauncherSettings(reconnectRequired, systemdStatus.relevant, systemdStatus.showStartStopButton); + const auto launcherStatus = applyLauncherSettings(reconnectRequired, systemdStatus.consideredForReconnect, systemdStatus.showStartStopButton); const auto showStartStopButton = systemdStatus.showStartStopButton || launcherStatus.showStartStopButton; const auto systemdOrLauncherRelevantForReconnect = systemdStatus.relevant || launcherStatus.relevant; #else @@ -574,7 +574,7 @@ Settings::Launcher::LauncherStatus TrayWidget::handleLauncherStatusChanged() { #ifdef LIB_SYNCTHING_CONNECTOR_SUPPORT_SYSTEMD const auto systemdStatus = Settings::values().systemd.status(m_connection); - const auto launcherStatus = applyLauncherSettings(false, systemdStatus.relevant, systemdStatus.showStartStopButton); + const auto launcherStatus = applyLauncherSettings(false, systemdStatus.consideredForReconnect, systemdStatus.showStartStopButton); const auto showStartStopButton = systemdStatus.showStartStopButton || launcherStatus.showStartStopButton; #else const auto launcherStatus = applyLauncherSettings(false); diff --git a/widgets/settings/settings.cpp b/widgets/settings/settings.cpp index 5406f84..4e3c9df 100644 --- a/widgets/settings/settings.cpp +++ b/widgets/settings/settings.cpp @@ -44,6 +44,13 @@ template <> struct hash { namespace Settings { +/*! + * \brief The minimum number of seconds the Syncthing service should be active before we try to connect. + * + * Because the REST-API is not instantly available after startup and we want to prevent connection errors. + */ +constexpr auto minActiveTimeInSeconds = 5; + /*! * \brief Contains the processes for launching extra tools. * \remarks Using std::unordered_map instead of QHash because SyncthingProcess can not be copied. @@ -123,12 +130,20 @@ Launcher::LauncherStatus Launcher::apply( // connect instantly if service is running if (consideredForReconnect) { - // give the service (which has just started) a few seconds to initialize - constexpr auto minActiveTimeInSeconds(5); if (reconnectRequired) { - connection.reconnectLater(minActiveTimeInSeconds * 1000); + if (launcher->isActiveFor(minActiveTimeInSeconds)) { + connection.reconnect(); + } else { + // give the service (which has just started) a few seconds to initialize + connection.reconnectLater(minActiveTimeInSeconds * 1000); + } } else if (isRunning && !connection.isConnected()) { - connection.connectLater(minActiveTimeInSeconds * 1000); + if (launcher->isActiveFor(minActiveTimeInSeconds)) { + connection.connect(); + } else { + // give the service (which has just started) a few seconds to initialize + connection.connectLater(minActiveTimeInSeconds * 1000); + } } } @@ -419,7 +434,6 @@ Systemd::ServiceStatus Systemd::apply( // connect instantly if service is running if (consideredForReconnect) { - constexpr auto minActiveTimeInSeconds(5); if (reconnectRequired) { if (service->isActiveWithoutSleepFor(minActiveTimeInSeconds)) { connection.reconnect();