Skip to content

Commit

Permalink
Fix lag (#59)
Browse files Browse the repository at this point in the history
  • Loading branch information
MuhXd authored Dec 22, 2024
1 parent fbd883f commit 2b54dda
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 30 deletions.
2 changes: 2 additions & 0 deletions src/jsonReader/Json.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ class JsonReader {
bool hassomedata = false;

void loadData() {
std::thread([=] {
auto configDir = Mod::get()->getConfigDir();
auto clicksPath = configDir / "Clicks" / "clicks-main";
if (std::filesystem::exists(clicksPath)) {
Expand All @@ -35,6 +36,7 @@ class JsonReader {
} else {
//log::error("Unable to load Categories");
}
}).detach();
}

void loadCategoryData(const std::filesystem::path& categoryDir, std::map<std::string, CategoryData>& categoryData) {
Expand Down
62 changes: 32 additions & 30 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,46 +168,48 @@ class $modify(PlayerObject) {
}
};

EventListener<web::WebTask> m_listener;
class $modify(MenuLayer) {
void SendRequestAPI() {
m_listener.bind([] (web::WebTask::Event* e) {
if (web::WebResponse* res = e->getValue()) {
if (res->string().unwrapOr("failed") == "failed") {
indexzip.Failed = true;
indexzip.Finished = true;
return;
}
if (res->into(Mod::get()->getConfigDir() / "Clicks.zip")) {
auto unzip = file::Unzip::create(Mod::get()->getConfigDir() / "Clicks.zip");
if (!unzip) {
std::thread([=] {
web::WebRequest().get("https://github.com/clicksounds/clicks/archive/refs/heads/main.zip").listen([=](auto res) {
if (res->string().unwrapOr("failed") == "failed") {
indexzip.Failed = true;
indexzip.Finished = true;
return;
}
std::filesystem::remove_all(Mod::get()->getConfigDir() / "Clicks");
(void) unzip.unwrap().extractAllTo(Mod::get()->getConfigDir() / "Clicks");
if (res->into(Mod::get()->getConfigDir() / "Clicks.zip")) {
auto unzip = file::Unzip::create(Mod::get()->getConfigDir() / "Clicks.zip");
if (!unzip) {
indexzip.Failed = true;
indexzip.Finished = true;
return;
}
std::filesystem::remove_all(Mod::get()->getConfigDir() / "Clicks");
(void) unzip.unwrap().extractAllTo(Mod::get()->getConfigDir() / "Clicks");
indexzip.Finished = true;
ClickJson->loadData();
onsettingsUpdate();
}
},
[](auto prog){},
[=]() {
indexzip.Failed = true;
indexzip.Finished = true;
ClickJson->loadData();
onsettingsUpdate();
}
} else if (e->isCancelled()) {
indexzip.Failed = true;
indexzip.Finished = true;
}
});
m_listener.setFilter(web::WebRequest().get("https://github.com/clicksounds/clicks/archive/refs/heads/main.zip"));
});
}).detach();
}
bool init() {
bool init() {
if (!indexzip.StartedDownloading) {
indexzip.StartedDownloading = true;
std::thread([=] {
// on boot set Sound Caches
ClickJson->loadData();
onsettingsUpdate();
this->SendRequestAPI();
}).detach();
}
geode::Loader::get()->queueInMainThread([=] {
std::thread([=] {
// on boot set Sound Caches
ClickJson->loadData();
onsettingsUpdate();
this->SendRequestAPI();
}).detach();
});
}
return MenuLayer::init();
}
};
Expand Down

0 comments on commit 2b54dda

Please sign in to comment.