fix: fix mod downloads not checking version (#1149)

This commit is contained in:
Fleeym 2024-11-14 02:35:05 +02:00 committed by GitHub
parent bd8387df1b
commit f575187754
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
5 changed files with 39 additions and 15 deletions

View file

@ -8,6 +8,7 @@
#include <fmt/chrono.h>
#include <loader/LoaderImpl.hpp>
#include "../internal/about.hpp"
#include "Geode/loader/Loader.hpp"
using namespace server;
@ -688,7 +689,7 @@ ServerRequest<ServerModVersion> server::getModVersion(std::string const& id, Mod
},
}, version);
return req.get(formatServerURL("/mods/{}/versions/{}", id, versionURL)).map(
return req.get(formatServerURL("/mods/{}/versions/{}?gd={}", id, versionURL, Loader::get()->getGameVersion())).map(
[](web::WebResponse* response) -> Result<ServerModVersion, ServerError> {
if (response->ok()) {
// Parse payload

View file

@ -1,12 +1,15 @@
#include "ModItem.hpp"
#include <vector>
#include <Geode/ui/GeodeUI.hpp>
#include <Geode/utils/ColorProvider.hpp>
#include <Geode/binding/ButtonSprite.hpp>
#include <Geode/loader/Loader.hpp>
#include <vector>
#include "../GeodeStyle.hpp"
#include "../popups/ModPopup.hpp"
#include "../popups/DevPopup.hpp"
#include "server/DownloadManager.hpp"
#include "ui/mods/popups/ModErrorPopup.hpp"
#include "ui/mods/sources/ModSource.hpp"
#include "../../GeodeUIEvent.hpp"
@ -556,18 +559,7 @@ void ModItem::onEnable(CCObject*) {
UpdateModListStateEvent(UpdateModState(m_source.getID())).post();
}
void ModItem::onInstall(CCObject*) {
if (auto updates = m_source.hasUpdates()) {
if (updates->replacement.has_value()) {
server::ModDownloadManager::get()->startDownload(
updates->replacement->id,
updates->replacement->version,
std::nullopt,
m_source.getID()
);
return;
}
}
server::ModDownloadManager::get()->startDownload(m_source.getID(), std::nullopt);
m_source.startInstall();
}
void ModItem::onDevelopers(CCObject*) {
DevListPopup::create(m_source)->show();

View file

@ -1,4 +1,7 @@
#include "ModPopup.hpp"
#include <optional>
#include <Geode/binding/ButtonSprite.hpp>
#include <Geode/ui/MDTextArea.hpp>
#include <Geode/ui/TextInput.hpp>
@ -12,6 +15,7 @@
#include "../../../internal/about.hpp"
#include "../../GeodeUIEvent.hpp"
#include "../popups/ModtoberPopup.hpp"
#include "server/DownloadManager.hpp"
class FetchTextArea : public CCNode {
public:
@ -1044,7 +1048,9 @@ void ModPopup::onInstall(CCObject*) {
return;
}
}
server::ModDownloadManager::get()->startDownload(m_source.getID(), std::nullopt);
m_source.startInstall();
this->onClose(nullptr);
}

View file

@ -236,3 +236,27 @@ server::ServerRequest<std::optional<server::ServerModUpdate>> ModSource::checkUp
},
}, m_value);
}
void ModSource::startInstall() {
if (auto updates = this->hasUpdates()) {
if (updates->replacement.has_value()) {
server::ModDownloadManager::get()->startDownload(
updates->replacement->id,
updates->replacement->version,
std::nullopt,
this->getID()
);
} else {
server::ModDownloadManager::get()->startDownload(
this->getID(),
updates->version
);
}
} else {
server::ModDownloadManager::get()->startDownload(
this->getID(),
this->asServer()
? std::optional{this->asServer()->latestVersion().getVersion()}
: std::nullopt
);
}
}

View file

@ -49,4 +49,5 @@ public:
server::ServerRequest<std::optional<std::string>> fetchChangelog() const;
server::ServerRequest<std::unordered_set<std::string>> fetchValidTags() const;
server::ServerRequest<std::optional<server::ServerModUpdate>> checkUpdates();
void startInstall();
};