Stop built-in Syncthing instance synchronously
So `Launcher::terminate()` exits when really everything has terminated and not just sub processes. It may nevertheless be worthwhile to implement a timeout. This may help with https://github.com/Martchus/syncthingtray/issues/180#issuecomment-1582465960.
This commit is contained in:
parent
72f54316a7
commit
091ec35580
|
@ -176,6 +176,12 @@ void SyncthingLauncher::kill()
|
|||
}
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stops the built-in Syncthing instance.
|
||||
* \remarks
|
||||
* - Does nothing if Syncthing is starting or stopping or has already been stopped or never been started.
|
||||
* - Returns immediately. The stopping is performed asynchronously.
|
||||
*/
|
||||
void SyncthingLauncher::tearDownLibSyncthing()
|
||||
{
|
||||
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||
|
@ -187,6 +193,20 @@ void SyncthingLauncher::tearDownLibSyncthing()
|
|||
#endif
|
||||
}
|
||||
|
||||
/*!
|
||||
* \brief Stops the built-in Syncthing instance.
|
||||
* \remarks
|
||||
* - Does nothing if Syncthing has already been stopped or never been started.
|
||||
* - Blocks the current thread until Syncthing has been stopped.
|
||||
*/
|
||||
void SyncthingLauncher::stopLibSyncthing()
|
||||
{
|
||||
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||
LibSyncthing::stopSyncthing();
|
||||
// no need to emit exited/runningChanged here; that is already done in runLibSyncthing()
|
||||
#endif
|
||||
}
|
||||
|
||||
void SyncthingLauncher::handleProcessReadyRead()
|
||||
{
|
||||
handleOutputAvailable(m_process.readAll());
|
||||
|
@ -270,13 +290,6 @@ void SyncthingLauncher::runLibSyncthing(const LibSyncthing::RuntimeOptions &runt
|
|||
emit exited(static_cast<int>(exitCode), exitCode == 0 ? QProcess::NormalExit : QProcess::CrashExit);
|
||||
emit runningChanged(false);
|
||||
}
|
||||
|
||||
void SyncthingLauncher::stopLibSyncthing()
|
||||
{
|
||||
LibSyncthing::stopSyncthing();
|
||||
// no need to emit exited/runningChanged here; that is already done in runLibSyncthing()
|
||||
}
|
||||
|
||||
#else
|
||||
void SyncthingLauncher::showLibSyncthingNotSupported()
|
||||
{
|
||||
|
|
|
@ -71,6 +71,7 @@ public Q_SLOTS:
|
|||
void terminate(Data::SyncthingConnection *relevantConnection = nullptr);
|
||||
void kill();
|
||||
void tearDownLibSyncthing();
|
||||
void stopLibSyncthing();
|
||||
|
||||
private Q_SLOTS:
|
||||
void handleProcessReadyRead();
|
||||
|
@ -78,7 +79,6 @@ private Q_SLOTS:
|
|||
void handleProcessFinished(int exitCode, QProcess::ExitStatus exitStatus);
|
||||
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||
void runLibSyncthing(const LibSyncthing::RuntimeOptions &runtimeOptions);
|
||||
void stopLibSyncthing();
|
||||
#else
|
||||
void showLibSyncthingNotSupported();
|
||||
#endif
|
||||
|
|
|
@ -154,11 +154,19 @@ void Launcher::autostart() const
|
|||
*/
|
||||
void Launcher::terminate()
|
||||
{
|
||||
// trigger termination of all pending processes
|
||||
// note: This covers the process launched via SyncthingLauncher and additional tool processes. It does *not* cover
|
||||
// the built-in Syncthing instance.
|
||||
auto killer = QtGui::SyncthingKiller(allProcesses());
|
||||
// stop the built-in Syncthing instance and wait until it has terminated
|
||||
#ifdef SYNCTHINGWIDGETS_USE_LIBSYNCTHING
|
||||
auto *const launcher = SyncthingLauncher::mainInstance();
|
||||
if (launcher) {
|
||||
launcher->tearDownLibSyncthing();
|
||||
launcher->stopLibSyncthing();
|
||||
}
|
||||
QtGui::SyncthingKiller(allProcesses()).waitForFinished();
|
||||
#endif
|
||||
// wait until all pending processes have terminated, possibly ask user to kill a process if it does not react
|
||||
killer.waitForFinished();
|
||||
}
|
||||
|
||||
static bool isActiveFor(const SyncthingLauncher &launcher, unsigned int atLeastSeconds)
|
||||
|
|
Loading…
Reference in New Issue