Use aboutToQuit() signal for cleanup-code
As recommended by the Qt documentation
This commit is contained in:
parent
cf5faeca51
commit
27f17fc94c
|
@ -117,6 +117,12 @@ void trigger(bool tray, bool webUi)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void shutdownSyncthingTray()
|
||||||
|
{
|
||||||
|
Settings::save();
|
||||||
|
Settings::Launcher::terminate();
|
||||||
|
}
|
||||||
|
|
||||||
int runApplication(int argc, const char *const *argv)
|
int runApplication(int argc, const char *const *argv)
|
||||||
{
|
{
|
||||||
// setup argument parser
|
// setup argument parser
|
||||||
|
@ -173,17 +179,16 @@ int runApplication(int argc, const char *const *argv)
|
||||||
QObject::connect(&service, &SyncthingService::errorOccurred, &handleSystemdServiceError);
|
QObject::connect(&service, &SyncthingService::errorOccurred, &handleSystemdServiceError);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// show (first) tray icon and enter main event loop
|
// init Syncthing Tray and immediately shutdown on failure
|
||||||
auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg.firstValue());
|
if (const auto res = initSyncthingTray(windowedArg.isPresent(), waitForTrayArg.isPresent(), connectionArg.firstValue())) {
|
||||||
if (!res) {
|
shutdownSyncthingTray();
|
||||||
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
return res;
|
||||||
res = application.exec();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// perform cleanup, then terminate
|
// trigger UI and enter event loop
|
||||||
Settings::Launcher::terminate();
|
QObject::connect(&application, &QCoreApplication::aboutToQuit, &shutdownSyncthingTray);
|
||||||
Settings::save();
|
trigger(triggerArg.isPresent(), showWebUiArg.isPresent());
|
||||||
return res;
|
return application.exec();
|
||||||
}
|
}
|
||||||
|
|
||||||
// trigger actions if --webui or --trigger is present but don't create a new tray icon
|
// trigger actions if --webui or --trigger is present but don't create a new tray icon
|
||||||
|
|
Loading…
Reference in New Issue