feat: make use of tiny-process
This commit is contained in:
parent
dbb23b769b
commit
d31cc8d752
3
.gitmodules
vendored
3
.gitmodules
vendored
@ -20,3 +20,6 @@
|
||||
[submodule "src/ui/impl/webview/lib/webviewpp"]
|
||||
path = src/ui/impl/webview/lib/webviewpp
|
||||
url = https://github.com/Soundux/webviewpp
|
||||
[submodule "lib/tiny-process-library"]
|
||||
path = lib/tiny-process-library
|
||||
url = https://gitlab.com/eidheim/tiny-process-library/
|
||||
|
@ -50,8 +50,9 @@ endif()
|
||||
|
||||
add_subdirectory(src/ui/impl/webview/lib/webviewpp EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(lib/nativefiledialog-extended EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(lib/tiny-process-library EXCLUDE_FROM_ALL)
|
||||
add_subdirectory(lib/InstanceGuard/Source EXCLUDE_FROM_ALL)
|
||||
target_link_libraries(soundux PUBLIC webview nfd InstanceGuard)
|
||||
target_link_libraries(soundux PUBLIC webview nfd InstanceGuard tiny-process-library)
|
||||
|
||||
# [[ Build Frontend ]]
|
||||
if (MSVC)
|
||||
|
1
lib/tiny-process-library
Submodule
1
lib/tiny-process-library
Submodule
@ -0,0 +1 @@
|
||||
Subproject commit 15e4f77f8254e4b093f6be128db50fe4b6bee120
|
@ -1,9 +1,9 @@
|
||||
#include "misc.hpp"
|
||||
#include <array>
|
||||
#include <fancy.hpp>
|
||||
#include <filesystem>
|
||||
#include <fstream>
|
||||
#include <optional>
|
||||
#include <process.hpp>
|
||||
#include <regex>
|
||||
#include <sstream>
|
||||
|
||||
@ -24,6 +24,14 @@ namespace Soundux::Helpers
|
||||
}
|
||||
return result;
|
||||
}
|
||||
bool exec(const std::string &command, std::string &result)
|
||||
{
|
||||
result.clear();
|
||||
TinyProcessLib::Process process(
|
||||
command, "", [&](const char *data, std::size_t dataLen) { result += std::string(data, dataLen); });
|
||||
|
||||
return process.get_exit_status() == 0;
|
||||
}
|
||||
#if defined(_WIN32)
|
||||
std::wstring widen(const std::string &s)
|
||||
{
|
||||
@ -38,23 +46,6 @@ namespace Soundux::Helpers
|
||||
}
|
||||
#endif
|
||||
#if defined(__linux__)
|
||||
bool exec(const std::string &command, std::string &result)
|
||||
{
|
||||
result.clear();
|
||||
|
||||
std::array<char, 128> buffer;
|
||||
auto *pipe = popen(command.c_str(), "r");
|
||||
if (!pipe)
|
||||
{
|
||||
throw std::runtime_error("popen failed");
|
||||
}
|
||||
while (fgets(buffer.data(), buffer.size(), pipe) != nullptr)
|
||||
{
|
||||
result += buffer.data();
|
||||
}
|
||||
|
||||
return pclose(pipe) == 0;
|
||||
}
|
||||
std::optional<int> getPpid(int pid)
|
||||
{
|
||||
std::filesystem::path path("/proc/" + std::to_string(pid));
|
||||
|
@ -1,4 +1,5 @@
|
||||
#pragma once
|
||||
#include <functional>
|
||||
#include <optional>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
@ -12,8 +13,8 @@ namespace Soundux
|
||||
#endif
|
||||
#if defined(__linux__)
|
||||
std::optional<int> getPpid(int pid);
|
||||
bool exec(const std::string &command, std::string &result);
|
||||
#endif
|
||||
bool exec(const std::string &command, std::string &result);
|
||||
std::vector<std::string> splitByNewLine(const std::string &str);
|
||||
} // namespace Helpers
|
||||
} // namespace Soundux
|
Loading…
x
Reference in New Issue
Block a user