mirror of
				https://github.com/hyperion-project/hyperion.ng.git
				synced 2025-03-01 10:33:28 +00:00 
			
		
		
		
	* Refactor to fix #1671 * Add GUI/NonGUI mode to info page * Do not show lock config, if in non-UI mode * Updae Changelog * Correct includes * Remove unused variable * use ninja generator under macos --------- Co-authored-by: Paulchen-Panther <16664240+Paulchen-Panther@users.noreply.github.com>
This commit is contained in:
		@@ -52,6 +52,7 @@ Note: The wizard will configure an APIv2 capable bridge always with Entertainmen
 | 
			
		||||
- Fixed that the Matrix effect finds its image - Thanks @lsellens
 | 
			
		||||
- MDNSBrower - Fixed, if timeout while resolving host occurs
 | 
			
		||||
- Non image updates ignored blacklisted LEDs (#1634)
 | 
			
		||||
- Fixed that Windows OsEvents failed in non-GUI mode (#1671)
 | 
			
		||||
 | 
			
		||||
##### LED-Devices
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
$(document).ready(function () {
 | 
			
		||||
  performTranslation();
 | 
			
		||||
 | 
			
		||||
  let isGuiMode = window.sysInfo.hyperion.isGuiMode;
 | 
			
		||||
  const CEC_ENABLED = (jQuery.inArray("cec", window.serverInfo.services) !== -1);
 | 
			
		||||
 | 
			
		||||
  let conf_editor_osEvents = null;
 | 
			
		||||
@@ -76,6 +77,12 @@ $(document).ready(function () {
 | 
			
		||||
    osEvents: window.schema.osEvents
 | 
			
		||||
  }, true, true);
 | 
			
		||||
 | 
			
		||||
  conf_editor_osEvents.on('ready', function () {
 | 
			
		||||
    if (!isGuiMode) {
 | 
			
		||||
      showInputOptionsForKey(conf_editor_osEvents, "osEvents", "suspendEnable", false);
 | 
			
		||||
    }
 | 
			
		||||
  });
 | 
			
		||||
 | 
			
		||||
  conf_editor_osEvents.on('change', function () {
 | 
			
		||||
    conf_editor_osEvents.validate().length || window.readOnlyMode ? $('#btn_submit_os_events').prop('disabled', true) : $('#btn_submit_os_events').prop('disabled', false);
 | 
			
		||||
  });
 | 
			
		||||
 
 | 
			
		||||
@@ -1224,6 +1224,7 @@ function getSystemInfo() {
 | 
			
		||||
  info += '- Avail Services:    ' + window.serverInfo.services + '\n';
 | 
			
		||||
  info += '- Config path:       ' + shy.rootPath + '\n';
 | 
			
		||||
  info += '- Database:          ' + (shy.readOnlyMode ? "ready-only" : "read/write") + '\n';
 | 
			
		||||
  info += '- Mode:              ' + (shy.isGuiMode ? "GUI" : "Non-GUI") + '\n';
 | 
			
		||||
 | 
			
		||||
  info += '\n';
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,7 @@
 | 
			
		||||
#include <QAbstractEventDispatcher>
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#include <powrprof.h>
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
#include <utils/settings.h>
 | 
			
		||||
@@ -21,8 +22,9 @@ class OsEventHandlerBase : public QObject
 | 
			
		||||
	Q_OBJECT
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
 | 
			
		||||
	OsEventHandlerBase();
 | 
			
		||||
	~OsEventHandlerBase() override;
 | 
			
		||||
	virtual ~OsEventHandlerBase();
 | 
			
		||||
 | 
			
		||||
public slots:
 | 
			
		||||
	void suspend(bool sleep);
 | 
			
		||||
@@ -46,6 +48,8 @@ protected:
 | 
			
		||||
	bool _isSuspendRegistered;
 | 
			
		||||
	bool _isLockRegistered;
 | 
			
		||||
 | 
			
		||||
	bool _isService;
 | 
			
		||||
 | 
			
		||||
	Logger* _log{};
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
@@ -53,10 +57,11 @@ protected:
 | 
			
		||||
 | 
			
		||||
class OsEventHandlerWindows : public OsEventHandlerBase, public QAbstractNativeEventFilter
 | 
			
		||||
{
 | 
			
		||||
 | 
			
		||||
public:
 | 
			
		||||
	OsEventHandlerWindows();
 | 
			
		||||
	~OsEventHandlerWindows() override;
 | 
			
		||||
	~OsEventHandlerWindows();
 | 
			
		||||
 | 
			
		||||
	void handleSuspendResumeEvent(bool sleep);
 | 
			
		||||
 | 
			
		||||
protected:
 | 
			
		||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
 | 
			
		||||
@@ -65,13 +70,17 @@ protected:
 | 
			
		||||
	bool nativeEventFilter(const QByteArray& eventType, void* message, long int* result) override;
 | 
			
		||||
#endif
 | 
			
		||||
 | 
			
		||||
private:
 | 
			
		||||
	bool registerOsEventHandler() override;
 | 
			
		||||
	void unregisterOsEventHandler() override;
 | 
			
		||||
	bool registerLockHandler() override;
 | 
			
		||||
	void unregisterLockHandler() override;
 | 
			
		||||
 | 
			
		||||
	QWidget			_widget;
 | 
			
		||||
private:
 | 
			
		||||
	static OsEventHandlerWindows* getInstance();
 | 
			
		||||
 | 
			
		||||
	static DEVICE_NOTIFY_CALLBACK_ROUTINE handlePowerNotifications;
 | 
			
		||||
 | 
			
		||||
	QWidget* _widget;
 | 
			
		||||
	HPOWERNOTIFY	_notifyHandle;
 | 
			
		||||
};
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -10,6 +10,8 @@
 | 
			
		||||
#include <QTimer>
 | 
			
		||||
#include <QHostInfo>
 | 
			
		||||
#include <QMultiMap>
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
 | 
			
		||||
// hyperion includes
 | 
			
		||||
#include <leddevice/LedDeviceWrapper.h>
 | 
			
		||||
@@ -389,6 +391,9 @@ void JsonAPI::handleSysInfoCommand(const QJsonObject &, const QString &command,
 | 
			
		||||
	hyperion["rootPath"] = _instanceManager->getRootPath();
 | 
			
		||||
	hyperion["readOnlyMode"] = _hyperion->getReadOnlyMode();
 | 
			
		||||
 | 
			
		||||
	QCoreApplication* app = QCoreApplication::instance();
 | 
			
		||||
	hyperion["isGuiMode"] = qobject_cast<QApplication*>(app) ? true : false;
 | 
			
		||||
 | 
			
		||||
	info["hyperion"] = hyperion;
 | 
			
		||||
 | 
			
		||||
	// send the result
 | 
			
		||||
 
 | 
			
		||||
@@ -3,19 +3,22 @@
 | 
			
		||||
#include <QtGlobal>
 | 
			
		||||
#include <QJsonDocument>
 | 
			
		||||
#include <QJsonObject>
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
#include <QApplication>
 | 
			
		||||
 | 
			
		||||
#include <events/EventHandler.h>
 | 
			
		||||
#include <utils/Logger.h>
 | 
			
		||||
 | 
			
		||||
#include <iostream>
 | 
			
		||||
 | 
			
		||||
#if defined(_WIN32)
 | 
			
		||||
#include <QCoreApplication>
 | 
			
		||||
 | 
			
		||||
#include <QWidget>
 | 
			
		||||
#include <windows.h>
 | 
			
		||||
#include <wtsapi32.h>
 | 
			
		||||
#include <powerbase.h>
 | 
			
		||||
 | 
			
		||||
#pragma comment( lib, "wtsapi32.lib" )
 | 
			
		||||
#pragma comment(lib, "PowrProf.lib")
 | 
			
		||||
 | 
			
		||||
#elif defined(__APPLE__)
 | 
			
		||||
#include <AppKit/AppKit.h>
 | 
			
		||||
#endif
 | 
			
		||||
@@ -26,10 +29,16 @@ OsEventHandlerBase::OsEventHandlerBase()
 | 
			
		||||
	, _isSuspendOnLock(false)
 | 
			
		||||
	, _isSuspendRegistered(false)
 | 
			
		||||
	, _isLockRegistered(false)
 | 
			
		||||
	, _isService(false)
 | 
			
		||||
{
 | 
			
		||||
	qRegisterMetaType<Event>("Event");
 | 
			
		||||
	_log = Logger::getInstance("EVENTS-OS");
 | 
			
		||||
 | 
			
		||||
	QCoreApplication* app = QCoreApplication::instance();
 | 
			
		||||
	if (!qobject_cast<QApplication*>(app))
 | 
			
		||||
	{
 | 
			
		||||
		_isService = true;
 | 
			
		||||
	}
 | 
			
		||||
	QObject::connect(this, &OsEventHandlerBase::signalEvent, EventHandler::getInstance(), &EventHandler::handleEvent);
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -65,6 +74,8 @@ void OsEventHandlerBase::handleSettingsUpdate(settings::type type, const QJsonDo
 | 
			
		||||
			unregisterOsEventHandler();
 | 
			
		||||
		}
 | 
			
		||||
 | 
			
		||||
		if (!_isService)
 | 
			
		||||
		{
 | 
			
		||||
			_isLockEnabled = obj["lockEnable"].toBool(true);
 | 
			
		||||
			if (_isLockEnabled || _isSuspendOnLock != prevIsSuspendOnLock)
 | 
			
		||||
			{
 | 
			
		||||
@@ -77,6 +88,7 @@ void OsEventHandlerBase::handleSettingsUpdate(settings::type type, const QJsonDo
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void OsEventHandlerBase::suspend(bool sleep)
 | 
			
		||||
{
 | 
			
		||||
@@ -118,8 +130,15 @@ void OsEventHandlerBase::lock(bool isLocked)
 | 
			
		||||
 | 
			
		||||
#if defined(_WIN32)
 | 
			
		||||
 | 
			
		||||
OsEventHandlerWindows* OsEventHandlerWindows::getInstance()
 | 
			
		||||
{
 | 
			
		||||
	static OsEventHandlerWindows instance;
 | 
			
		||||
	return &instance;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
OsEventHandlerWindows::OsEventHandlerWindows()
 | 
			
		||||
	: _notifyHandle(NULL)
 | 
			
		||||
	: _notifyHandle(NULL),
 | 
			
		||||
	_widget(nullptr)
 | 
			
		||||
{
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@@ -127,6 +146,8 @@ OsEventHandlerWindows::~OsEventHandlerWindows()
 | 
			
		||||
{
 | 
			
		||||
	unregisterLockHandler();
 | 
			
		||||
	unregisterOsEventHandler();
 | 
			
		||||
 | 
			
		||||
	delete _widget;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#if (QT_VERSION >= QT_VERSION_CHECK(6, 0, 0))
 | 
			
		||||
@@ -135,8 +156,8 @@ bool OsEventHandlerWindows::nativeEventFilter(const QByteArray& eventType, void*
 | 
			
		||||
bool OsEventHandlerWindows::nativeEventFilter(const QByteArray& eventType, void* message, long int* /*result*/)
 | 
			
		||||
#endif
 | 
			
		||||
{
 | 
			
		||||
	MSG* msg = static_cast<MSG*>(message);
 | 
			
		||||
 | 
			
		||||
	MSG* msg = static_cast<MSG*>(message);
 | 
			
		||||
	switch (msg->message)
 | 
			
		||||
	{
 | 
			
		||||
	case WM_WTSSESSION_CHANGE:
 | 
			
		||||
@@ -152,34 +173,45 @@ bool OsEventHandlerWindows::nativeEventFilter(const QByteArray& eventType, void*
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
 | 
			
		||||
	case WM_POWERBROADCAST:
 | 
			
		||||
		switch (msg->wParam)
 | 
			
		||||
		{
 | 
			
		||||
		case PBT_APMRESUMESUSPEND:
 | 
			
		||||
			emit suspend(false);
 | 
			
		||||
			return true;
 | 
			
		||||
			break;
 | 
			
		||||
		case PBT_APMSUSPEND:
 | 
			
		||||
			emit suspend(true);
 | 
			
		||||
			return true;
 | 
			
		||||
			break;
 | 
			
		||||
		}
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	return false;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
void OsEventHandlerWindows::handleSuspendResumeEvent(bool sleep)
 | 
			
		||||
{
 | 
			
		||||
	if (sleep)
 | 
			
		||||
	{
 | 
			
		||||
		suspend(true);
 | 
			
		||||
	}
 | 
			
		||||
	else
 | 
			
		||||
	{
 | 
			
		||||
		suspend(false);
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
ULONG OsEventHandlerWindows::handlePowerNotifications(PVOID Context, ULONG Type, PVOID Setting)
 | 
			
		||||
{
 | 
			
		||||
	switch (Type)
 | 
			
		||||
	{
 | 
			
		||||
	case PBT_APMRESUMESUSPEND:
 | 
			
		||||
		getInstance()->handleSuspendResumeEvent(false);
 | 
			
		||||
		break;
 | 
			
		||||
	case PBT_APMSUSPEND:
 | 
			
		||||
		getInstance()->handleSuspendResumeEvent(true);
 | 
			
		||||
		break;
 | 
			
		||||
	}
 | 
			
		||||
	return S_OK;
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
bool OsEventHandlerWindows::registerOsEventHandler()
 | 
			
		||||
{
 | 
			
		||||
	bool isRegistered{ _isSuspendRegistered };
 | 
			
		||||
	if (!_isSuspendRegistered)
 | 
			
		||||
	{
 | 
			
		||||
		auto handle = reinterpret_cast<HWND> (_widget.winId());
 | 
			
		||||
		_notifyHandle = RegisterSuspendResumeNotification(handle, DEVICE_NOTIFY_WINDOW_HANDLE);
 | 
			
		||||
		if (_notifyHandle != NULL)
 | 
			
		||||
		DEVICE_NOTIFY_SUBSCRIBE_PARAMETERS notificationsParameters = { handlePowerNotifications, NULL };
 | 
			
		||||
		if (PowerRegisterSuspendResumeNotification(DEVICE_NOTIFY_CALLBACK, (HANDLE)¬ificationsParameters, &_notifyHandle) == ERROR_SUCCESS)
 | 
			
		||||
		{
 | 
			
		||||
			QCoreApplication::instance()->installNativeEventFilter(this);
 | 
			
		||||
			isRegistered = true;
 | 
			
		||||
		}
 | 
			
		||||
		else
 | 
			
		||||
		{
 | 
			
		||||
@@ -200,8 +232,7 @@ void OsEventHandlerWindows::unregisterOsEventHandler()
 | 
			
		||||
	{
 | 
			
		||||
		if (_notifyHandle != NULL)
 | 
			
		||||
		{
 | 
			
		||||
			QCoreApplication::instance()->removeNativeEventFilter(this);
 | 
			
		||||
			UnregisterSuspendResumeNotification(_notifyHandle);
 | 
			
		||||
			PowerUnregisterSuspendResumeNotification(_notifyHandle);
 | 
			
		||||
		}
 | 
			
		||||
		_notifyHandle = NULL;
 | 
			
		||||
		_isSuspendRegistered = false;
 | 
			
		||||
@@ -213,17 +244,23 @@ bool OsEventHandlerWindows::registerLockHandler()
 | 
			
		||||
	bool isRegistered{ _isLockRegistered };
 | 
			
		||||
	if (!_isLockRegistered)
 | 
			
		||||
	{
 | 
			
		||||
		auto handle = reinterpret_cast<HWND> (_widget.winId());
 | 
			
		||||
		if (!_isService)
 | 
			
		||||
		{
 | 
			
		||||
			_widget = new QWidget();
 | 
			
		||||
			if (_widget)
 | 
			
		||||
			{
 | 
			
		||||
				auto handle = reinterpret_cast<HWND> (_widget->winId());
 | 
			
		||||
				if (WTSRegisterSessionNotification(handle, NOTIFY_FOR_THIS_SESSION))
 | 
			
		||||
				{
 | 
			
		||||
					QCoreApplication::instance()->installNativeEventFilter(this);
 | 
			
		||||
					isRegistered = true;
 | 
			
		||||
				}
 | 
			
		||||
				else
 | 
			
		||||
				{
 | 
			
		||||
					Error(_log, "Could not register for lock/unlock events!");
 | 
			
		||||
				}
 | 
			
		||||
 | 
			
		||||
 | 
			
		||||
			}
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
 | 
			
		||||
	if (isRegistered)
 | 
			
		||||
@@ -237,11 +274,15 @@ void OsEventHandlerWindows::unregisterLockHandler()
 | 
			
		||||
{
 | 
			
		||||
	if (_isLockRegistered)
 | 
			
		||||
	{
 | 
			
		||||
		auto handle = reinterpret_cast<HWND> (_widget.winId());
 | 
			
		||||
		if (!_isService)
 | 
			
		||||
		{
 | 
			
		||||
			auto handle = reinterpret_cast<HWND> (_widget->winId());
 | 
			
		||||
			QCoreApplication::instance()->removeNativeEventFilter(this);
 | 
			
		||||
			WTSUnRegisterSessionNotification(handle);
 | 
			
		||||
			_isLockRegistered = false;
 | 
			
		||||
		}
 | 
			
		||||
	}
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
#elif defined(__linux__)
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user