- Core *core = Core::instance();
- CoreConnection *connection = Client::coreConnection();
- connect(connection, SIGNAL(connectToInternalCore(SignalProxy *)), core, SLOT(setupInternalClientSession(SignalProxy *)));
- connect(core, SIGNAL(sessionState(const QVariant &)), connection, SLOT(internalSessionStateReceived(const QVariant &)));
+
+ // 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(init()));
+ 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)));
+
+ _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);