Use boost process v2 for boost >= 1.80.0

This commit is contained in:
badaix 2024-03-31 18:45:25 +02:00
parent a1acf5e86b
commit 68c4853a40
2 changed files with 27 additions and 1 deletions

View file

@ -268,7 +268,7 @@ jobs:
key: ${{ runner.os }}-dependencies
- name: dependencies
if: steps.cache-dependencies.outputs.cache-hit != 'true'
run: vcpkg.exe install libflac libvorbis soxr opus boost-asio --triplet x64-windows
run: vcpkg.exe install libflac libvorbis soxr opus boost-asio boost-process --triplet x64-windows
- name: configure
run: |
echo vcpkg installation root: ${env:VCPKG_INSTALLATION_ROOT}

View file

@ -28,11 +28,22 @@
// 3rd party headers
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wunused-parameter"
#if BOOST_VERSION >= 108000
#if defined(__clang__) && (__clang_major__ >= 13) && !((__clang_major__ == 13) && (__clang_minor__ == 0) && (__clang_patchlevel__ == 0))
#pragma GCC diagnostic ignored "-Wunused-but-set-variable"
#endif
#pragma GCC diagnostic ignored "-Wpedantic"
#include <boost/process/v2.hpp>
#else
#pragma GCC diagnostic ignored "-Wpragmas"
#pragma GCC diagnostic ignored "-Wunused-result"
#pragma GCC diagnostic ignored "-Wmissing-braces"
#pragma GCC diagnostic ignored "-Wnarrowing"
#pragma GCC diagnostic ignored "-Wc++11-narrowing"
#include <boost/process/args.hpp>
#include <boost/process/child.hpp>
#include <boost/process/exe.hpp>
#endif
#pragma GCC diagnostic pop
// standard headers
@ -233,6 +244,8 @@ void Player::setVolume(const Volume& volume)
}
else if (settings_.mixer.mode == ClientSettings::Mixer::Mode::script)
{
#if BOOST_VERSION >= 108000
// Use Boost process v2 if Boost >= 1.80.0 is available
static std::optional<Volume> pending_volume_setting;
static bool script_running = false;
if (script_running)
@ -268,6 +281,19 @@ void Player::setVolume(const Volume& volume)
LOG(ERROR, LOG_TAG) << "Failed to run script '" + settings_.mixer.parameter + "', error: " << e.what() << "\n";
}
}
#else
// Use Boost process v1
try
{
using namespace boost::process;
child c(exe = settings_.mixer.parameter, args = {"--volume", cpt::to_string(volume), "--mute", mute ? "true" : "false"});
c.detach();
}
catch (const std::exception& e)
{
LOG(ERROR, LOG_TAG) << "Failed to run script '" + settings_.mixer.parameter + "', error: " << e.what() << "\n";
}
#endif
}
}