Improve taking the launcher status into account when connecting
* Take the time the launcher is active into account (in the same way as it is done for the systemd service) * Fix case when systemd service would be relevant but configured to consider the launcher status
This commit is contained in:
parent
4b246d4b4d
commit
fe332078f1
|
@ -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);
|
||||
|
|
|
@ -44,6 +44,13 @@ template <> struct hash<QString> {
|
|||
|
||||
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();
|
||||
|
|
Loading…
Reference in New Issue