+void Core::initAsync()
+{
+ try {
+ init();
+ }
+ catch (ExitException e) {
+ emit exitRequested(e.exitCode, e.errorString);
+ }
+}
+
+void Core::shutdown()
+{
+ qInfo() << "Core shutting down...";
+
+ saveState();
+
+ for (auto&& client : _connectingClients) {
+ client->deleteLater();
+ }
+ _connectingClients.clear();
+
+ if (_sessions.isEmpty()) {
+ emit shutdownComplete();
+ return;
+ }
+
+ for (auto&& session : _sessions) {
+ connect(session, &SessionThread::shutdownComplete, this, &Core::onSessionShutdown);
+ session->shutdown();
+ }
+}
+
+void Core::onSessionShutdown(SessionThread* session)
+{
+ _sessions.take(_sessions.key(session))->deleteLater();
+ if (_sessions.isEmpty()) {
+ qInfo() << "Core shutdown complete!";
+ emit shutdownComplete();
+ }