Fix auto-start settings on Windows

This commit is contained in:
Jonathan White 2020-06-17 17:58:24 -04:00
parent 9c0fa376a1
commit 05a0df799e
2 changed files with 3 additions and 3 deletions

View File

@ -51,7 +51,7 @@
<RegistryValue Id="Autostart.rst" Root="HKCU" Action="write" <RegistryValue Id="Autostart.rst" Root="HKCU" Action="write"
Key="Software\Microsoft\Windows\CurrentVersion\Run" Key="Software\Microsoft\Windows\CurrentVersion\Run"
Name="$(var.CPACK_PACKAGE_NAME)" Name="$(var.CPACK_PACKAGE_NAME)"
Value="[#CM_FP_KeePassXC.exe]" Value="&quot;[#CM_FP_KeePassXC.exe]&quot;"
Type="string" /> Type="string" />
<Condition>AUTOSTARTPROGRAM</Condition> <Condition>AUTOSTARTPROGRAM</Condition>
</Component> </Component>

View File

@ -18,6 +18,7 @@
#include "WinUtils.h" #include "WinUtils.h"
#include <QAbstractNativeEventFilter> #include <QAbstractNativeEventFilter>
#include <QApplication> #include <QApplication>
#include <QDir>
#include <QSettings> #include <QSettings>
#include <windows.h> #include <windows.h>
@ -88,14 +89,13 @@ bool WinUtils::isLaunchAtStartupEnabled() const
{ {
return QSettings(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat) return QSettings(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat)
.contains(qAppName()); .contains(qAppName());
;
} }
void WinUtils::setLaunchAtStartup(bool enable) void WinUtils::setLaunchAtStartup(bool enable)
{ {
QSettings reg(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat); QSettings reg(R"(HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Run)", QSettings::NativeFormat);
if (enable) { if (enable) {
reg.setValue(qAppName(), QApplication::applicationFilePath()); reg.setValue(qAppName(), QString("\"%1\"").arg(QDir::toNativeSeparators(QApplication::applicationFilePath())));
} else { } else {
reg.remove(qAppName()); reg.remove(qAppName());
} }