From cb2f5c154c1177da05e16f4c7c62312d6c80e352 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:25:27 +0100 Subject: [PATCH 1/3] feat(custon): restart_interval for continuous script --- man/waybar-custom.5.scd | 6 ++++++ src/modules/custom.cpp | 11 ++++++++++- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 0ae7f4c..92eda6c 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -33,6 +33,12 @@ Addressed by *custom/* You can update it manually with a signal. If no *interval* is defined, it is assumed that the out script loops it self. +*restart_interval*: ++ + typeof: integer ++ + The restart interval (in seconds). + Can't be used with the *interval* option, so only with continuous scripts. + Once the scripts exit, it'll be re-executed after the *restart_interval*. + *signal*: ++ typeof: integer ++ The signal number used to update the module. diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index ca09508..cbc865d 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -55,12 +55,21 @@ void waybar::modules::Custom::continuousWorker() { exit_code = WEXITSTATUS(util::command::close(fp_, pid_)); fp_ = nullptr; } - thread_.stop(); if (exit_code != 0) { output_ = {exit_code, ""}; dp.emit(); spdlog::error("{} stopped unexpectedly, is it endless?", name_); } + if (config_["restart_interval"].isUInt()) { + pid_ = -1; + fp_ = util::command::open(cmd, pid_); + if (!fp_) { + throw std::runtime_error("Unable to open " + cmd); + } + thread_.sleep_for(std::chrono::seconds(config_["restart_interval"].asUInt()); + } else { + thread_.stop(); + } return; } std::string output = buff; From d12ad1128ec606c6c46e851eaa69c2d50393cde2 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:30:22 +0100 Subject: [PATCH 2/3] fix: man --- man/waybar-custom.5.scd | 4 ++-- src/modules/custom.cpp | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/man/waybar-custom.5.scd b/man/waybar-custom.5.scd index 92eda6c..905dbc1 100644 --- a/man/waybar-custom.5.scd +++ b/man/waybar-custom.5.scd @@ -33,11 +33,11 @@ Addressed by *custom/* You can update it manually with a signal. If no *interval* is defined, it is assumed that the out script loops it self. -*restart_interval*: ++ +*restart-interval*: ++ typeof: integer ++ The restart interval (in seconds). Can't be used with the *interval* option, so only with continuous scripts. - Once the scripts exit, it'll be re-executed after the *restart_interval*. + Once the script exit, it'll be re-executed after the *restart-interval*. *signal*: ++ typeof: integer ++ diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index cbc865d..c81f192 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -60,13 +60,13 @@ void waybar::modules::Custom::continuousWorker() { dp.emit(); spdlog::error("{} stopped unexpectedly, is it endless?", name_); } - if (config_["restart_interval"].isUInt()) { + if (config_["restart-interval"].isUInt()) { pid_ = -1; fp_ = util::command::open(cmd, pid_); if (!fp_) { throw std::runtime_error("Unable to open " + cmd); } - thread_.sleep_for(std::chrono::seconds(config_["restart_interval"].asUInt()); + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt()); } else { thread_.stop(); } From ff36154c4bfd23651ba5bcc8e966f825b09ffad7 Mon Sep 17 00:00:00 2001 From: Alex Date: Wed, 25 Mar 2020 22:31:04 +0100 Subject: [PATCH 3/3] fix: typo --- src/modules/custom.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/modules/custom.cpp b/src/modules/custom.cpp index c81f192..24cfa71 100644 --- a/src/modules/custom.cpp +++ b/src/modules/custom.cpp @@ -66,7 +66,7 @@ void waybar::modules::Custom::continuousWorker() { if (!fp_) { throw std::runtime_error("Unable to open " + cmd); } - thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt()); + thread_.sleep_for(std::chrono::seconds(config_["restart-interval"].asUInt())); } else { thread_.stop(); }