Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
fix(init): register AV connects and call after AV is ready
Browse files Browse the repository at this point in the history
Fixes #4651
  • Loading branch information
anthonybilinski committed Oct 13, 2017
1 parent 2f1bf10 commit 7170b48
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 2 deletions.
8 changes: 8 additions & 0 deletions src/core/core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,10 @@ void Core::makeAv()
qCritical() << "Toxav core failed to start";
emit failedToStart();
}
for (const auto& callback : toCallWhenAvReady) {
callback(av);
}
toCallWhenAvReady.clear();
}

/**
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions src/core/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ class Core : public QObject
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);

Expand Down Expand Up @@ -226,6 +227,7 @@ private slots:
QMutex messageSendMutex;
bool ready;
const ICoreSettings* const s;
std::vector<std::function<void(CoreAV* av)>> toCallWhenAvReady;

static QThread* coreThread;

Expand Down
3 changes: 1 addition & 2 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down

0 comments on commit 7170b48

Please sign in to comment.