From 41d41ca8df10c94315110d5cda79f00ca23c79ab Mon Sep 17 00:00:00 2001 From: Maxim Kolesnikov Date: Sun, 3 Apr 2022 18:11:13 +0700 Subject: [PATCH] fix(script): output timing inconsistencies (#2667) Fixes #2650 --- CHANGELOG.md | 1 + include/adapters/script_runner.hpp | 29 +++++++------ include/modules/script.hpp | 8 +++- src/adapters/script_runner.cpp | 66 ++++++++++++++++-------------- src/modules/script.cpp | 36 +++++++++++----- 5 files changed, 82 insertions(+), 58 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 50a763e0..10761c2b 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Positioning in awesomeWM ([`#2651`](https://github.com/polybar/polybar/pull/2651)) - `internal/xworkspaces`: The module sometimes crashed polybar when windows were closed. ([`#2655`](https://github.com/polybar/polybar/pull/2655)) - Mouseover error when only one cursor is defined ([`#2656`](https://github.com/polybar/polybar/pull/2656)) +- Timing inconsistencies with `custom/script` output ([`#2650`](https://github.com/polybar/polybar/issues/2650), first described at [`#2630`](https://github.com/polybar/polybar/pull/2630)) ## [3.6.1] - 2022-03-05 ### Build diff --git a/include/adapters/script_runner.hpp b/include/adapters/script_runner.hpp index a2322e50..5bb5a616 100644 --- a/include/adapters/script_runner.hpp +++ b/include/adapters/script_runner.hpp @@ -11,9 +11,18 @@ POLYBAR_NS class script_runner { public: + struct data { + int counter{0}; + int pid{-1}; + int exit_status{0}; + string output; + }; + + using on_update = std::function; 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); + + script_runner(on_update on_update, const string& exec, const string& exec_if, bool tail, interval interval, + const vector>& env); bool check_condition() const; interval process(); @@ -22,16 +31,11 @@ class script_runner { void stop(); - int get_pid() const; - int get_counter() const; - int get_exit_status() const; - - string get_output(); - bool is_stopping() const; protected: bool set_output(string&&); + bool set_exit_status(int); interval run_tail(); interval run(); @@ -39,7 +43,7 @@ class script_runner { private: const logger& m_log; - const std::function m_on_update; + const on_update m_on_update; const string m_exec; const string m_exec_if; @@ -47,13 +51,8 @@ class script_runner { const interval m_interval; const vector> m_env; - std::mutex m_output_lock; - string m_output; - - std::atomic_int m_counter{0}; + data m_data; std::atomic_bool m_stopping{false}; - std::atomic_int m_pid{-1}; - std::atomic_int m_exit_status{0}; }; POLYBAR_NS_END diff --git a/include/modules/script.hpp b/include/modules/script.hpp index 94308249..47c20a85 100644 --- a/include/modules/script.hpp +++ b/include/modules/script.hpp @@ -26,6 +26,8 @@ namespace modules { bool check_condition(); private: + void handle_runner_update(const script_runner::data&); + static constexpr auto TAG_LABEL = "