mirror of
https://github.com/xiaozhou233/JuiceAgent.git
synced 2026-12-05 13:05:53 +08:00
- libloader: add platform/linux/Entry.cpp that starts the loader from a constructor - libloader: read the config path from JuiceAgent_ConfigPath, falling back to $HOME/.juiceagent - libloader: default JuiceAgentNativeLibraryPath to libagent.so on non-Windows - injector: print a notice that the Linux injector is not open source yet
59 lines
1.4 KiB
C++
59 lines
1.4 KiB
C++
#include "JuiceAgent/Logger.hpp"
|
|
#include "Loader.hpp"
|
|
|
|
#include <cstdlib>
|
|
#include <filesystem>
|
|
#include <string>
|
|
#include <system_error>
|
|
#include <thread>
|
|
|
|
namespace fs = std::filesystem;
|
|
|
|
static void run_loader() {
|
|
const char* env = std::getenv("JuiceAgent_ConfigPath");
|
|
std::string current_path;
|
|
|
|
if (env != nullptr && env[0] != '\0') {
|
|
// Use the environment variable if it exists and is not empty.
|
|
current_path = env;
|
|
} else {
|
|
spdlog::trace("[libloader] JuiceAgent_ConfigPath is not set");
|
|
|
|
const char* home = std::getenv("HOME");
|
|
if (home == nullptr || home[0] == '\0') {
|
|
spdlog::error("[libloader] HOME environment variable is not set");
|
|
return;
|
|
}
|
|
|
|
// Fall back to $HOME/.juiceagent.
|
|
fs::path config_dir = fs::path(home) / ".juiceagent";
|
|
|
|
std::error_code ec;
|
|
fs::create_directories(config_dir, ec);
|
|
|
|
if (ec) {
|
|
spdlog::error(
|
|
"[libloader] Failed to create config directory: {}",
|
|
ec.message()
|
|
);
|
|
return;
|
|
}
|
|
|
|
current_path = config_dir.string();
|
|
}
|
|
|
|
spdlog::info("[libloader] current path: {}", current_path);
|
|
|
|
JuiceAgent::Loader::entrypoint(current_path.c_str());
|
|
}
|
|
|
|
__attribute__((constructor))
|
|
static void entry() {
|
|
Logger::init();
|
|
|
|
spdlog::info("[libloader] loaded!");
|
|
|
|
std::thread([] {
|
|
run_loader();
|
|
}).detach();
|
|
} |