fix(ipc): Clear content if no output is produced

Before, if the command produced no output, the `m_output` field would
not have been overwritten and the old output was displayed.

But since this is an explicit trigger of the hook, the user would expect
the output to be updated to whatever the script produces (even if that
is nothing).

Ref: https://www.reddit.com/r/Polybar/comments/e9a8ww
This commit is contained in:
patrick96 2019-12-11 21:32:43 +01:00 committed by Patrick Ziegler
parent a902b5a449
commit 1fe679d6b3

View File

@ -1,6 +1,6 @@
#include "modules/ipc.hpp" #include "modules/ipc.hpp"
#include "components/ipc.hpp"
#include "components/ipc.hpp"
#include "modules/meta/base.inl" #include "modules/meta/base.inl"
POLYBAR_NS POLYBAR_NS
@ -112,6 +112,8 @@ namespace modules {
m_log.info("%s: Found matching hook (%s)", name(), hook->payload); m_log.info("%s: Found matching hook (%s)", name(), hook->payload);
try { try {
// Clear the output in case the command produces no output
m_output.clear();
auto command = command_util::make_command(hook->command); auto command = command_util::make_command(hook->command);
command->exec(false); command->exec(false);
command->tail([this](string line) { m_output = line; }); command->tail([this](string line) { m_output = line; });
@ -123,6 +125,6 @@ namespace modules {
broadcast(); broadcast();
} }
} }
} } // namespace modules
POLYBAR_NS_END POLYBAR_NS_END