mirror of
https://github.com/geode-sdk/geode.git
synced 2025-02-17 00:30:26 -05:00
add Index::isUpdating(), show message properly when updating index
This commit is contained in:
parent
dc2fba24ee
commit
b63611ede8
4 changed files with 36 additions and 10 deletions
|
@ -299,6 +299,10 @@ namespace geode {
|
||||||
* Whether the index is up-to-date, i.e. all sources are up-to-date
|
* Whether the index is up-to-date, i.e. all sources are up-to-date
|
||||||
*/
|
*/
|
||||||
bool isUpToDate() const;
|
bool isUpToDate() const;
|
||||||
|
/**
|
||||||
|
* Whether the index is currently updating
|
||||||
|
*/
|
||||||
|
bool isUpdating() const;
|
||||||
/**
|
/**
|
||||||
* Update the index. Add an event listener for the IndexUpdateEvent
|
* Update the index. Add an event listener for the IndexUpdateEvent
|
||||||
* class to track updating progress
|
* class to track updating progress
|
||||||
|
|
|
@ -288,6 +288,10 @@ bool Index::isUpToDate() const {
|
||||||
return m_impl->m_isUpToDate;
|
return m_impl->m_isUpToDate;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool Index::isUpdating() const {
|
||||||
|
return m_impl->m_updating;
|
||||||
|
}
|
||||||
|
|
||||||
bool Index::hasTriedToUpdate() const {
|
bool Index::hasTriedToUpdate() const {
|
||||||
return m_impl->m_triedToUpdate;
|
return m_impl->m_triedToUpdate;
|
||||||
}
|
}
|
||||||
|
@ -318,6 +322,8 @@ void Index::Impl::downloadIndex(std::string commitHash) {
|
||||||
|
|
||||||
std::thread([=, this]() {
|
std::thread([=, this]() {
|
||||||
// unzip new index
|
// unzip new index
|
||||||
|
log::debug("Unzipping index");
|
||||||
|
IndexUpdateEvent(UpdateProgress(100, "Unzipping index")).post();
|
||||||
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) {
|
||||||
|
@ -344,12 +350,15 @@ void Index::Impl::downloadIndex(std::string commitHash) {
|
||||||
IndexUpdateEvent(UpdateFailed(fmt::format("Error downloading: {}", err))).post();
|
IndexUpdateEvent(UpdateFailed(fmt::format("Error downloading: {}", err))).post();
|
||||||
})
|
})
|
||||||
.progress([](auto&, double now, double total) {
|
.progress([](auto&, double now, double total) {
|
||||||
IndexUpdateEvent(
|
// prevent nan at the start, for some reason
|
||||||
UpdateProgress(
|
if (total != 0.0) {
|
||||||
static_cast<uint8_t>(now / total * 100.0),
|
IndexUpdateEvent(
|
||||||
"Downloading"
|
UpdateProgress(
|
||||||
)
|
static_cast<uint8_t>(now / total * 100.0),
|
||||||
).post();
|
"Downloading"
|
||||||
|
)
|
||||||
|
).post();
|
||||||
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -488,7 +488,9 @@ void ModListLayer::reloadList(bool keepScroll, std::optional<ModListQuery> const
|
||||||
// set list status
|
// set list status
|
||||||
if (!items->count()) {
|
if (!items->count()) {
|
||||||
m_listLabel->setVisible(true);
|
m_listLabel->setVisible(true);
|
||||||
m_listLabel->setString("No mods found");
|
if (!Index::get()->isUpdating()) {
|
||||||
|
m_listLabel->setString("No mods found");
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
m_listLabel->setVisible(false);
|
m_listLabel->setVisible(false);
|
||||||
}
|
}
|
||||||
|
@ -500,9 +502,12 @@ void ModListLayer::reloadList(bool keepScroll, std::optional<ModListQuery> const
|
||||||
}
|
}
|
||||||
|
|
||||||
// update index if needed
|
// update index if needed
|
||||||
if (g_tab == ModListType::Download && !Index::get()->hasTriedToUpdate()) {
|
if (g_tab == ModListType::Download && !Index::get()->isUpToDate()) {
|
||||||
m_listLabel->setVisible(true);
|
m_listLabel->setVisible(true);
|
||||||
m_listLabel->setString("Updating index...");
|
// dont want to overwrite th message we set in UpdateProgress
|
||||||
|
if (!Index::get()->isUpdating()) {
|
||||||
|
m_listLabel->setString("Updating index...");
|
||||||
|
}
|
||||||
if (!m_loadingCircle) {
|
if (!m_loadingCircle) {
|
||||||
m_loadingCircle = LoadingCircle::create();
|
m_loadingCircle = LoadingCircle::create();
|
||||||
|
|
||||||
|
@ -622,7 +627,14 @@ void ModListLayer::onCheckForUpdates(CCObject*) {
|
||||||
|
|
||||||
void ModListLayer::onIndexUpdate(IndexUpdateEvent* event) {
|
void ModListLayer::onIndexUpdate(IndexUpdateEvent* event) {
|
||||||
std::visit(makeVisitor {
|
std::visit(makeVisitor {
|
||||||
[&](UpdateProgress const& prog) {},
|
[&](UpdateProgress const& prog) {
|
||||||
|
auto msg = prog.second;
|
||||||
|
// amazing
|
||||||
|
if (prog.second == "Downloading") {
|
||||||
|
msg += fmt::format(" {}%", prog.first);
|
||||||
|
}
|
||||||
|
m_listLabel->setString((msg + "...").c_str());
|
||||||
|
},
|
||||||
[&](UpdateFinished const&) {
|
[&](UpdateFinished const&) {
|
||||||
this->reloadList();
|
this->reloadList();
|
||||||
},
|
},
|
||||||
|
|
|
@ -491,6 +491,7 @@ Result<> Unzip::intoDir(
|
||||||
// removed
|
// removed
|
||||||
{
|
{
|
||||||
GEODE_UNWRAP_INTO(auto unzip, Unzip::create(from));
|
GEODE_UNWRAP_INTO(auto unzip, Unzip::create(from));
|
||||||
|
// TODO: this is quite slow lol, takes 30 seconds to extract index..
|
||||||
GEODE_UNWRAP(unzip.extractAllTo(to));
|
GEODE_UNWRAP(unzip.extractAllTo(to));
|
||||||
}
|
}
|
||||||
if (deleteZipAfter) {
|
if (deleteZipAfter) {
|
||||||
|
|
Loading…
Reference in a new issue