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"]
|
[submodule "src/ui/impl/webview/lib/webviewpp"]
|
||||||
path = src/ui/impl/webview/lib/webviewpp
|
path = src/ui/impl/webview/lib/webviewpp
|
||||||
url = https://github.com/Soundux/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(src/ui/impl/webview/lib/webviewpp EXCLUDE_FROM_ALL)
|
||||||
add_subdirectory(lib/nativefiledialog-extended 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)
|
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 ]]
|
# [[ Build Frontend ]]
|
||||||
if (MSVC)
|
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 "misc.hpp"
|
||||||
#include <array>
|
|
||||||
#include <fancy.hpp>
|
#include <fancy.hpp>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
#include <fstream>
|
#include <fstream>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
|
#include <process.hpp>
|
||||||
#include <regex>
|
#include <regex>
|
||||||
#include <sstream>
|
#include <sstream>
|
||||||
|
|
||||||
@ -24,6 +24,14 @@ namespace Soundux::Helpers
|
|||||||
}
|
}
|
||||||
return result;
|
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)
|
#if defined(_WIN32)
|
||||||
std::wstring widen(const std::string &s)
|
std::wstring widen(const std::string &s)
|
||||||
{
|
{
|
||||||
@ -38,23 +46,6 @@ namespace Soundux::Helpers
|
|||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(__linux__)
|
#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::optional<int> getPpid(int pid)
|
||||||
{
|
{
|
||||||
std::filesystem::path path("/proc/" + std::to_string(pid));
|
std::filesystem::path path("/proc/" + std::to_string(pid));
|
||||||
|
@ -1,4 +1,5 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
#include <functional>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
@ -12,8 +13,8 @@ namespace Soundux
|
|||||||
#endif
|
#endif
|
||||||
#if defined(__linux__)
|
#if defined(__linux__)
|
||||||
std::optional<int> getPpid(int pid);
|
std::optional<int> getPpid(int pid);
|
||||||
bool exec(const std::string &command, std::string &result);
|
|
||||||
#endif
|
#endif
|
||||||
|
bool exec(const std::string &command, std::string &result);
|
||||||
std::vector<std::string> splitByNewLine(const std::string &str);
|
std::vector<std::string> splitByNewLine(const std::string &str);
|
||||||
} // namespace Helpers
|
} // namespace Helpers
|
||||||
} // namespace Soundux
|
} // namespace Soundux
|
Loading…
x
Reference in New Issue
Block a user