2021-10-02 23:27:11 +00:00
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <chrono>
|
|
|
|
#include <mutex>
|
|
|
|
|
|
|
|
#include "common.hpp"
|
|
|
|
#include "components/logger.hpp"
|
|
|
|
|
|
|
|
POLYBAR_NS
|
|
|
|
|
|
|
|
class script_runner {
|
|
|
|
public:
|
|
|
|
using interval = std::chrono::duration<double>;
|
|
|
|
script_runner(std::function<void(void)> on_update, const string& exec, const string& exec_if, bool tail,
|
2022-03-06 08:34:12 +00:00
|
|
|
interval interval_success, interval interval_fail, const vector<pair<string, string>>& env);
|
2021-10-02 23:27:11 +00:00
|
|
|
|
|
|
|
bool check_condition() const;
|
|
|
|
interval process();
|
|
|
|
|
|
|
|
void clear_output();
|
|
|
|
|
|
|
|
void stop();
|
|
|
|
|
|
|
|
int get_pid() const;
|
|
|
|
int get_counter() const;
|
2022-02-23 14:01:28 +00:00
|
|
|
int get_exit_status() const;
|
2021-10-02 23:27:11 +00:00
|
|
|
|
|
|
|
string get_output();
|
|
|
|
|
|
|
|
bool is_stopping() const;
|
|
|
|
|
|
|
|
protected:
|
2022-02-23 14:01:28 +00:00
|
|
|
bool set_output(string&&);
|
2021-10-02 23:27:11 +00:00
|
|
|
|
|
|
|
interval run_tail();
|
|
|
|
interval run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const logger& m_log;
|
|
|
|
|
|
|
|
const std::function<void(void)> m_on_update;
|
|
|
|
|
|
|
|
const string m_exec;
|
|
|
|
const string m_exec_if;
|
|
|
|
const bool m_tail;
|
2022-03-06 08:34:12 +00:00
|
|
|
const interval m_interval_success;
|
|
|
|
const interval m_interval_fail;
|
2021-10-02 23:27:11 +00:00
|
|
|
const vector<pair<string, string>> 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};
|
2022-02-23 14:01:28 +00:00
|
|
|
std::atomic_int m_exit_status{0};
|
2021-10-02 23:27:11 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|