Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .github/workflows/multi-platform.yml
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ jobs:

steps:
- uses: actions/checkout@v4
with:
submodules: recursive

- name: Build the mod
uses: geode-sdk/build-geode-mod@main
Expand Down
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "external/reproc"]
path = external/reproc
url = https://github.com/DaanDeMeyer/reproc.git
4 changes: 4 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ file(GLOB_RECURSE SOURCES src/*.cpp src/*/*.cpp)
# Set up the mod binary
add_library(${PROJECT_NAME} SHARED ${SOURCES})

set(REPROC++ ON)
add_subdirectory(external/reproc)
target_link_libraries(${PROJECT_NAME} reproc++)

if (NOT DEFINED ENV{GEODE_SDK})
message(FATAL_ERROR "Unable to find Geode SDK! Please define GEODE_SDK environment variable to point to Geode")
else()
Expand Down
1 change: 1 addition & 0 deletions external/reproc
Submodule reproc added at 317992
62 changes: 32 additions & 30 deletions src/wakatime/cli.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
#include "../utils/which.hpp"
#include "cli.hpp"
#include "wakatime.hpp"
#include "reproc++/run.hpp"

#ifdef GEODE_IS_WINDOWS
#define POPEN _popen
Expand Down Expand Up @@ -96,24 +97,29 @@ namespace cli {
std::string getCurrentVersion() {
if (!isInstalled()) return "";

std::filesystem::path path = getPath();

std::string command = fmt::format("{} --version", utils::quote(path.string()));
std::vector<std::string> args = { getPath().string(), "--version" };
std::string result, stderr_output;

std::string result;
char buffer[128];
reproc::options options;
options.redirect.parent = false;

FILE* pipe = POPEN(command.c_str(), "r");
if (!pipe) {
geode::log::error("Unable to fetch wakatime-cli version");
auto [status, ec] = reproc::run(args, options, reproc::sink::string(result), reproc::sink::string(stderr_output));

if (ec) {
geode::log::error("WakaTime CLI exited with error code: {}", ec.message());
return "";
}

while (!feof(pipe)) {
if (fgets(buffer, sizeof(buffer), pipe) != nullptr) result += buffer;
if (status != 0) {
geode::log::error("WakaTime CLI exited with status: {}", status);
return "";
}

PCLOSE(pipe);
if (!stderr_output.empty()) {
geode::log::error("WakaTime CLI stderr: {}", stderr_output);
return "";
}

result.erase(0, result.find_first_not_of(" \n\r\t"));
result.erase(result.find_last_not_of(" \n\r\t") + 1);
Expand Down Expand Up @@ -258,29 +264,25 @@ namespace cli {
}

bool execute(const std::filesystem::path& path, const std::vector<std::string>& args) {
std::string command = utils::quote(path.string());

for (const auto& arg : args) {
command += " " + arg;
}
std::vector<std::string> command;
command.push_back(path.string());
command.insert(command.end(), args.begin(), args.end());

geode::log::debug("Executing WakaTime CLI command: {}", command);

std::thread([command]() {
std::string fullCommand = utils::quote(command);
#ifdef GEODE_IS_WINDOWS
fullCommand += " >nul 2>&1";
#else
fullCommand += " >/dev/null 2>&1";
#endif

FILE* pipe = POPEN(fullCommand.c_str(), "r");
if (pipe) {
int result = PCLOSE(pipe);
if (result != 0) geode::log::error("WakaTime CLI command failed with exit code: {}", result);
} else {
geode::log::error("WakaTime CLI command failed to start");
}
reproc::options options;
options.redirect.parent = false;

std::string stdout_output, stderr_output;

auto [status, ec] = reproc::run(command, options, reproc::sink::string(stdout_output), reproc::sink::string(stderr_output));

if (ec) geode::log::error("WakaTime CLI exited with error code: {}", ec.message());

if (!stderr_output.empty()) geode::log::error("WakaTime CLI command stderr: {}", stderr_output);

if (status != 0) geode::log::error("WakaTime CLI exited with status: {}", status);
}).detach();

return true;
Expand Down
1 change: 1 addition & 0 deletions src/wakatime/tracker.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ namespace tracker {
active = true;
activityStarted = std::chrono::system_clock::now();
geode::log::debug("New activity: {} {}", getCategory(), project);
onActivityChange(); // send heartbeat
}

void ActivityTracker::checkActivity() {
Expand Down
Loading