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