This repository has been archived on 2024-10-22. You can view files and clone it, but cannot push or open issues or pull requests.
YimMenu/src/backend/looped_command.cpp

45 lines
911 B
C++
Raw Normal View History

#include "looped_command.hpp"
#include "fiber_pool.hpp"
namespace big
{
looped_command::looped_command(const std::string& name, const std::string& label, const std::string& description, bool& toggle) :
bool_command(name, label, description, toggle)
{
g_looped_commands.push_back(this);
}
void looped_command::enable()
{
if (!m_toggle)
{
m_toggle = true;
m_last_enabled = true;
g_fiber_pool->queue_job([this] { on_enable(); });
}
}
void looped_command::disable()
{
if (m_toggle)
{
m_toggle = false;
m_last_enabled = false;
g_fiber_pool->queue_job([this] { disable(); });
}
}
void looped_command::refresh()
{
if (m_toggle && !m_last_enabled)
{
m_last_enabled = true;
g_fiber_pool->queue_job([this] { on_enable(); });
}
else if (!m_toggle && m_last_enabled)
{
m_last_enabled = false;
g_fiber_pool->queue_job([this] { on_disable(); });
}
}
}