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:
|
2022-04-03 11:11:13 +00:00
|
|
|
struct data {
|
|
|
|
int counter{0};
|
|
|
|
int pid{-1};
|
|
|
|
int exit_status{0};
|
|
|
|
string output;
|
|
|
|
};
|
|
|
|
|
|
|
|
using on_update = std::function<void(const data&)>;
|
2021-10-02 23:27:11 +00:00
|
|
|
using interval = std::chrono::duration<double>;
|
2022-04-03 11:11:13 +00:00
|
|
|
|
2022-04-03 18:08:01 +00:00
|
|
|
script_runner(on_update on_update, const string& exec, const string& exec_if, bool tail, 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();
|
|
|
|
|
|
|
|
bool is_stopping() const;
|
|
|
|
|
|
|
|
protected:
|
2022-02-23 14:01:28 +00:00
|
|
|
bool set_output(string&&);
|
2022-04-03 11:11:13 +00:00
|
|
|
bool set_exit_status(int);
|
2021-10-02 23:27:11 +00:00
|
|
|
|
|
|
|
interval run_tail();
|
|
|
|
interval run();
|
|
|
|
|
|
|
|
private:
|
|
|
|
const logger& m_log;
|
|
|
|
|
2022-04-03 11:11:13 +00:00
|
|
|
const on_update m_on_update;
|
2021-10-02 23:27:11 +00:00
|
|
|
|
|
|
|
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;
|
|
|
|
|
2022-04-03 11:11:13 +00:00
|
|
|
data m_data;
|
2021-10-02 23:27:11 +00:00
|
|
|
std::atomic_bool m_stopping{false};
|
|
|
|
};
|
|
|
|
|
|
|
|
POLYBAR_NS_END
|