add option for single-page local mods list

This commit is contained in:
HJfod 2024-11-10 12:17:14 +02:00
parent a3b306a4e0
commit efb1fbf729
6 changed files with 38 additions and 13 deletions

View file

@ -85,6 +85,12 @@
"name": "Enable Geode-Themed Colors", "name": "Enable Geode-Themed Colors",
"description": "When enabled, the Geode menu has a <ca>Geode-themed color scheme</c>. <cy>This does not affect any other menus!</c>" "description": "When enabled, the Geode menu has a <ca>Geode-themed color scheme</c>. <cy>This does not affect any other menus!</c>"
}, },
"infinite-local-mods-list": {
"type": "bool",
"default": false,
"name": "Expand Installed Mods List",
"description": "Make the installed mods list a single infinite scrollable list instead of having pages"
},
"developer-title": { "developer-title": {
"type": "title", "type": "title",
"name": "Developer Settings" "name": "Developer Settings"

View file

@ -68,9 +68,15 @@ void InstalledModListSource::resetQuery() {
}; };
} }
InstalledModListSource::ProviderTask InstalledModListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) { InstalledModListSource::ProviderTask InstalledModListSource::fetchPage(size_t page, bool forceUpdate) {
m_query.page = page; m_query.page = page;
m_query.pageSize = pageSize; m_query.pageSize = m_pageSize;
// Infinite mods list option
if (Mod::get()->template getSettingValue<bool>("infinite-local-mods-list")) {
m_query.page = 0;
m_query.pageSize = Loader::get()->getAllMods().size();
}
auto content = ModListSource::ProvidedMods(); auto content = ModListSource::ProvidedMods();
for (auto& mod : Loader::get()->getAllMods()) { for (auto& mod : Loader::get()->getAllMods()) {
@ -122,3 +128,12 @@ InvalidateQueryAfter<InstalledModsQuery> InstalledModListSource::getQueryMut() {
bool InstalledModListSource::isDefaultQuery() const { bool InstalledModListSource::isDefaultQuery() const {
return m_query.isDefault(); return m_query.isDefault();
} }
$execute {
listenForSettingChanges("infinite-local-mods-list", [](bool value) {
auto size = value ? std::numeric_limits<size_t>::max() : 10;
InstalledModListSource::get(InstalledModListType::All)->setPageSize(size);
InstalledModListSource::get(InstalledModListType::OnlyErrors)->setPageSize(size);
// Updates is technically a server mod list :-) So I left it out here
});
}

View file

@ -5,7 +5,6 @@
#define FTS_FUZZY_MATCH_IMPLEMENTATION #define FTS_FUZZY_MATCH_IMPLEMENTATION
#include <Geode/external/fts/fts_fuzzy_match.h> #include <Geode/external/fts/fts_fuzzy_match.h>
static constexpr size_t PER_PAGE = 10;
static std::vector<ModListSource*> ALL_EXTANT_SOURCES {}; static std::vector<ModListSource*> ALL_EXTANT_SOURCES {};
static size_t ceildiv(size_t a, size_t b) { static size_t ceildiv(size_t a, size_t b) {
@ -33,7 +32,7 @@ typename ModListSource::PageLoadTask ModListSource::loadPage(size_t page, bool f
return PageLoadTask::immediate(Ok(m_cachedPages.at(page))); return PageLoadTask::immediate(Ok(m_cachedPages.at(page)));
} }
m_cachedPages.erase(page); m_cachedPages.erase(page);
return this->fetchPage(page, PER_PAGE, forceUpdate).map( return this->fetchPage(page, forceUpdate).map(
[this, page](Result<ProvidedMods, LoadPageError>* result) -> Result<Page, LoadPageError> { [this, page](Result<ProvidedMods, LoadPageError>* result) -> Result<Page, LoadPageError> {
if (result->isOk()) { if (result->isOk()) {
auto data = result->unwrap(); auto data = result->unwrap();
@ -56,12 +55,15 @@ typename ModListSource::PageLoadTask ModListSource::loadPage(size_t page, bool f
} }
std::optional<size_t> ModListSource::getPageCount() const { std::optional<size_t> ModListSource::getPageCount() const {
return m_cachedItemCount ? std::optional(ceildiv(m_cachedItemCount.value(), PER_PAGE)) : std::nullopt; return m_cachedItemCount ? std::optional(ceildiv(m_cachedItemCount.value(), m_pageSize)) : std::nullopt;
} }
std::optional<size_t> ModListSource::getItemCount() const { std::optional<size_t> ModListSource::getItemCount() const {
return m_cachedItemCount; return m_cachedItemCount;
} }
void ModListSource::setPageSize(size_t size) {
m_pageSize = size;
this->reset();
}
void ModListSource::reset() { void ModListSource::reset() {
this->resetQuery(); this->resetQuery();

View file

@ -51,9 +51,10 @@ public:
protected: protected:
std::unordered_map<size_t, Page> m_cachedPages; std::unordered_map<size_t, Page> m_cachedPages;
std::optional<size_t> m_cachedItemCount; std::optional<size_t> m_cachedItemCount;
size_t m_pageSize = 10;
virtual void resetQuery() = 0; virtual void resetQuery() = 0;
virtual ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) = 0; virtual ProviderTask fetchPage(size_t page, bool forceUpdate) = 0;
virtual void setSearchQuery(std::string const& query) = 0; virtual void setSearchQuery(std::string const& query) = 0;
ModListSource(); ModListSource();
@ -75,6 +76,7 @@ public:
PageLoadTask loadPage(size_t page, bool forceUpdate = false); PageLoadTask loadPage(size_t page, bool forceUpdate = false);
std::optional<size_t> getPageCount() const; std::optional<size_t> getPageCount() const;
std::optional<size_t> getItemCount() const; std::optional<size_t> getItemCount() const;
void setPageSize(size_t size);
static void clearAllCaches(); static void clearAllCaches();
static bool isRestartRequired(); static bool isRestartRequired();
@ -123,7 +125,7 @@ protected:
InstalledModsQuery m_query; InstalledModsQuery m_query;
void resetQuery() override; void resetQuery() override;
ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override; ProviderTask fetchPage(size_t page, bool forceUpdate) override;
void setSearchQuery(std::string const& query) override; void setSearchQuery(std::string const& query) override;
InstalledModListSource(InstalledModListType type); InstalledModListSource(InstalledModListType type);
@ -153,7 +155,7 @@ protected:
server::ModsQuery m_query; server::ModsQuery m_query;
void resetQuery() override; void resetQuery() override;
ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override; ProviderTask fetchPage(size_t page, bool forceUpdate) override;
void setSearchQuery(std::string const& query) override; void setSearchQuery(std::string const& query) override;
ServerModListSource(ServerModListType type); ServerModListSource(ServerModListType type);
@ -174,7 +176,7 @@ public:
class ModPackListSource : public ModListSource { class ModPackListSource : public ModListSource {
protected: protected:
void resetQuery() override; void resetQuery() override;
ProviderTask fetchPage(size_t page, size_t pageSize, bool forceUpdate) override; ProviderTask fetchPage(size_t page, bool forceUpdate) override;
void setSearchQuery(std::string const& query) override; void setSearchQuery(std::string const& query) override;
ModPackListSource(); ModPackListSource();

View file

@ -1,7 +1,7 @@
#include "ModListSource.hpp" #include "ModListSource.hpp"
void ModPackListSource::resetQuery() {} void ModPackListSource::resetQuery() {}
ModPackListSource::ProviderTask ModPackListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) { ModPackListSource::ProviderTask ModPackListSource::fetchPage(size_t page, bool forceUpdate) {
return ProviderTask::immediate(Err(LoadPageError("Coming soon ;)"))); return ProviderTask::immediate(Err(LoadPageError("Coming soon ;)")));
} }

View file

@ -4,9 +4,9 @@ void ServerModListSource::resetQuery() {
m_query = this->createDefaultQuery(); m_query = this->createDefaultQuery();
} }
ServerModListSource::ProviderTask ServerModListSource::fetchPage(size_t page, size_t pageSize, bool forceUpdate) { ServerModListSource::ProviderTask ServerModListSource::fetchPage(size_t page, bool forceUpdate) {
m_query.page = page; m_query.page = page;
m_query.pageSize = pageSize; m_query.pageSize = m_pageSize;
return server::getMods(m_query, !forceUpdate).map( return server::getMods(m_query, !forceUpdate).map(
[](Result<server::ServerModsList, server::ServerError>* result) -> ProviderTask::Value { [](Result<server::ServerModsList, server::ServerError>* result) -> ProviderTask::Value {
if (result->isOk()) { if (result->isOk()) {