make openInfoPopup return a Task<bool>

This commit is contained in:
HJfod 2024-07-29 13:10:42 +03:00
parent c4fe40b037
commit c323faee27
2 changed files with 17 additions and 3 deletions

View file

@ -15,8 +15,11 @@ namespace geode {
* Open the info popup for a mod based on an ID. If the mod is installed,
* its installed popup is opened. Otherwise will check if the servers
* have this mod, or if not, show an error popup
* @returns A Task that completes to `true` if the mod was found and a
* popup was opened, and `false` otherwise. If you wish to modify the
* created popup, listen for the Geode UI events listed in `GeodeUI.hpp`
*/
GEODE_DLL void openInfoPopup(std::string const& modID);
GEODE_DLL Task<bool> openInfoPopup(std::string const& modID);
/**
* Open the info popup for a mod on the changelog page
*/

View file

@ -56,6 +56,13 @@ protected:
}
public:
Task<bool> listen() const {
return m_listener.getFilter().map(
[](auto* result) -> bool { return result->isOk(); },
[](auto) -> std::monostate { return std::monostate(); }
);
}
static LoadServerModLayer* create(std::string const& id) {
auto ret = new LoadServerModLayer();
if (ret && ret->initAnchored(180, 100, id, "square01_001.png", CCRectZero)) {
@ -127,12 +134,16 @@ void geode::openSupportPopup(ModMetadata const& metadata) {
void geode::openInfoPopup(Mod* mod) {
ModPopup::create(mod)->show();
}
void geode::openInfoPopup(std::string const& modID) {
Task<bool> geode::openInfoPopup(std::string const& modID) {
if (auto mod = Loader::get()->getInstalledMod(modID)) {
openInfoPopup(mod);
return Task<bool>::immediate(true);
}
else {
LoadServerModLayer::create(modID)->show();
auto popup = LoadServerModLayer::create(modID);
auto task = popup->listen();
popup->show();
return task;
}
}
void geode::openIndexPopup(Mod* mod) {