This commit is contained in:
parent
ab9a5292aa
commit
b4542c24be
@ -1,5 +1,6 @@
|
||||
#include "GetbinClient.hpp"
|
||||
#include <drogon/HttpClient.h>
|
||||
#include <drogon/HttpAppFramework.h>
|
||||
#include <drogon/utils/Utilities.h>
|
||||
#include <fstream>
|
||||
#include <sstream>
|
||||
@ -11,12 +12,41 @@
|
||||
#include <cstdio>
|
||||
#include <map>
|
||||
#include <atomic>
|
||||
#include <mutex>
|
||||
#include <condition_variable>
|
||||
|
||||
using json = nlohmann::json;
|
||||
|
||||
static constexpr const char* SERVER_HOST = "getpkg.xyz";
|
||||
|
||||
GetbinClient::GetbinClient() {}
|
||||
// Global flag to track if event loop is running
|
||||
static std::atomic<bool> g_eventLoopRunning{false};
|
||||
static std::thread g_eventLoopThread;
|
||||
static std::mutex g_eventLoopMutex;
|
||||
static std::condition_variable g_eventLoopCv;
|
||||
|
||||
static void ensureEventLoop() {
|
||||
static std::once_flag initFlag;
|
||||
std::call_once(initFlag, []() {
|
||||
g_eventLoopThread = std::thread([]() {
|
||||
// Start the event loop in a separate thread
|
||||
drogon::app().getLoop()->queueInLoop([]() {
|
||||
std::unique_lock<std::mutex> lock(g_eventLoopMutex);
|
||||
g_eventLoopRunning = true;
|
||||
g_eventLoopCv.notify_all();
|
||||
});
|
||||
drogon::app().run();
|
||||
});
|
||||
|
||||
// Wait for event loop to start
|
||||
std::unique_lock<std::mutex> lock(g_eventLoopMutex);
|
||||
g_eventLoopCv.wait(lock, []() { return g_eventLoopRunning.load(); });
|
||||
});
|
||||
}
|
||||
|
||||
GetbinClient::GetbinClient() {
|
||||
ensureEventLoop();
|
||||
}
|
||||
|
||||
bool GetbinClient::download(const std::string& toolName, const std::string& arch, const std::string& outPath) {
|
||||
auto client = drogon::HttpClient::newHttpClient("https://" + std::string(SERVER_HOST));
|
||||
|
Loading…
x
Reference in New Issue
Block a user