1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(init): register AV connects and call after AV is ready

Fixes #4651
This commit is contained in:
anthony.bilinski 2017-10-13 15:22:24 -07:00
parent 2f1bf10780
commit 7170b48589
3 changed files with 11 additions and 2 deletions

View File

@ -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<void(CoreAV* av)>&& toCall)
{
toCallWhenAvReady.emplace_back(std::move(toCall));
}
/**
* @brief Sets the NoSpam value to prevent friend request spam

View File

@ -73,6 +73,7 @@ public:
QPair<QByteArray, QByteArray> getKeypair() const;
bool isReady() const;
void callWhenAvReady(std::function<void(CoreAV* av)>&& 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<std::function<void(CoreAV* av)>> toCallWhenAvReady;
static QThread* coreThread;

View File

@ -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);