diff --git a/src/gui/application.cpp b/src/gui/application.cpp index f962f9b14dde8..c318868907887 100644 --- a/src/gui/application.cpp +++ b/src/gui/application.cpp @@ -158,6 +158,11 @@ bool Application::configVersionMigration() return true; } + // 'Launch on system startup' defaults to true > 3.11.x + const auto theme = Theme::instance(); + configFile.setLaunchOnSystemStartup(configFile.launchOnSystemStartup()); + Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), configFile.launchOnSystemStartup()); + // back up all old config files QStringList backupFilesList; QDir configDir(configFile.configPath()); diff --git a/src/gui/generalsettings.cpp b/src/gui/generalsettings.cpp index 0b32d9db47b69..6a6315b38def5 100644 --- a/src/gui/generalsettings.cpp +++ b/src/gui/generalsettings.cpp @@ -159,10 +159,9 @@ GeneralSettings::GeneralSettings(QWidget *parent) _ui->autostartCheckBox->setChecked(hasSystemAutoStart); _ui->autostartCheckBox->setDisabled(hasSystemAutoStart); _ui->autostartCheckBox->setToolTip(tr("You cannot disable autostart because system-wide autostart is enabled.")); - } else { - const auto hasAutoStart = Utility::hasLaunchOnStartup(Theme::instance()->appName()); + } else { connect(_ui->autostartCheckBox, &QAbstractButton::toggled, this, &GeneralSettings::slotToggleLaunchOnStartup); - _ui->autostartCheckBox->setChecked(hasAutoStart); + _ui->autostartCheckBox->setChecked(ConfigFile().launchOnSystemStartup()); } // setup about section @@ -454,7 +453,13 @@ void GeneralSettings::saveMiscSettings() void GeneralSettings::slotToggleLaunchOnStartup(bool enable) { + ConfigFile configFile; + if (enable == Utility::hasLaunchOnStartup(Theme::instance()->appName())) { + return; + } + const auto theme = Theme::instance(); + configFile.setLaunchOnSystemStartup(enable); Utility::setLaunchOnStartup(theme->appName(), theme->appNameGUI(), enable); } diff --git a/src/libsync/configfile.cpp b/src/libsync/configfile.cpp index 7d2ebb4f39369..dd5efa0f67450 100644 --- a/src/libsync/configfile.cpp +++ b/src/libsync/configfile.cpp @@ -84,6 +84,7 @@ static constexpr char logExpireC[] = "logExpire"; static constexpr char logFlushC[] = "logFlush"; static constexpr char showExperimentalOptionsC[] = "showExperimentalOptions"; static constexpr char clientVersionC[] = "clientVersion"; +static constexpr char launchOnSystemStartupC[] = "launchOnSystemStartup"; static constexpr char proxyHostC[] = "Proxy/host"; static constexpr char proxyTypeC[] = "Proxy/type"; @@ -1152,6 +1153,18 @@ void ConfigFile::setClientVersionString(const QString &version) settings.setValue(QLatin1String(clientVersionC), version); } +bool ConfigFile::launchOnSystemStartup() const +{ + QSettings settings(configFile(), QSettings::IniFormat); + return settings.value(QLatin1String(launchOnSystemStartupC), true).toBool(); +} + +void ConfigFile::setLaunchOnSystemStartup(const bool autostart) +{ + QSettings settings(configFile(), QSettings::IniFormat); + settings.setValue(QLatin1String(launchOnSystemStartupC), autostart); +} + Q_GLOBAL_STATIC(QString, g_configFileName) std::unique_ptr ConfigFile::settingsWithGroup(const QString &group, QObject *parent) diff --git a/src/libsync/configfile.h b/src/libsync/configfile.h index 0ca15b807c73c..7ae1f98df207b 100644 --- a/src/libsync/configfile.h +++ b/src/libsync/configfile.h @@ -220,6 +220,11 @@ class OWNCLOUDSYNC_EXPORT ConfigFile [[nodiscard]] QString clientVersionString() const; void setClientVersionString(const QString &version); + /** If the option 'Launch on system startup' is set + Updated by configVersionMigration() at client startup. */ + [[nodiscard]] bool launchOnSystemStartup() const; + void setLaunchOnSystemStartup(const bool autostart); + /** Returns a new settings pre-set in a specific group. The Settings will be created with the given parent. If no parent is specified, the caller must destroy the settings */ static std::unique_ptr settingsWithGroup(const QString &group, QObject *parent = nullptr);