mirror of
https://github.com/hyperion-project/hyperion.ng.git
synced 2025-03-01 10:33:28 +00:00
NSIS/Systray option to launch Hyperion on Windows start [HKCU] (#887)
* NSIS/Systray option to launch Hyperion on Windows start * corrected file path in registry
This commit is contained in:
@@ -3,12 +3,15 @@
|
||||
#ifndef _WIN32
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
|
||||
// QT includes
|
||||
#include <QPixmap>
|
||||
#include <QWindow>
|
||||
#include <QGuiApplication>
|
||||
#include <QWidget>
|
||||
#include <QColor>
|
||||
#include <QDesktopServices>
|
||||
#include <QSettings>
|
||||
|
||||
#include <utils/ColorRgb.h>
|
||||
#include <effectengine/EffectDefinition.h>
|
||||
@@ -43,6 +46,11 @@ void SysTray::iconActivated(QSystemTrayIcon::ActivationReason reason)
|
||||
{
|
||||
switch (reason)
|
||||
{
|
||||
#ifdef _WIN32
|
||||
case QSystemTrayIcon::Context:
|
||||
getCurrentAutorunState();
|
||||
break;
|
||||
#endif
|
||||
case QSystemTrayIcon::Trigger:
|
||||
break;
|
||||
case QSystemTrayIcon::DoubleClick:
|
||||
@@ -89,6 +97,14 @@ void SysTray::createTrayIcon()
|
||||
_trayIconEfxMenu->addAction(efxAction);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
autorunAction = new QAction(tr("&Disable autostart"), this);
|
||||
connect(autorunAction, SIGNAL(triggered()), this, SLOT(setAutorunState()));
|
||||
|
||||
_trayIconMenu->addAction(autorunAction);
|
||||
_trayIconMenu->addSeparator();
|
||||
#endif
|
||||
|
||||
_trayIconMenu->addAction(settingsAction);
|
||||
_trayIconMenu->addSeparator();
|
||||
_trayIconMenu->addAction(colorAction);
|
||||
@@ -101,6 +117,32 @@ void SysTray::createTrayIcon()
|
||||
_trayIcon->setContextMenu(_trayIconMenu);
|
||||
}
|
||||
|
||||
#ifdef _WIN32
|
||||
bool SysTray::getCurrentAutorunState()
|
||||
{
|
||||
QSettings reg("HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
if (reg.value("Hyperion", 0).toString() == qApp->applicationFilePath().replace('/', '\\'))
|
||||
{
|
||||
autorunAction->setText(tr("&Disable autostart"));
|
||||
return true;
|
||||
}
|
||||
|
||||
autorunAction->setText(tr("&Enable autostart"));
|
||||
return false;
|
||||
}
|
||||
#endif
|
||||
|
||||
void SysTray::setAutorunState()
|
||||
{
|
||||
#ifdef _WIN32
|
||||
bool currentState = getCurrentAutorunState();
|
||||
QSettings reg("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat);
|
||||
(currentState)
|
||||
? reg.remove("Hyperion")
|
||||
: reg.setValue("Hyperion", qApp->applicationFilePath().replace('/', '\\'));
|
||||
#endif
|
||||
}
|
||||
|
||||
void SysTray::setColor(const QColor & color)
|
||||
{
|
||||
std::vector<ColorRgb> rgbColor{ ColorRgb{ (uint8_t)color.red(), (uint8_t)color.green(), (uint8_t)color.blue() } };
|
||||
|
@@ -27,6 +27,7 @@ public slots:
|
||||
void settings();
|
||||
void setEffect();
|
||||
void clearEfxColor();
|
||||
void setAutorunState();
|
||||
|
||||
private slots:
|
||||
void iconActivated(QSystemTrayIcon::ActivationReason reason);
|
||||
@@ -37,19 +38,30 @@ private slots:
|
||||
void webserverPortChanged(const quint16& port) { _webPort = port; };
|
||||
|
||||
///
|
||||
/// @brief is called whenever a hyperion isntance state changes
|
||||
/// @brief is called whenever a hyperion instance state changes
|
||||
///
|
||||
void handleInstanceStateChange(const InstanceState& state, const quint8& instance, const QString& name);
|
||||
|
||||
private:
|
||||
void createTrayIcon();
|
||||
|
||||
#ifdef _WIN32
|
||||
///
|
||||
/// @brief Checks whether Hyperion should start at Windows system start.
|
||||
/// @return True on success, otherwise false
|
||||
///
|
||||
bool getCurrentAutorunState();
|
||||
#endif
|
||||
|
||||
QAction *quitAction;
|
||||
QAction *startAction;
|
||||
QAction *stopAction;
|
||||
QAction *colorAction;
|
||||
QAction *settingsAction;
|
||||
QAction *clearAction;
|
||||
#ifdef _WIN32
|
||||
QAction *autorunAction;
|
||||
#endif
|
||||
|
||||
QSystemTrayIcon *_trayIcon;
|
||||
QMenu *_trayIconMenu;
|
||||
|
Reference in New Issue
Block a user