diff --git a/src/Network/Core.cpp b/src/Network/Core.cpp index 46d4a1f..d28c515 100644 --- a/src/Network/Core.cpp +++ b/src/Network/Core.cpp @@ -8,17 +8,20 @@ #include "Http.h" #include "Network/network.hpp" #include "Security/Init.h" +#include #include #if defined(_WIN32) #include #include - #elif defined(__linux__) #include #include #include +#include #include #include +#include +#include #endif #include "Logger.h" @@ -96,7 +99,27 @@ void Parse(std::string Data, SOCKET CSocket) { break; case 'O': // open default browser with URL if (IsAllowedLink(Data.substr(1))) { +#if defined(__linux) + if (char* browser = getenv("BROWSER"); browser != nullptr && !std::string_view(browser).empty()) { + pid_t pid; + auto arg = Data.substr(1); + char* argv[] = { browser, arg.data() }; + auto status = posix_spawn(&pid, browser, nullptr, nullptr, argv, environ); + if (status == 0) { + debug("Browser PID: " + std::to_string(pid)); + // we don't wait for it to exit, because we just don't care. + // typically, you'd waitpid() here. + } else { + error("Failed to open the following link in the browser (error follows below): " + arg); + error(std::string("posix_spawn: ") + strerror(status)); + } + } else { + error("Failed to open the following link in the browser because the $BROWSER environment variable is not set: " + Data.substr(1)); + } +#elif defined(WIN32) ShellExecuteA(nullptr, "open", Data.substr(1).c_str(), nullptr, nullptr, SW_SHOW); /// TODO: Look at when working on linux port +#endif + info("Opening Link \"" + Data.substr(1) + "\""); } Data.clear();