Skip to content

Commit

Permalink
force openInfoPopup to show latest version
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed Dec 20, 2024
1 parent c6666a3 commit bda9444
Showing 1 changed file with 36 additions and 7 deletions.
43 changes: 36 additions & 7 deletions loader/src/ui/GeodeUI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ class LoadServerModLayer : public Popup<std::string const&> {
protected:
std::string m_id;
EventListener<server::ServerRequest<server::ServerModMetadata>> m_listener;
EventListener<server::ServerRequest<server::ServerModVersion>> m_versionListener;

std::optional<server::ServerModMetadata> m_loadedMod{};

bool setup(std::string const& id) override {
m_closeBtn->setVisible(false);
Expand All @@ -24,22 +27,21 @@ class LoadServerModLayer : public Popup<std::string const&> {
m_mainLayer->addChildAtPosition(spinner, Anchor::Center, ccp(0, -10));

m_id = id;
m_listener.bind(this, &LoadServerModLayer::onRequest);
m_listener.bind(this, &LoadServerModLayer::onModRequest);
m_listener.setFilter(server::getMod(id));

return true;
}

void onRequest(server::ServerRequest<server::ServerModMetadata>::Event* event) {
void onModRequest(server::ServerRequest<server::ServerModMetadata>::Event* event) {
if (auto res = event->getValue()) {
if (res->isOk()) {
// Copy info first as onClose may free the listener which will free the event
auto info = res->unwrap();
this->onClose(nullptr);
// Run this on next frame because otherwise the popup is unable to call server::getMod for some reason
Loader::get()->queueInMainThread([info = std::move(info)]() mutable {
ModPopup::create(ModSource(std::move(info)))->show();
});
m_loadedMod = std::move(info);

m_versionListener.bind(this, &LoadServerModLayer::onVersionRequest);
m_versionListener.setFilter(server::getModVersion(m_id));
}
else {
auto id = m_id;
Expand All @@ -56,6 +58,33 @@ class LoadServerModLayer : public Popup<std::string const&> {
}
}

void onVersionRequest(server::ServerRequest<server::ServerModVersion>::Event* event) {
if (auto res = event->getValue()) {
// this is promised non optional by this point
auto info = std::move(*m_loadedMod);

if (res->isOk()) {
// i don't actually think there's a better way to do this
// sorry guys

auto versionInfo = res->unwrap();
info.versions = {versionInfo};
}

// if there's an error, just load whatever the last fetched version was
// (this can happen for mods not on current gd version)

this->onClose(nullptr);
// Run this on next frame because otherwise the popup is unable to call server::getMod for some reason
Loader::get()->queueInMainThread([info = std::move(info)]() mutable {
ModPopup::create(ModSource(std::move(info)))->show();
});
}
else if (event->isCancelled()) {
this->onClose(nullptr);
}
}

public:
Task<bool> listen() const {
return m_listener.getFilter().map(
Expand Down

0 comments on commit bda9444

Please sign in to comment.