Merge pull request #32 from namecheap/bugfix/RND-586-flameshot-network-settings-are-not-reading-on-autostart-on-windows

Bugfix/rnd 586 flameshot network settings are not reading on autostart on windows
This commit is contained in:
Yurii Puchkov
2020-09-02 12:09:55 -07:00
committed by GitHub
2 changed files with 26 additions and 2 deletions

View File

@@ -2,6 +2,8 @@
#include <QDir>
#include <QSettings>
#include <QFileInfo>
#include <QString>
#include <QSettings>
ConfigEnterprise::ConfigEnterprise()
@@ -9,11 +11,18 @@ ConfigEnterprise::ConfigEnterprise()
// get enterprise settings
m_settings = nullptr;
QString configIniPath = QDir(QDir::currentPath()).filePath("config.ini");
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
if(!(QFileInfo::exists(configIniPath) && QFileInfo(configIniPath).isFile())) {
#if defined(Q_OS_LINUX) || defined(Q_OS_UNIX)
configIniPath = "/etc/flameshot/config.ini";
}
#elif defined(Q_OS_WIN)
// calculate workdir for flameshot on startup if is not set yet
QSettings bootUpSettings(
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::NativeFormat);
QFileInfo fi(bootUpSettings.value("Flameshot").toString());
configIniPath = QDir(fi.absolutePath()).filePath("config.ini");
#endif
}
m_settings = new QSettings(configIniPath, QSettings::IniFormat);
}

View File

@@ -310,12 +310,27 @@ void ConfigHandler::setStartupLaunch(const bool start) {
QSettings bootUpSettings(
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\Run",
QSettings::NativeFormat);
// set workdir for flameshot on startup
QSettings bootUpPath(
"HKEY_CURRENT_USER\\SOFTWARE\\Microsoft\\Windows\\CurrentVersion\\App Paths",
QSettings::NativeFormat);
if (start) {
QString app_path =
QDir::toNativeSeparators(QCoreApplication::applicationFilePath());
bootUpSettings.setValue("Flameshot", app_path);
// set application workdir
bootUpPath.beginGroup("flameshot.exe");
bootUpPath.setValue("Path", QCoreApplication::applicationDirPath());
bootUpPath.endGroup();
} else {
bootUpSettings.remove("Flameshot");
// remove application workdir
bootUpPath.beginGroup("flameshot.exe");
bootUpPath.remove("");
bootUpPath.endGroup();
}
#endif
m_settings.setValue(QStringLiteral("startupLaunch"), start);