- Core *core = Core::instance();
- CoreConnection *connection = Client::coreConnection();
- connect(connection, SIGNAL(connectToInternalCore(InternalPeer*)), core, SLOT(setupInternalClientSession(InternalPeer*)));
- connect(core, SIGNAL(sessionState(Protocol::SessionState)), connection, SLOT(internalSessionStateReceived(Protocol::SessionState)));
+
+ // Start internal core in a separate thread, so it doesn't block the UI
+ _core = new Core{};
+ _core->moveToThread(&_coreThread);
+ connect(&_coreThread, SIGNAL(started()), _core, SLOT(initAsync()));
+ connect(&_coreThread, SIGNAL(finished()), _core, SLOT(deleteLater()));
+
+ connect(this, SIGNAL(connectInternalPeer(QPointer<InternalPeer>)), _core, SLOT(connectInternalPeer(QPointer<InternalPeer>)));
+ connect(_core, SIGNAL(sessionState(Protocol::SessionState)), Client::coreConnection(), SLOT(internalSessionStateReceived(Protocol::SessionState)));
+
+ connect(_core, SIGNAL(dbUpgradeInProgress(bool)), Client::instance(), SLOT(onDbUpgradeInProgress(bool)));
+ connect(_core, SIGNAL(exitRequested(int,QString)), Client::instance(), SLOT(onExitRequested(int,QString)));
+
+ _coreThread.start();
+}
+
+
+void MonolithicApplication::onConnectionRequest(QPointer<InternalPeer> peer)
+{
+ if (!_core) {
+ startInternalCore();
+ }
+
+ // While starting the core may take a while, the object itself is instantiated synchronously and the connections
+ // established, so it's safe to emit this immediately. The core will take care of queueing the request until
+ // initialization is complete.
+ emit connectInternalPeer(peer);