feat(script): add repeat interval for script failure and exec-if
This commit is contained in:
parent
50eac859fd
commit
5b2de60353
@ -57,6 +57,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
|
||||
- `polybar-msg hook` is deprecated in favor of using the hook action. `polybar-msg` will tell you the correct command to use.
|
||||
|
||||
### Added
|
||||
- Add repeat interval for script failure (`interval-fail`) and `exec-if` (`interval-if`) ([`#943`](https://github.com/polybar/polybar/issues/943), [`#2606`](https://github.com/polybar/polybar/issues/2606))
|
||||
- Support `px` and `pt` units everyhwere where before only a number of spaces or pixels could be specified. ([`#2578`](https://github.com/polybar/polybar/pull/2578), [`#1651`](https://github.com/polybar/polybar/issues/1651), [`#951`](https://github.com/polybar/polybar/issues/951))
|
||||
- `internal/alsa`: Right and middle click settings. ([`#2566`](https://github.com/polybar/polybar/issues/2566), [`#2573`](https://github.com/polybar/polybar/pull/2573))
|
||||
- `internal/network`:
|
||||
|
@ -13,7 +13,7 @@ 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,
|
||||
interval interval, const vector<pair<string, string>>& env);
|
||||
interval interval_success, interval interval_fail, const vector<pair<string, string>>& env);
|
||||
|
||||
bool check_condition() const;
|
||||
interval process();
|
||||
@ -44,7 +44,8 @@ class script_runner {
|
||||
const string m_exec;
|
||||
const string m_exec_if;
|
||||
const bool m_tail;
|
||||
const interval m_interval;
|
||||
const interval m_interval_success;
|
||||
const interval m_interval_fail;
|
||||
const vector<pair<string, string>> m_env;
|
||||
|
||||
std::mutex m_output_lock;
|
||||
|
@ -31,7 +31,9 @@ namespace modules {
|
||||
static constexpr auto FORMAT_FAIL = "format-fail";
|
||||
|
||||
const bool m_tail;
|
||||
const script_runner::interval m_interval{0};
|
||||
const script_runner::interval m_interval_success{0};
|
||||
const script_runner::interval m_interval_fail{0};
|
||||
const script_runner::interval m_interval_if{0};
|
||||
|
||||
script_runner m_runner;
|
||||
|
||||
|
@ -12,13 +12,14 @@
|
||||
POLYBAR_NS
|
||||
|
||||
script_runner::script_runner(std::function<void(void)> on_update, const string& exec, const string& exec_if, bool tail,
|
||||
interval interval, const vector<pair<string, string>>& env)
|
||||
interval interval_success, interval interval_fail, const vector<pair<string, string>>& env)
|
||||
: m_log(logger::make())
|
||||
, m_on_update(on_update)
|
||||
, m_exec(exec)
|
||||
, m_exec_if(exec_if)
|
||||
, m_tail(tail)
|
||||
, m_interval(interval)
|
||||
, m_interval_success(interval_success)
|
||||
, m_interval_fail(interval_fail)
|
||||
, m_env(env) {}
|
||||
|
||||
/**
|
||||
@ -60,7 +61,7 @@ int script_runner::get_counter() const {
|
||||
return m_counter;
|
||||
}
|
||||
|
||||
int script_runner::get_exit_status() const {
|
||||
int script_runner::get_exit_status() const {
|
||||
return m_exit_status;
|
||||
}
|
||||
|
||||
@ -131,9 +132,9 @@ script_runner::interval script_runner::run() {
|
||||
}
|
||||
|
||||
if (m_exit_status == 0) {
|
||||
return m_interval;
|
||||
return m_interval_success;
|
||||
} else {
|
||||
return std::max(m_interval, interval{1s});
|
||||
return std::max(m_interval_fail, interval{1s});
|
||||
}
|
||||
}
|
||||
|
||||
@ -168,9 +169,9 @@ script_runner::interval script_runner::run_tail() {
|
||||
auto exit_status = cmd.wait();
|
||||
|
||||
if (exit_status == 0) {
|
||||
return m_interval;
|
||||
return m_interval_success;
|
||||
} else {
|
||||
return std::max(m_interval, interval{1s});
|
||||
return std::max(m_interval_fail, interval{1s});
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,9 +9,11 @@ namespace modules {
|
||||
script_module::script_module(const bar_settings& bar, string name_)
|
||||
: module<script_module>(bar, move(name_))
|
||||
, m_tail(m_conf.get(name(), "tail", false))
|
||||
, m_interval(m_conf.get<script_runner::interval>(name(), "interval", m_tail ? 0s : 5s))
|
||||
, m_interval_success(m_conf.get<script_runner::interval>(name(), "interval", m_tail ? 0s : 5s))
|
||||
, m_interval_fail(m_conf.get<script_runner::interval>(name(), "interval-fail", m_interval_success))
|
||||
, m_interval_if(m_conf.get<script_runner::interval>(name(), "interval-if", m_interval_success))
|
||||
, m_runner([this]() { broadcast(); }, m_conf.get(name(), "exec", ""s), m_conf.get(name(), "exec-if", ""s), m_tail,
|
||||
m_interval, m_conf.get_with_prefix(name(), "env-")) {
|
||||
m_interval_success, m_interval_fail, m_conf.get_with_prefix(name(), "env-")) {
|
||||
// Load configured click handlers
|
||||
m_actions[mousebtn::LEFT] = m_conf.get(name(), "click-left", ""s);
|
||||
m_actions[mousebtn::MIDDLE] = m_conf.get(name(), "click-middle", ""s);
|
||||
@ -47,7 +49,7 @@ namespace modules {
|
||||
sleep_time = m_runner.process();
|
||||
} else {
|
||||
m_runner.clear_output();
|
||||
sleep_time = std::max(m_interval, script_runner::interval(1s));
|
||||
sleep_time = std::max(m_interval_if, script_runner::interval(1s));
|
||||
}
|
||||
|
||||
if (m_runner.is_stopping()) {
|
||||
|
Loading…
Reference in New Issue
Block a user