mirror of
https://github.com/geode-sdk/geode.git
synced 2024-11-22 23:48:08 -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
|
||||
*/
|
||||
bool isUpToDate() const;
|
||||
/**
|
||||
* Whether the index is currently updating
|
||||
*/
|
||||
bool isUpdating() const;
|
||||
/**
|
||||
* Update the index. Add an event listener for the IndexUpdateEvent
|
||||
* class to track updating progress
|
||||
|
|
|
@ -288,6 +288,10 @@ bool Index::isUpToDate() const {
|
|||
return m_impl->m_isUpToDate;
|
||||
}
|
||||
|
||||
bool Index::isUpdating() const {
|
||||
return m_impl->m_updating;
|
||||
}
|
||||
|
||||
bool Index::hasTriedToUpdate() const {
|
||||
return m_impl->m_triedToUpdate;
|
||||
}
|
||||
|
@ -318,6 +322,8 @@ void Index::Impl::downloadIndex(std::string commitHash) {
|
|||
|
||||
std::thread([=, this]() {
|
||||
// unzip new index
|
||||
log::debug("Unzipping index");
|
||||
IndexUpdateEvent(UpdateProgress(100, "Unzipping index")).post();
|
||||
auto unzip = file::Unzip::intoDir(targetFile, targetDir, true)
|
||||
.expect("Unable to unzip new index");
|
||||
if (!unzip) {
|
||||
|
@ -344,12 +350,15 @@ void Index::Impl::downloadIndex(std::string commitHash) {
|
|||
IndexUpdateEvent(UpdateFailed(fmt::format("Error downloading: {}", err))).post();
|
||||
})
|
||||
.progress([](auto&, double now, double total) {
|
||||
IndexUpdateEvent(
|
||||
UpdateProgress(
|
||||
static_cast<uint8_t>(now / total * 100.0),
|
||||
"Downloading"
|
||||
)
|
||||
).post();
|
||||
// prevent nan at the start, for some reason
|
||||
if (total != 0.0) {
|
||||
IndexUpdateEvent(
|
||||
UpdateProgress(
|
||||
static_cast<uint8_t>(now / total * 100.0),
|
||||
"Downloading"
|
||||
)
|
||||
).post();
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
@ -488,7 +488,9 @@ void ModListLayer::reloadList(bool keepScroll, std::optional<ModListQuery> const
|
|||
// set list status
|
||||
if (!items->count()) {
|
||||
m_listLabel->setVisible(true);
|
||||
m_listLabel->setString("No mods found");
|
||||
if (!Index::get()->isUpdating()) {
|
||||
m_listLabel->setString("No mods found");
|
||||
}
|
||||
} else {
|
||||
m_listLabel->setVisible(false);
|
||||
}
|
||||
|
@ -500,9 +502,12 @@ void ModListLayer::reloadList(bool keepScroll, std::optional<ModListQuery> const
|
|||
}
|
||||
|
||||
// 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->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) {
|
||||
m_loadingCircle = LoadingCircle::create();
|
||||
|
||||
|
@ -622,7 +627,14 @@ void ModListLayer::onCheckForUpdates(CCObject*) {
|
|||
|
||||
void ModListLayer::onIndexUpdate(IndexUpdateEvent* event) {
|
||||
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&) {
|
||||
this->reloadList();
|
||||
},
|
||||
|
|
|
@ -491,6 +491,7 @@ Result<> Unzip::intoDir(
|
|||
// removed
|
||||
{
|
||||
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));
|
||||
}
|
||||
if (deleteZipAfter) {
|
||||
|
|
Loading…
Reference in a new issue