make index unzip async

This commit is contained in:
ConfiG 2023-09-11 15:22:19 +03:00
parent ae048e48a9
commit 7c582f177f
No known key found for this signature in database
GPG key ID: 44DA1983F524C11B

View file

@ -318,19 +318,25 @@ void Index::Impl::downloadIndex() {
return;
}
std::thread([=, this]() {
// unzip new index
auto unzip = file::Unzip::intoDir(targetFile, targetDir, true)
.expect("Unable to unzip new index");
if (!unzip) {
Loader::get()->queueInMainThread([unzip] {
IndexUpdateEvent(UpdateFailed(unzip.unwrapErr())).post();
});
return;
}
// remove the directory github adds to the root of the zip
(void)flattenGithubRepo(targetDir);
Loader::get()->queueInMainThread([this] {
// update index
this->updateFromLocalTree();
});
}).detach();
})
.expect([](std::string const& err) {
IndexUpdateEvent(UpdateFailed(fmt::format("Error downloading: {}", err))).post();
@ -448,7 +454,8 @@ void Index::update(bool force) {
// update sources
if (force) {
m_impl->downloadIndex();
} else {
}
else {
m_impl->checkForUpdates();
}
}