diff --git a/src/lib/common/Settings.cpp b/src/lib/common/Settings.cpp index 60a6cb728..4af5f7b8f 100644 --- a/src/lib/common/Settings.cpp +++ b/src/lib/common/Settings.cpp @@ -110,12 +110,8 @@ QVariant Settings::defaultValue(const QString &key) if (key == Server::Binary) return kServerBinName; - if (key == Core::ElevateMode) { - if (instance()->isNativeMode()) - return Settings::ElevateMode::Always; - else - return Settings::ElevateMode::Never; - } + if (key == Daemon::Elevate) + return instance()->isNativeMode(); if (key == Core::UpdateUrl) return kUrlUpdateCheck; @@ -141,9 +137,6 @@ QVariant Settings::defaultValue(const QString &key) #endif } - if (key == Daemon::Elevate) - return true; - return QVariant(); } diff --git a/src/lib/common/Settings.h b/src/lib/common/Settings.h index 561982738..524b83248 100644 --- a/src/lib/common/Settings.h +++ b/src/lib/common/Settings.h @@ -41,7 +41,6 @@ public: struct Core { inline static const auto CoreMode = QStringLiteral("core/coreMode"); - inline static const auto ElevateMode = QStringLiteral("core/elevateMode"); inline static const auto Interface = QStringLiteral("core/interface"); inline static const auto LastVersion = QStringLiteral("core/lastVersion"); inline static const auto Port = QStringLiteral("core/port"); @@ -104,28 +103,6 @@ public: }; Q_ENUM(ProcessMode) - /** - * @brief The elevate mode tristate determines two behaviors on Windows. - * The matrix for these two behaviors is as follows: - * | sods | elevate | - * |-----------|------------| - * kAutomatic | true | false | - * kAlways | false | true | - * kNever | false | false | - * The first, --stop-on-desk-switch (sods), is passed through the daemon as a - * command line argument to the server/client, and determines if it restarts - * when switching Windows desktops (e.g. when Windows UAC dialog pops up). - * The second, elevate, is passed as a boolean flag to the daemon over IPC, - * and determines whether the server/client should be started with elevated privileges. - */ - enum ElevateMode - { - Automatic = 0, - Always = 1, - Never = 2 - }; - Q_ENUM(ElevateMode) - enum CoreMode { None, @@ -182,7 +159,6 @@ private: , Settings::Client::LanguageSync , Settings::Client::RemoteHost , Settings::Core::CoreMode - , Settings::Core::ElevateMode , Settings::Core::Interface , Settings::Core::LastVersion , Settings::Core::Port diff --git a/src/lib/gui/core/CoreProcess.cpp b/src/lib/gui/core/CoreProcess.cpp index 8d9d27bfd..78b5ecc75 100644 --- a/src/lib/gui/core/CoreProcess.cpp +++ b/src/lib/gui/core/CoreProcess.cpp @@ -264,8 +264,7 @@ void CoreProcess::startProcessFromDaemon(const QString &app, const QStringList & qInfo("running command: %s", qPrintable(commandQuoted)); - auto elevateMode = Settings::value(Settings::Core::ElevateMode).value(); - if (!m_daemonIpcClient->sendStartProcess(commandQuoted, elevateMode)) { + if (!m_daemonIpcClient->sendStartProcess(commandQuoted, Settings::value(Settings::Daemon::Elevate).toBool())) { qCritical("cannot start process, ipc command failed"); return; } diff --git a/src/lib/gui/dialogs/SettingsDialog.cpp b/src/lib/gui/dialogs/SettingsDialog.cpp index e2e664fbb..37d2ff6cb 100644 --- a/src/lib/gui/dialogs/SettingsDialog.cpp +++ b/src/lib/gui/dialogs/SettingsDialog.cpp @@ -68,6 +68,25 @@ void SettingsDialog::initConnections() connect(ui->btnTlsCertPath, &QPushButton::clicked, this, &SettingsDialog::browseCertificatePath); connect(ui->btnBrowseLog, &QPushButton::clicked, this, &SettingsDialog::browseLogPath); connect(ui->cbLogToFile, &QCheckBox::toggled, this, &SettingsDialog::setLogToFile); + connect(ui->cbElevateDaemon, &QCheckBox::toggled, this, [&](bool checked) { + if (!checked) + return; + if (ui->cbStopOnDeskSwitch->isChecked()) { + blockSignals(true); + ui->cbStopOnDeskSwitch->setChecked(false); + blockSignals(false); + } + }); + + connect(ui->cbStopOnDeskSwitch, &QCheckBox::toggled, this, [&](bool checked) { + if (!checked) + return; + if (ui->cbElevateDaemon->isChecked()) { + blockSignals(true); + ui->cbElevateDaemon->setChecked(false); + blockSignals(false); + } + }); } void SettingsDialog::regenCertificates() @@ -133,7 +152,7 @@ void SettingsDialog::accept() Settings::setValue(Settings::Log::ToFile, ui->cbLogToFile->isChecked()); Settings::setValue(Settings::Log::File, ui->lineLogFilename->text()); Settings::setValue(Settings::Core::StopOnDeskSwitch, ui->cbStopOnDeskSwitch->isChecked()); - Settings::setValue(Settings::Core::ElevateMode, ui->comboElevate->currentIndex()); + Settings::setValue(Settings::Daemon::Elevate, ui->cbElevateDaemon->isChecked()); Settings::setValue(Settings::Gui::Autohide, ui->cbAutoHide->isChecked()); Settings::setValue(Settings::Gui::AutoUpdateCheck, ui->cbAutoUpdate->isChecked()); Settings::setValue(Settings::Core::PreventSleep, ui->cbPreventSleep->isChecked()); @@ -169,7 +188,7 @@ void SettingsDialog::loadFromConfig() ui->cbScrollDirection->setChecked(Settings::value(Settings::Client::InvertScrollDirection).toBool()); ui->cbCloseToTray->setChecked(Settings::value(Settings::Gui::CloseToTray).toBool()); ui->cbStopOnDeskSwitch->setChecked(Settings::value(Settings::Core::StopOnDeskSwitch).toBool()); - ui->comboElevate->setCurrentIndex(Settings::value(Settings::Core::ElevateMode).toInt()); + ui->cbElevateDaemon->setChecked(Settings::value(Settings::Daemon::Elevate).toBool()); ui->cbAutoUpdate->setChecked(Settings::value(Settings::Gui::AutoUpdateCheck).toBool()); const auto processMode = Settings::value(Settings::Core::ProcessMode).value(); @@ -268,7 +287,7 @@ void SettingsDialog::updateControls() // Handle enable and disable of service items if (Settings::isNativeMode()) { ui->groupService->setEnabled(writable); - ui->widgetElevate->setEnabled(writable && serviceChecked); + ui->cbElevateDaemon->setEnabled(writable && serviceChecked); ui->cbStopOnDeskSwitch->setEnabled(writable && serviceChecked); } else if (ui->groupService->isVisibleTo(ui->tabAdvanced)) { ui->groupService->setVisible(false); diff --git a/src/lib/gui/dialogs/SettingsDialog.ui b/src/lib/gui/dialogs/SettingsDialog.ui index f72d11fa2..b370c985f 100644 --- a/src/lib/gui/dialogs/SettingsDialog.ui +++ b/src/lib/gui/dialogs/SettingsDialog.ui @@ -147,6 +147,9 @@ true + + false + @@ -538,6 +541,9 @@ + + true + 0 @@ -554,81 +560,6 @@ false - - - - - 0 - 0 - - - - - - - - 0 - 0 - - - - Launch with elevated privileges - - - - - - - - 0 - 0 - - - - - 0 - 0 - - - - Specify when the Windows background service should run the server or client - process at an elevated privilege level. - - - - <p>You may want to alter whether or not the privilege level of the server or client - process is automatically changed depending on your use case. In some cases it can help - to diagnose or solve some problems related to elevated processes in Windows.</p> - <ul> - <li>Automatic: Elevate when the window session changes to secure mode</li> - <li>Always elevate: Always run in elevated mode (could be unsafe)</li> - <li>Never elevate: Turn off compatibility with login screen and UAC</li> - </ul> - - - - 0 - - - - Automatic (as needed) - - - - - Always elevate - - - - - Never elevate - - - - - - - @@ -637,6 +568,19 @@ Run as system only when at the login screen and UAC prompt + + true + + + + + + + Always run as system (work at login screen and UAC) + + + false + @@ -680,7 +624,6 @@ comboLogLevel lineLogFilename btnBrowseLog - comboElevate diff --git a/src/lib/gui/ipc/DaemonIpcClient.cpp b/src/lib/gui/ipc/DaemonIpcClient.cpp index 40e5b8873..12d1930e8 100644 --- a/src/lib/gui/ipc/DaemonIpcClient.cpp +++ b/src/lib/gui/ipc/DaemonIpcClient.cpp @@ -132,13 +132,12 @@ bool DaemonIpcClient::sendLogLevel(const QString &logLevel) return true; } -bool DaemonIpcClient::sendStartProcess(const QString &command, Settings::ElevateMode elevateMode) +bool DaemonIpcClient::sendStartProcess(const QString &command, bool elevate) { if (!keepAlive()) return false; - using ElevateMode = Settings::ElevateMode; - if (!sendMessage("elevate=" + (elevateMode == ElevateMode::Always ? QStringLiteral("yes") : QStringLiteral("no")))) { + if (!sendMessage("elevate=" + (elevate ? QStringLiteral("yes") : QStringLiteral("no")))) { return false; } diff --git a/src/lib/gui/ipc/DaemonIpcClient.h b/src/lib/gui/ipc/DaemonIpcClient.h index 988926ae3..df694d528 100644 --- a/src/lib/gui/ipc/DaemonIpcClient.h +++ b/src/lib/gui/ipc/DaemonIpcClient.h @@ -22,7 +22,7 @@ public: explicit DaemonIpcClient(QObject *parent = nullptr); bool connectToServer(); bool sendLogLevel(const QString &logLevel); - bool sendStartProcess(const QString &command, Settings::ElevateMode elevateMode); + bool sendStartProcess(const QString &command, bool elevate); bool sendStopProcess(); bool sendClearSettings(); QString requestLogPath();