From 5d3a122ebfe2c204712719d49bb70dafb541d4fd Mon Sep 17 00:00:00 2001 From: Mitternacht822 Date: Tue, 20 May 2025 10:24:00 +0400 Subject: [PATCH] testing new feature with autostart backup option --- client/settings.h | 9 +++++ client/ui/controllers/settingsController.cpp | 38 ++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/client/settings.h b/client/settings.h index eec6cc44..306b7a50 100644 --- a/client/settings.h +++ b/client/settings.h @@ -85,6 +85,15 @@ public: setValue("Conf/autoConnect", enabled); } + bool isAutoStart() const + { + return value("Conf/autoStart", false).toBool(); + } + void setAutoStart(bool enabled) + { + setValue("Conf/autoStart", enabled); + } + bool isStartMinimized() const { return value("Conf/startMinimized", false).toBool(); diff --git a/client/ui/controllers/settingsController.cpp b/client/ui/controllers/settingsController.cpp index c5c569db..17b3dd13 100644 --- a/client/ui/controllers/settingsController.cpp +++ b/client/ui/controllers/settingsController.cpp @@ -140,6 +140,12 @@ void SettingsController::restoreAppConfigFromData(const QByteArray &data) { bool ok = m_settings->restoreAppConfig(data); if (ok) { +#if defined(Q_OS_WINDOWS) || defined(Q_OS_LINUX) || defined(Q_OS_MACX) + bool autoStartEnabled = m_settings->isAutoStart(); + if (autoStartEnabled != isAutoStartEnabled()) { + toggleAutoStart(autoStartEnabled); + } +#endif m_serversModel->resetModel(); m_languageModel->changeLanguage( static_cast(m_languageModel->getCurrentLanguageIndex())); @@ -191,6 +197,38 @@ bool SettingsController::isAutoStartEnabled() void SettingsController::toggleAutoStart(bool enable) { +/*#ifdef Q_OS_WINDOWS + if (enable) { + QString exePath = QCoreApplication::applicationFilePath(); + QString shortcutName = "AmneziaVPN.lnk"; + + QString startupFolder = QDir::homePath() + + "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"; + + QString shortcutPath = QDir::toNativeSeparators(startupFolder + "/" + shortcutName); + QString targetPath = QDir::toNativeSeparators(exePath); + + QProcess::execute("powershell", { + "-Command", + QString("" + "$WshShell = New-Object -ComObject WScript.Shell; " + "$Shortcut = $WshShell.CreateShortcut('%1'); " + "$Shortcut.TargetPath = '%2'; " + "$Shortcut.WorkingDirectory = '%3'; " + "$Shortcut.Save()" + ).arg(shortcutPath, targetPath, QFileInfo(targetPath).absolutePath()) + }); + } else { + QString startupFolder = QDir::homePath() + + "/AppData/Roaming/Microsoft/Windows/Start Menu/Programs/Startup"; + QString shortcutPath = QDir::toNativeSeparators(startupFolder + "/AmneziaVPN.lnk"); + QFile::remove(shortcutPath); + QSettings runKey("HKEY_CURRENT_USER\\Software\\Microsoft\\Windows\\CurrentVersion\\Run", QSettings::NativeFormat); + runKey.remove("AmneziaVPN"); + } +#else + Autostart::setAutostart(enable); +#endif*/ Autostart::setAutostart(enable); }