feat(ipc): Initial exec of configured hook
Adds a new config parameter `initial = N` that will make the hook at defined index N execute on start.
This commit is contained in:
parent
56b89d5a44
commit
7a26254844
@ -28,6 +28,7 @@ namespace modules {
|
||||
public:
|
||||
explicit ipc_module(const bar_settings&, string);
|
||||
|
||||
void start();
|
||||
void update() {}
|
||||
string get_output();
|
||||
bool build(builder* builder, const string& tag) const;
|
||||
@ -37,7 +38,7 @@ namespace modules {
|
||||
static constexpr auto TAG_OUTPUT = "<output>";
|
||||
vector<unique_ptr<hook>> m_hooks;
|
||||
string m_output;
|
||||
|
||||
size_t m_initial{0_z};
|
||||
map<mousebtn, string> m_actions;
|
||||
};
|
||||
}
|
||||
|
@ -21,7 +21,11 @@ namespace modules {
|
||||
}
|
||||
|
||||
if (m_hooks.empty()) {
|
||||
throw module_error("No ipc hooks defined");
|
||||
throw module_error("No hooks defined");
|
||||
}
|
||||
|
||||
if ((m_initial = m_conf.get(name(), "initial", m_initial)) && m_initial > m_hooks.size()) {
|
||||
throw module_error("Initial hook out of bounds (defined: " + to_string(m_hooks.size()) + ")");
|
||||
}
|
||||
|
||||
m_actions[mousebtn::LEFT] = m_conf.get(name(), "click-left", ""s);
|
||||
@ -33,6 +37,18 @@ namespace modules {
|
||||
m_formatter->add(DEFAULT_FORMAT, TAG_OUTPUT, {TAG_OUTPUT});
|
||||
}
|
||||
|
||||
/**
|
||||
* Start module and run first defined hook if configured to
|
||||
*/
|
||||
void ipc_module::start() {
|
||||
if (m_initial > 0_z) {
|
||||
auto command = command_util::make_command(m_hooks.at(m_initial - 1)->command);
|
||||
command->exec(false);
|
||||
command->tail([this](string line) { m_output = line; });
|
||||
}
|
||||
static_module::start();
|
||||
}
|
||||
|
||||
/**
|
||||
* Wrap the output with defined mouse actions
|
||||
*/
|
||||
@ -69,10 +85,10 @@ namespace modules {
|
||||
bool ipc_module::build(builder* builder, const string& tag) const {
|
||||
if (tag == TAG_OUTPUT) {
|
||||
builder->node(m_output);
|
||||
return true;
|
||||
} else {
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
/**
|
||||
|
Loading…
Reference in New Issue
Block a user