From 1189f86c1aa59c489ac19038df9b4147d5869188 Mon Sep 17 00:00:00 2001
From: LordGrey <48840279+Lord-Grey@users.noreply.github.com>
Date: Thu, 22 Dec 2022 12:40:39 +0100
Subject: [PATCH] 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
---
.github/workflows/pull-request.yml | 9 +-
.github/workflows/push-master.yml | 9 +-
CHANGELOG.md | 11 +
assets/webconfig/i18n/en.json | 3 +
assets/webconfig/index.html | 33 ++
assets/webconfig/js/hyperion.js | 15 +
assets/webconfig/js/settings.js | 15 +
include/api/JsonAPI.h | 26 ++
include/hyperion/BGEffectHandler.h | 10 +-
include/hyperion/ComponentRegister.h | 24 +-
include/hyperion/Hyperion.h | 26 ++
include/hyperion/HyperionIManager.h | 27 +-
libsrc/api/JSONRPC_schema/schema-system.json | 20 ++
libsrc/api/JSONRPC_schema/schema.json | 2 +-
libsrc/api/JSONRPC_schemas.qrc | 3 +-
libsrc/api/JsonAPI.cpp | 63 +++-
libsrc/hyperion/ComponentRegister.cpp | 82 +++--
libsrc/hyperion/Hyperion.cpp | 21 +-
libsrc/hyperion/HyperionIManager.cpp | 34 +-
resources/icons/resume.svg | 1 +
resources/icons/suspend.svg | 3 +
src/hyperion-remote/JsonConnection.cpp | 72 +++++
src/hyperion-remote/JsonConnection.h | 30 ++
src/hyperion-remote/hyperion-remote.cpp | 50 ++-
src/hyperiond/CMakeLists.txt | 13 +
src/hyperiond/SuspendHandler.cpp | 312 +++++++++++++++++++
src/hyperiond/SuspendHandler.h | 79 +++++
src/hyperiond/hyperiond.cpp | 5 +
src/hyperiond/hyperiond.h | 10 +-
src/hyperiond/main.cpp | 17 +-
src/hyperiond/systray.cpp | 30 +-
src/hyperiond/systray.h | 6 +
32 files changed, 994 insertions(+), 67 deletions(-)
create mode 100644 libsrc/api/JSONRPC_schema/schema-system.json
create mode 100644 resources/icons/resume.svg
create mode 100644 resources/icons/suspend.svg
create mode 100644 src/hyperiond/SuspendHandler.cpp
create mode 100644 src/hyperiond/SuspendHandler.h
diff --git a/.github/workflows/pull-request.yml b/.github/workflows/pull-request.yml
index 92870ad1..4aab0779 100644
--- a/.github/workflows/pull-request.yml
+++ b/.github/workflows/pull-request.yml
@@ -150,11 +150,16 @@ jobs:
with:
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
key: ${{ runner.os }}-chocolatey
+
+# - name: Install Python
+# shell: powershell
+# run: |
+# choco install --no-progress python -y
- - name: Install Python, OpenSSL, DirectX SDK
+ - name: Install OpenSSL, DirectX SDK
shell: powershell
run: |
- choco install --no-progress python openssl directx-sdk -y
+ choco install --no-progress openssl directx-sdk -y
- name: Install libjpeg-turbo
run: |
diff --git a/.github/workflows/push-master.yml b/.github/workflows/push-master.yml
index 44d99d7e..78584474 100644
--- a/.github/workflows/push-master.yml
+++ b/.github/workflows/push-master.yml
@@ -116,10 +116,15 @@ jobs:
path: C:\Users\runneradmin\AppData\Local\Temp\chocolatey
key: ${{ runner.os }}-chocolatey
- - name: Install Python, OpenSSL, DirectX SDK
+# - name: Install Python
+# shell: powershell
+# run: |
+# choco install --no-progress python -y
+
+ - name: Install OpenSSL, DirectX SDK
shell: powershell
run: |
- choco install --no-progress python openssl directx-sdk -y
+ choco install --no-progress openssl directx-sdk -y
- name: Install libjpeg-turbo
run: |
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 7c8f8055..71a372a2 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -10,10 +10,21 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Added
+- Allow to Disable / Enable all instances (#970) by
+ - Suspend/Resume support for Linux and Windows (#1493,#1282, #978).
+ Suspend/Resume/Restart is supported via API, UI, Systray and hyperion-remote
+ - Idle scenario via Screen Locking (Linux/Windows), Screensaver invokation (Linux), hyperion-remote or API
+ In Idle, all instances, components will be disabled besides the output processing (LED-Devices, smoothing).
+ The current priorities will be cleared and the background effect per instance will be executed, if enabled.
+ - Commands toogleSuspend and toggleIdle allow to flip between modes, e.g. might be used to trigger modes by a remote
+- Add instance# in API response (#1504)
+
### Changed
### Fixed
+- Restart correctly, if running as service (#1368)
+
## Removed
## [2.0.14](https://github.com/hyperion-project/hyperion.ng/releases/tag/2.0.14) - 2022-11
diff --git a/assets/webconfig/i18n/en.json b/assets/webconfig/i18n/en.json
index 1ae5e0e4..bb3453b8 100644
--- a/assets/webconfig/i18n/en.json
+++ b/assets/webconfig/i18n/en.json
@@ -13,6 +13,9 @@
"infoDialog_password_current_text": "Current password",
"infoDialog_password_minimum_length": "Passwords must be minimum 8 characters.",
"infoDialog_password_new_text": "New password",
+ "InfoDialog_systemSuspend_title": "Suspend",
+ "InfoDialog_systemResume_title": "Resume",
+ "InfoDialog_systemRestart_title": "Restart",
"infoDialog_username_text": "Username",
"about_3rd_party_licenses": "3rd party licenses",
"about_3rd_party_licenses_error": "We had trouble collecting 3rd party licenses information from web.
Please follow this link to the GitHub Resource.",
diff --git a/assets/webconfig/index.html b/assets/webconfig/index.html
index 44313cf5..bb1a7d0b 100644
--- a/assets/webconfig/index.html
+++ b/assets/webconfig/index.html
@@ -213,6 +213,39 @@
+
+
+
+
+
+
+
diff --git a/assets/webconfig/js/hyperion.js b/assets/webconfig/js/hyperion.js
index 5193da05..7bd59c65 100644
--- a/assets/webconfig/js/hyperion.js
+++ b/assets/webconfig/js/hyperion.js
@@ -318,6 +318,21 @@ function requestSysInfo()
sendToHyperion("sysinfo");
}
+function requestSystemSuspend()
+{
+ sendToHyperion("system","suspend");
+}
+
+function requestSystemResume()
+{
+ sendToHyperion("system","resume");
+}
+
+function requestSystemRestart()
+{
+ sendToHyperion("system","restart");
+}
+
function requestServerConfigSchema()
{
sendToHyperion("config","getschema");
diff --git a/assets/webconfig/js/settings.js b/assets/webconfig/js/settings.js
index c07e2beb..003dcf7c 100644
--- a/assets/webconfig/js/settings.js
+++ b/assets/webconfig/js/settings.js
@@ -75,6 +75,21 @@ $(document).ready(function () {
changePassword();
});
+ //Suspend Hyperion
+ $('#btn_systemSuspend').off().on('click', function () {
+ requestSystemSuspend();
+ });
+
+ //Resume Hyperion
+ $('#btn_systemResume').off().on('click', function () {
+ requestSystemResume();
+ });
+
+ //Restart Hyperion
+ $('#btn_systemRestart').off().on('click', function () {
+ requestSystemRestart();
+ });
+
//Lock Ui
$('#btn_lock_ui').off().on('click', function () {
removeStorage('loginToken');
diff --git a/include/api/JsonAPI.h b/include/api/JsonAPI.h
index ca8becf9..6346ce72 100644
--- a/include/api/JsonAPI.h
+++ b/include/api/JsonAPI.h
@@ -99,6 +99,26 @@ signals:
///
void forwardJsonMessage(QJsonObject);
+ ///
+ /// Signal emits whenever a suspend/resume request for all instances should be forwarded
+ ///
+ void suspendAll(bool isSuspend);
+
+ ///
+ /// Signal emits whenever a toggle suspend/resume request for all instances should be forwarded
+ ///
+ void toggleSuspendAll();
+
+ ///
+ /// Signal emits whenever a idle mode request for all instances should be forwarded
+ ///
+ void idleAll(bool isIdle);
+
+ ///
+ /// Signal emits whenever a toggle idle/working mode request for all instances should be forwarded
+ ///
+ void toggleIdleAll();
+
private:
// true if further callbacks are forbidden (http)
bool _noListener;
@@ -298,6 +318,12 @@ private:
///
void handleServiceCommand(const QJsonObject &message, const QString &command, int tan);
+ /// Handle an incoming JSON message for actions related to the overall Hyperion system
+ ///
+ /// @param message the incoming message
+ ///
+ void handleSystemCommand(const QJsonObject &message, const QString &command, int tan);
+
///
/// Handle an incoming JSON message of unknown type
///
diff --git a/include/hyperion/BGEffectHandler.h b/include/hyperion/BGEffectHandler.h
index 1dc0b1ef..96de909b 100644
--- a/include/hyperion/BGEffectHandler.h
+++ b/include/hyperion/BGEffectHandler.h
@@ -20,6 +20,7 @@ public:
, _hyperion(hyperion)
, _prioMuxer(_hyperion->getMuxerInstance())
, _isBgEffectEnabled(false)
+ , _isSuspended(false)
{
QString subComponent = parent()->property("instance").toString();
_log = Logger::getInstance("HYPERION", subComponent);
@@ -33,6 +34,11 @@ public:
this->handlePriorityUpdate();
});
+ // listen for suspend/resume requests, to not start a background effect when system goes into suspend mode
+ connect(_hyperion, &Hyperion::suspendRequest, this, [=] (bool isSuspended) {
+ _isSuspended = isSuspended;
+ });
+
// initialization
handleSettingsUpdate(settings::BGEFFECT, _hyperion->getSetting(settings::BGEFFECT));
}
@@ -109,7 +115,7 @@ private slots:
Debug(_log,"Stop background (color-) effect as it moved out of scope");
_hyperion->clear(PriorityMuxer::BG_PRIORITY);
}
- else if (_prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectEnabled)
+ else if (!_isSuspended && _prioMuxer->getCurrentPriority() == PriorityMuxer::LOWEST_PRIORITY && _isBgEffectEnabled)
{
Debug(_log,"Start background (color-) effect as it moved in scope");
emit handleSettingsUpdate (settings::BGEFFECT, _bgEffectConfig);
@@ -126,6 +132,8 @@ private:
QJsonDocument _bgEffectConfig;
bool _isBgEffectEnabled;
+
+ bool _isSuspended;
};
#endif // BGEFFECTHANDLER_H
diff --git a/include/hyperion/ComponentRegister.h b/include/hyperion/ComponentRegister.h
index 9512923d..aa202340 100644
--- a/include/hyperion/ComponentRegister.h
+++ b/include/hyperion/ComponentRegister.h
@@ -7,12 +7,15 @@
#include