#pragma once #include #include #include #include "common.hpp" #include "components/logger.hpp" POLYBAR_NS class script_runner { public: using interval = std::chrono::duration; script_runner(std::function on_update, const string& exec, const string& exec_if, bool tail, interval interval, const vector>& env); bool check_condition() const; interval process(); void clear_output(); void stop(); int get_pid() const; int get_counter() const; string get_output(); bool is_stopping() const; protected: bool set_output(const string&&); interval run_tail(); interval run(); private: const logger& m_log; const std::function m_on_update; const string m_exec; const string m_exec_if; const bool m_tail; const interval m_interval; const vector> m_env; std::mutex m_output_lock; string m_output; std::atomic_int m_counter{0}; std::atomic_bool m_stopping{false}; std::atomic_int m_pid{-1}; }; POLYBAR_NS_END