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:
Paulchen Panther 2020-08-01 17:50:20 +02:00 committed by GitHub
parent d4b4158cb7
commit 7550a93e59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
4 changed files with 104 additions and 1 deletions

View File

@ -40,6 +40,9 @@
;Require administrator access
RequestExecutionLevel admin
;Tnstaller window branding text
BrandingText /TRIMLEFT "@CPACK_NSIS_BRANDING_TEXT@"
@CPACK_NSIS_DEFINES@
!include Sections.nsh
@ -523,6 +526,10 @@ Function DownloadFile
FunctionEnd
!endif
Function writeStartupRegistry
WriteRegStr HKCU "SOFTWARE\MICROSOFT\Windows\CurrentVersion\Run" "@CPACK_NSIS_PACKAGE_NAME@" "$INSTDIR\bin\hyperiond.exe"
FunctionEnd
;--------------------------------
; Define some macro setting for the gui
@CPACK_NSIS_INSTALLER_MUI_ICON_CODE@
@ -553,6 +560,10 @@ FunctionEnd
!insertmacro MUI_PAGE_INSTFILES
@CPACK_NSIS_INSTALLER_FINISH_TITLE_CODE@
@CPACK_NSIS_INSTALLER_FINISH_TITLE_3LINES_CODE@
!define MUI_FINISHPAGE_SHOWREADME "$INSTDIR\bin\hyperiond.exe"
!define MUI_FINISHPAGE_SHOWREADME_TEXT "$(FINISH_READMETXT)"
!define MUI_FINISHPAGE_SHOWREADME_FUNCTION writeStartupRegistry
!define MUI_FINISHPAGE_SHOWREADME_NOTCHECKED
!insertmacro MUI_PAGE_FINISH
!insertmacro MUI_UNPAGE_CONFIRM
@ -613,6 +624,42 @@ FunctionEnd
!insertmacro MUI_LANGUAGE "Ukrainian"
!insertmacro MUI_LANGUAGE "Welsh"
LangString FINISH_READMETXT ${LANG_ENGLISH} "Load @CPACK_NSIS_PACKAGE_NAME@ at Windows startup"
LangString FINISH_READMETXT ${LANG_ALBANIAN} "Thirr @CPACK_NSIS_PACKAGE_NAME@ gjatë startimit të Windows-it"
LangString FINISH_READMETXT ${LANG_ARABIC} "مع بدء الويندوز @CPACK_NSIS_PACKAGE_NAME@ تشغيل"
LangString FINISH_READMETXT ${LANG_BOSNIAN} "Pokreni @CPACK_NSIS_PACKAGE_NAME@ pri startovanju Windowsa"
LangString FINISH_READMETXT ${LANG_BULGARIAN} "Стартирайте @CPACK_NSIS_PACKAGE_NAME@ при стартиране на Windows"
LangString FINISH_READMETXT ${LANG_CROATIAN} "Uèitaj @CPACK_NSIS_PACKAGE_NAME@ prilikom podizanja Windowsa"
LangString FINISH_READMETXT ${LANG_CZECH} "Nahrát @CPACK_NSIS_PACKAGE_NAME@ pøi spuštìní windows"
LangString FINISH_READMETXT ${LANG_DANISH} "Indlæs @CPACK_NSIS_PACKAGE_NAME@ ved Windows opstart"
LangString FINISH_READMETXT ${LANG_DUTCH} "Laad @CPACK_NSIS_PACKAGE_NAME@ bij opstarten van Windows"
LangString FINISH_READMETXT ${LANG_FINNISH} "Lataa @CPACK_NSIS_PACKAGE_NAME@ Windowsin käynnistyessä"
LangString FINISH_READMETXT ${LANG_FRENCH} "Charger @CPACK_NSIS_PACKAGE_NAME@ lors de l'initialisation de Windows"
LangString FINISH_READMETXT ${LANG_GERMAN} "Starte @CPACK_NSIS_PACKAGE_NAME@ beim Windows start"
LangString FINISH_READMETXT ${LANG_HUNGARIAN} "Indítsa el a @CPACK_NSIS_PACKAGE_NAME@ alkalmazást, amikor a Windows elindul"
LangString FINISH_READMETXT ${LANG_INDONESIAN} "Panggil @CPACK_NSIS_PACKAGE_NAME@ saat Windows dimulai"
LangString FINISH_READMETXT ${LANG_ITALIAN} "Esegui @CPACK_NSIS_PACKAGE_NAME@ all'avvio del sistema"
LangString FINISH_READMETXT ${LANG_JAPANESE} "Windows起動時に@CPACK_NSIS_PACKAGE_NAME@を起動する"
LangString FINISH_READMETXT ${LANG_KOREAN} "Windows 시작시 @CPACK_NSIS_PACKAGE_NAME@ 시작"
LangString FINISH_READMETXT ${LANG_LATVIAN} "Startējiet @CPACK_NSIS_PACKAGE_NAME@, kad Windows tiek startēts"
LangString FINISH_READMETXT ${LANG_LITHUANIAN} "Pradėkite @CPACK_NSIS_PACKAGE_NAME@, kai Windows paleidžiama"
LangString FINISH_READMETXT ${LANG_MACEDONIAN} "Започнете @CPACK_NSIS_PACKAGE_NAME@ кога ќе започне Windows"
LangString FINISH_READMETXT ${LANG_NORWEGIAN} "Start @CPACK_NSIS_PACKAGE_NAME@ ved Windows oppstart"
LangString FINISH_READMETXT ${LANG_POLISH} "Uruchamiaæ @CPACK_NSIS_PACKAGE_NAME@ przy logowaniu Windows"
LangString FINISH_READMETXT ${LANG_PORTUGUESE} "Carregar o @CPACK_NSIS_PACKAGE_NAME@ na inicialização do Windows"
LangString FINISH_READMETXT ${LANG_ROMANIAN} "Incarca @CPACK_NSIS_PACKAGE_NAME@ la pornirea Windows"
LangString FINISH_READMETXT ${LANG_RUSSIAN} "Запускать @CPACK_NSIS_PACKAGE_NAME@ при старте Windows"
LangString FINISH_READMETXT ${LANG_SERBIAN} "Покрените @CPACK_NSIS_PACKAGE_NAME@ при покретању Виндовс"
LangString FINISH_READMETXT ${LANG_SIMPCHINESE} "Windows 系统启动时运行 @CPACK_NSIS_PACKAGE_NAME@"
LangString FINISH_READMETXT ${LANG_SLOVAK} "Naèíta @CPACK_NSIS_PACKAGE_NAME@ pri spustení Windows"
LangString FINISH_READMETXT ${LANG_SLOVENIAN} "Zažene @CPACK_NSIS_PACKAGE_NAME@ kot del zagona Windows"
LangString FINISH_READMETXT ${LANG_SPANISH} "Inicia @CPACK_NSIS_PACKAGE_NAME@ en el arranque de Windows"
LangString FINISH_READMETXT ${LANG_SWEDISH} "Startar @CPACK_NSIS_PACKAGE_NAME@ som en del av Windows boot"
LangString FINISH_READMETXT ${LANG_TRADCHINESE} "在 Windows 啟動時載入 @CPACK_NSIS_PACKAGE_NAME@"
LangString FINISH_READMETXT ${LANG_TURKISH} "@CPACK_NSIS_PACKAGE_NAME@ 'i Windows baþlatýlýrken baþlatýr"
LangString FINISH_READMETXT ${LANG_UKRAINIAN} "Запустіть @CPACK_NSIS_PACKAGE_NAME@ у запуску Windows"
;--------------------------------
;Reserve Files
@ -861,6 +908,7 @@ Section "Uninstall"
; Remove the registry entries.
DeleteRegKey SHCTX "Software\@CPACK_PACKAGE_VENDOR@\@CPACK_PACKAGE_INSTALL_REGISTRY_KEY@"
DeleteRegValue HKCU "SOFTWARE\MICROSOFT\Windows\CurrentVersion\Run" "@CPACK_NSIS_PACKAGE_NAME@"
; Removes all optional components
!insertmacro SectionList "RemoveSection_CPack"

View File

@ -102,6 +102,7 @@ SET ( CPACK_NSIS_INSTALLED_ICON_NAME "bin\\\\hyperiond.exe")
SET ( CPACK_NSIS_HELP_LINK "https://www.hyperion-project.org")
SET ( CPACK_NSIS_URL_INFO_ABOUT "https://www.hyperion-project.org")
SET ( CPACK_NSIS_MUI_FINISHPAGE_RUN "hyperiond.exe")
SET ( CPACK_NSIS_BRANDING_TEXT "Hyperion-${HYPERION_VERSION}")
# additional hyperiond startmenu link, won't be created if the user disables startmenu links
SET ( CPACK_NSIS_CREATE_ICONS_EXTRA "CreateShortCut '$SMPROGRAMS\\\\$STARTMENU_FOLDER\\\\Hyperion (Console).lnk' '$INSTDIR\\\\bin\\\\hyperiond.exe' '-d -c'")
SET ( CPACK_NSIS_DELETE_ICONS_EXTRA "Delete '$SMPROGRAMS\\\\$MUI_TEMP\\\\Hyperion (Console).lnk'")

View File

@ -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() } };

View File

@ -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;