From 7170b48589c88eaa33263ffb0155dbf384b82d56 Mon Sep 17 00:00:00 2001 From: "anthony.bilinski" Date: Fri, 13 Oct 2017 15:22:24 -0700 Subject: [PATCH] fix(init): register AV connects and call after AV is ready Fixes #4651 --- src/core/core.cpp | 8 ++++++++ src/core/core.h | 2 ++ src/widget/widget.cpp | 3 +-- 3 files changed, 11 insertions(+), 2 deletions(-) diff --git a/src/core/core.cpp b/src/core/core.cpp index 501fec762..c7aaf9881 100644 --- a/src/core/core.cpp +++ b/src/core/core.cpp @@ -248,6 +248,10 @@ void Core::makeAv() qCritical() << "Toxav core failed to start"; emit failedToStart(); } + for (const auto& callback : toCallWhenAvReady) { + callback(av); + } + toCallWhenAvReady.clear(); } /** @@ -1371,6 +1375,10 @@ bool Core::isReady() const return av && av->getToxAv() && tox && ready; } +void Core::callWhenAvReady(std::function&& toCall) +{ + toCallWhenAvReady.emplace_back(std::move(toCall)); +} /** * @brief Sets the NoSpam value to prevent friend request spam diff --git a/src/core/core.h b/src/core/core.h index a32d71031..ec7b381e1 100644 --- a/src/core/core.h +++ b/src/core/core.h @@ -73,6 +73,7 @@ public: QPair getKeypair() const; bool isReady() const; + void callWhenAvReady(std::function&& toCall); void sendFile(uint32_t friendId, QString filename, QString filePath, long long filesize); @@ -226,6 +227,7 @@ private: QMutex messageSendMutex; bool ready; const ICoreSettings* const s; + std::vector> toCallWhenAvReady; static QThread* coreThread; diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 915bed760..fc6aff675 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -242,9 +242,8 @@ void Widget::init() connect(profile, &Profile::selfAvatarChanged, profileForm, &ProfileForm::onSelfAvatarLoaded); const Settings& s = Settings::getInstance(); - CoreAV* av = core->getAv(); - connect(av, &CoreAV::avEnd, this, &Widget::onCallEnd); + core->callWhenAvReady([this](CoreAV* av){connect(av, &CoreAV::avEnd, this, &Widget::onCallEnd);}); connect(core, &Core::fileDownloadFinished, filesForm, &FilesForm::onFileDownloadComplete); connect(core, &Core::fileUploadFinished, filesForm, &FilesForm::onFileUploadComplete); connect(ui->addButton, &QPushButton::clicked, this, &Widget::onAddClicked);