mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
Add Suspend/Resume support (#1535)
* Add Suspend/Resume support * Support Suspend/Resume/Restart via API, UI and Systray * Support screen lock/unlock scenario * Handle idle scenario * Align with fix for #1368 * Update Windows build * Refactor SuspendHandler to maintain state * Do not start BG-Effect, if system goes into suspend mode * Correct Idle and Resume interaction
This commit is contained in:
@@ -55,12 +55,13 @@ ComponentRegister::ComponentRegister(Hyperion* hyperion)
|
||||
vect << COMP_FORWARDER;
|
||||
#endif
|
||||
|
||||
for(auto e : vect)
|
||||
for(auto e : qAsConst(vect))
|
||||
{
|
||||
_componentStates.emplace(e, (e == COMP_ALL));
|
||||
}
|
||||
|
||||
connect(_hyperion, &Hyperion::compStateChangeRequest, this, &ComponentRegister::handleCompStateChangeRequest);
|
||||
connect(_hyperion, &Hyperion::compStateChangeRequestAll, this, &ComponentRegister::handleCompStateChangeRequestAll);
|
||||
}
|
||||
|
||||
ComponentRegister::~ComponentRegister()
|
||||
@@ -72,56 +73,93 @@ int ComponentRegister::isComponentEnabled(hyperion::Components comp) const
|
||||
return (_componentStates.count(comp)) ? _componentStates.at(comp) : -1;
|
||||
}
|
||||
|
||||
void ComponentRegister::setNewComponentState(hyperion::Components comp, bool activated)
|
||||
void ComponentRegister::setNewComponentState(hyperion::Components comp, bool isActive)
|
||||
{
|
||||
|
||||
if (_componentStates.count(comp) > 0)
|
||||
{
|
||||
if (_componentStates[comp] != activated)
|
||||
if (_componentStates[comp] != isActive)
|
||||
{
|
||||
Debug(_log, "%s: %s", componentToString(comp), (activated ? "enabled" : "disabled"));
|
||||
_componentStates[comp] = activated;
|
||||
Debug(_log, "%s: %s", componentToString(comp), (isActive ? "enabled" : "disabled"));
|
||||
_componentStates[comp] = isActive;
|
||||
// emit component has changed state
|
||||
emit updatedComponentState(comp, activated);
|
||||
emit updatedComponentState(comp, isActive);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentRegister::handleCompStateChangeRequest(hyperion::Components comps, bool activated)
|
||||
void ComponentRegister::handleCompStateChangeRequest(hyperion::Components comps, bool isActive)
|
||||
{
|
||||
if(comps == COMP_ALL && !_inProgress)
|
||||
if(comps == COMP_ALL )
|
||||
{
|
||||
handleCompStateChangeRequestAll(isActive,{});
|
||||
}
|
||||
}
|
||||
|
||||
void ComponentRegister::handleCompStateChangeRequestAll(bool isActive, const ComponentList& excludeList)
|
||||
{
|
||||
if (!_inProgress)
|
||||
{
|
||||
_inProgress = true;
|
||||
if(!activated && _prevComponentStates.empty())
|
||||
if(!isActive)
|
||||
{
|
||||
Debug(_log,"Disable Hyperion, store current component states");
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
Debug(_log,"Disable Hyperion instance, store current components' state");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log,"Disable selected Hyperion components, store their current state");
|
||||
}
|
||||
|
||||
for(const auto &comp : _componentStates)
|
||||
{
|
||||
// save state
|
||||
_prevComponentStates.emplace(comp.first, comp.second);
|
||||
// disable if enabled
|
||||
if(comp.second)
|
||||
if (!excludeList.contains(comp.first) && comp.first != COMP_ALL)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, false);
|
||||
// save state
|
||||
_prevComponentStates.emplace(comp.first, comp.second);
|
||||
// disable if enabled
|
||||
if(comp.second)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, false);
|
||||
}
|
||||
}
|
||||
}
|
||||
setNewComponentState(COMP_ALL, false);
|
||||
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
setNewComponentState(COMP_ALL, false);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(activated && !_prevComponentStates.empty())
|
||||
if(isActive && !_prevComponentStates.empty())
|
||||
{
|
||||
Debug(_log,"Enable Hyperion, recover previous component states");
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
Debug(_log,"Enable Hyperion instance, restore components' previous state");
|
||||
}
|
||||
else
|
||||
{
|
||||
Debug(_log,"Enable selected Hyperion components, restore their previous state");
|
||||
}
|
||||
|
||||
for(const auto &comp : _prevComponentStates)
|
||||
{
|
||||
// if comp was enabled, enable again
|
||||
if(comp.second)
|
||||
if (!excludeList.contains(comp.first) && comp.first != COMP_ALL)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, true);
|
||||
// if comp was enabled, enable again
|
||||
if(comp.second)
|
||||
{
|
||||
emit _hyperion->compStateChangeRequest(comp.first, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
_prevComponentStates.clear();
|
||||
setNewComponentState(COMP_ALL, true);
|
||||
if (excludeList.isEmpty())
|
||||
{
|
||||
setNewComponentState(COMP_ALL, true);
|
||||
}
|
||||
}
|
||||
}
|
||||
_inProgress = false;
|
||||
|
@@ -75,6 +75,8 @@ Hyperion::Hyperion(quint8 instance, bool readonlyMode)
|
||||
#endif
|
||||
, _readOnlyMode(readonlyMode)
|
||||
{
|
||||
qRegisterMetaType<ComponentList>("ComponentList");
|
||||
|
||||
QString subComponent = "I"+QString::number(instance);
|
||||
this->setProperty("instance", (QString) subComponent);
|
||||
|
||||
@@ -117,8 +119,9 @@ void Hyperion::start()
|
||||
connect(_muxer, &PriorityMuxer::visiblePriorityChanged, this, &Hyperion::handleSourceAvailability);
|
||||
connect(_muxer, &PriorityMuxer::visibleComponentChanged, this, &Hyperion::handleVisibleComponentChanged);
|
||||
|
||||
// listens for ComponentRegister changes of COMP_ALL to perform core enable/disable actions
|
||||
// connect(&_componentRegister, &ComponentRegister::updatedComponentState, this, &Hyperion::updatedComponentState);
|
||||
// listen for suspend/resume, idle requests to perform core activation/deactivation actions
|
||||
connect(this, &Hyperion::suspendRequest, this, &Hyperion::setSuspend);
|
||||
connect(this, &Hyperion::idleRequest, this, &Hyperion::setIdle);
|
||||
|
||||
// listen for settings updates of this instance (LEDS & COLOR)
|
||||
connect(_settingsManager, &SettingsManager::settingsChanged, this, &Hyperion::handleSettingsUpdate);
|
||||
@@ -377,6 +380,20 @@ int Hyperion::isComponentEnabled(hyperion::Components comp) const
|
||||
return _componentRegister->isComponentEnabled(comp);
|
||||
}
|
||||
|
||||
void Hyperion::setSuspend(bool isSuspend)
|
||||
{
|
||||
bool enable = !isSuspend;
|
||||
emit compStateChangeRequestAll(enable);
|
||||
}
|
||||
|
||||
void Hyperion::setIdle(bool isIdle)
|
||||
{
|
||||
clear(-1);
|
||||
|
||||
bool enable = !isIdle;
|
||||
emit compStateChangeRequestAll(enable, {hyperion::COMP_LEDDEVICE, hyperion::COMP_SMOOTHING} );
|
||||
}
|
||||
|
||||
void Hyperion::registerInput(int priority, hyperion::Components component, const QString& origin, const QString& owner, unsigned smooth_cfg)
|
||||
{
|
||||
_muxer->registerInput(priority, component, origin, owner, smooth_cfg);
|
||||
|
@@ -63,13 +63,43 @@ void HyperionIManager::stopAll()
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::toggleStateAllInstances(bool pause)
|
||||
void HyperionIManager::suspend()
|
||||
{
|
||||
Info(_log,"Suspend all instances and enabled components");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->suspendRequest(true);
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::resume()
|
||||
{
|
||||
Info(_log,"Resume all instances and enabled components");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->suspendRequest(false);
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::toggleIdle(bool isIdle)
|
||||
{
|
||||
Info(_log,"Put all instances in %s state", isIdle ? "idle" : "working");
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->idleRequest(isIdle);
|
||||
}
|
||||
}
|
||||
|
||||
void HyperionIManager::toggleStateAllInstances(bool enable)
|
||||
{
|
||||
// copy the instances due to loop corruption, even with .erase() return next iter
|
||||
QMap<quint8, Hyperion*> instCopy = _runningInstances;
|
||||
for(const auto instance : instCopy)
|
||||
{
|
||||
emit instance->compStateChangeRequest(hyperion::COMP_ALL, pause);
|
||||
emit instance->compStateChangeRequest(hyperion::COMP_ALL, enable);
|
||||
}
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user