diff --git a/.env.example b/.env.example index 94435f396..ef5b56cbb 100644 --- a/.env.example +++ b/.env.example @@ -24,6 +24,12 @@ # Reset all settings and delete all data on startup # SYNERGY_RESET_ALL=true +# Enable the activation dialog (used for testing) +# SYNERGY_ENABLE_ACTIVATION=true + +# Show licensed product menu items, etc (used for testing) +# SYNERGY_LICENSED_PRODUCT=true + # # Build # diff --git a/ChangeLog b/ChangeLog index 92b594290..9f196f0eb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -78,6 +78,7 @@ Enhancements: - #7432 Only show close to tray reminder when not quitting the app - #7434 Show dark logo in dark mode and improve .env loader - #7435 Add reset settings menu action and env var +- #7436 Introduced new env vars for testing # 1.14.6 diff --git a/src/gui/src/MainWindow.cpp b/src/gui/src/MainWindow.cpp index c0ca769ea..7b3348ed3 100644 --- a/src/gui/src/MainWindow.cpp +++ b/src/gui/src/MainWindow.cpp @@ -31,6 +31,7 @@ #include "gui/diagnostic.h" #include "gui/dialogs/SettingsDialog.h" #include "gui/license/LicenseHandler.h" +#include "gui/license/license_config.h" #include "gui/license/license_notices.h" #include "gui/messages.h" #include "gui/string_utils.h" @@ -62,6 +63,7 @@ using namespace synergy::gui; using namespace synergy::license; +using namespace synergy::gui::license; using CoreMode = CoreProcess::Mode; using CoreConnectionState = CoreProcess::ConnectionState; @@ -134,14 +136,14 @@ void MainWindow::saveWindow() { } void MainWindow::setupControls() { - if (!kEnableActivation) { + if (!isActivationEnabled()) { updateWindowTitle(); } - if (!kLicensedProduct) { + if (!isLicensedProduct()) { m_pActionHelp->setText("Report a bug"); m_pActionActivate->setText("Purchase"); - } else if (!kEnableActivation) { + } else if (!isActivationEnabled()) { m_pActionActivate->setVisible(false); } @@ -287,7 +289,7 @@ void MainWindow::onCreated() { applyCloseToTray(); - if (kEnableActivation && !m_AppConfig.serialKey().isEmpty()) { + if (isActivationEnabled() && !m_AppConfig.serialKey().isEmpty()) { m_LicenseHandler.changeSerialKey(m_AppConfig.serialKey()); } @@ -300,7 +302,7 @@ void MainWindow::onCreated() { } void MainWindow::onShown() { - if (kEnableActivation) { + if (isActivationEnabled()) { const auto &license = m_LicenseHandler.license(); if (!m_AppConfig.activationHasRun() || !license.isValid() || license.isExpired()) { @@ -435,7 +437,7 @@ void MainWindow::on_m_pActionAbout_triggered() { } void MainWindow::on_m_pActionHelp_triggered() const { - if (kLicensedProduct) { + if (isLicensedProduct()) { QDesktopServices::openUrl(QUrl(kUrlHelp)); } else { QDesktopServices::openUrl(QUrl(kUrlBugReport)); @@ -464,7 +466,7 @@ void MainWindow::on_m_pButtonConfigureServer_clicked() { } void MainWindow::on_m_pActionActivate_triggered() { - if (kLicensedProduct) { + if (isLicensedProduct()) { showActivationDialog(); } else { QDesktopServices::openUrl(QUrl(kUrlPurchase)); @@ -573,7 +575,7 @@ void MainWindow::open() { void MainWindow::onCoreProcessStarting() { - if (kEnableActivation) { + if (isActivationEnabled()) { const auto &license = m_LicenseHandler.license(); if (license.isExpired() && showActivationDialog() == QDialog::Rejected) { qDebug("license expired, cancelling core start"); @@ -704,7 +706,7 @@ void MainWindow::updateFromLogLine(const QString &line) { checkConnected(line); checkFingerprint(line); - if (kEnableActivation) { + if (isActivationEnabled()) { checkLicense(line); } } @@ -816,7 +818,7 @@ void MainWindow::showDevThanksMessage() { return; } - if (kEnableActivation) { + if (isActivationEnabled()) { qDebug("activation enabled, skipping dev thanks message"); return; } @@ -1014,7 +1016,7 @@ void MainWindow::updateLocalFingerprint() { } QString MainWindow::productName() const { - if (kEnableActivation) { + if (isActivationEnabled()) { return m_LicenseHandler.productName(); } else if (!kProductName.isEmpty()) { return kProductName; @@ -1061,7 +1063,7 @@ void MainWindow::showConfigureServer(const QString &message) { } int MainWindow::showActivationDialog() { - if (!kEnableActivation) { + if (!isActivationEnabled()) { qFatal("cannot show activation dialog when activation is disabled"); } diff --git a/src/lib/gui/constants.h b/src/lib/gui/constants.h index ad23c0f84..c6cbe86cb 100644 --- a/src/lib/gui/constants.h +++ b/src/lib/gui/constants.h @@ -53,19 +53,4 @@ const QString kProductName = SYNERGY_PRODUCT_NAME; const QString kProductName; #endif -#ifdef SYNERGY_LICENSED_PRODUCT -const bool kLicensedProduct = true; -#else -const bool kLicensedProduct = false; -#endif - -#ifdef SYNERGY_ENABLE_ACTIVATION -#ifndef SYNERGY_LICENSED_PRODUCT -#error "activation requires licensed product" -#endif -const bool kEnableActivation = true; -#else -const bool kEnableActivation = false; -#endif // SYNERGY_ENABLE_ACTIVATION - } // namespace synergy::gui diff --git a/src/lib/gui/core/CoreProcess.cpp b/src/lib/gui/core/CoreProcess.cpp index ef4f024d7..88ec105d1 100644 --- a/src/lib/gui/core/CoreProcess.cpp +++ b/src/lib/gui/core/CoreProcess.cpp @@ -17,9 +17,9 @@ #include "CoreProcess.h" -#include "constants.h" #include "gui/config/IAppConfig.h" #include "gui/core/CoreTool.h" +#include "gui/license/license_config.h" #include "gui/paths.h" #include "tls/TlsUtility.h" @@ -36,6 +36,9 @@ #include #include +using namespace synergy::license; +using namespace synergy::gui::license; + namespace synergy::gui { const int kRetryDelay = 1000; @@ -136,8 +139,8 @@ QString CoreProcess::Deps::getProfileRoot() const { // CoreProcess::CoreProcess( - IAppConfig &appConfig, IServerConfig &serverConfig, - const license::ILicense &license, std::shared_ptr deps) + IAppConfig &appConfig, IServerConfig &serverConfig, const ILicense &license, + std::shared_ptr deps) : m_appConfig(appConfig), m_serverConfig(serverConfig), m_license(license), @@ -534,7 +537,7 @@ bool CoreProcess::addServerArgs(QStringList &args, QString &app) { args << "-c" << configFilename; qInfo("core config file: %s", qPrintable(configFilename)); - if (kEnableActivation && !m_appConfig.serialKey().isEmpty()) { + if (isActivationEnabled() && !m_appConfig.serialKey().isEmpty()) { args << "--serial-key" << m_appConfig.serialKey(); } diff --git a/src/lib/gui/core/CoreProcess.h b/src/lib/gui/core/CoreProcess.h index eb134d1f6..6e18b7279 100644 --- a/src/lib/gui/core/CoreProcess.h +++ b/src/lib/gui/core/CoreProcess.h @@ -21,7 +21,7 @@ #include "gui/config/IServerConfig.h" #include "gui/ipc/QIpcClient.h" #include "gui/proxy/QProcessProxy.h" -#include "license/License.h" +#include "license/ILicense.h" #include #include @@ -35,6 +35,7 @@ class CoreProcess : public QObject { using IServerConfig = synergy::gui::IServerConfig; using QProcessProxy = synergy::gui::proxy::QProcessProxy; using IQIpcClient = synergy::gui::ipc::IQIpcClient; + using ILicense = synergy::license::ILicense; Q_OBJECT @@ -59,7 +60,7 @@ public: explicit CoreProcess( IAppConfig &appConfig, IServerConfig &serverConfig, - const license::ILicense &license, + const ILicense &license, std::shared_ptr deps = std::make_shared()); void extracted(QString &app, QStringList &args); @@ -120,7 +121,7 @@ private: IAppConfig &m_appConfig; IServerConfig &m_serverConfig; - const license::ILicense &m_license; + const ILicense &m_license; std::shared_ptr m_pDeps; QString m_address; ProcessState m_processState = ProcessState::Stopped; diff --git a/src/lib/gui/dialogs/SettingsDialog.cpp b/src/lib/gui/dialogs/SettingsDialog.cpp index 1429b4ae2..a3b71f730 100644 --- a/src/lib/gui/dialogs/SettingsDialog.cpp +++ b/src/lib/gui/dialogs/SettingsDialog.cpp @@ -19,8 +19,8 @@ #include "SettingsDialog.h" #include "UpgradeDialog.h" -#include "gui/constants.h" #include "gui/core/CoreProcess.h" +#include "gui/license/license_config.h" #include "gui/tls/TlsCertificate.h" #include "gui/tls/TlsUtility.h" #include "gui/validators/ScreenNameValidator.h" @@ -88,7 +88,7 @@ void SettingsDialog::on_m_pButtonBrowseLog_clicked() { void SettingsDialog::on_m_pCheckBoxEnableTls_clicked(bool) { updateTlsControlsEnabled(); - if (kEnableActivation && !m_tlsUtility.isAvailable()) { + if (license::isActivationEnabled() && !m_tlsUtility.isAvailable()) { m_pCheckBoxEnableTls->setChecked(false); updateTlsControlsEnabled(); diff --git a/src/lib/gui/license/LicenseHandler.h b/src/lib/gui/license/LicenseHandler.h index 7c07433c1..d516c325e 100644 --- a/src/lib/gui/license/LicenseHandler.h +++ b/src/lib/gui/license/LicenseHandler.h @@ -18,6 +18,7 @@ #pragma once #include "gui/constants.h" +#include "gui/license/license_config.h" #include "license/License.h" #include "license/ProductEdition.h" @@ -52,6 +53,6 @@ signals: void invalidLicense() const; private: - bool m_enabled = synergy::gui::kEnableActivation; + bool m_enabled = synergy::gui::license::isActivationEnabled(); License m_license = License::invalid(); }; diff --git a/src/lib/gui/license/license_config.cpp b/src/lib/gui/license/license_config.cpp new file mode 100644 index 000000000..5f30317b4 --- /dev/null +++ b/src/lib/gui/license/license_config.cpp @@ -0,0 +1,58 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2024 Synergy Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "license_config.h" + +#include "string_utils.h" + +#include +#include + +namespace synergy::gui::license { + +#ifdef SYNERGY_LICENSED_PRODUCT +const bool kLicensedProduct = true; +#else +const bool kLicensedProduct = false; +#endif + +#ifdef SYNERGY_ENABLE_ACTIVATION +#ifndef SYNERGY_LICENSED_PRODUCT +#error "activation requires licensed product" +#endif +const bool kEnableActivation = true; +#else +const bool kEnableActivation = false; +#endif // SYNERGY_ENABLE_ACTIVATION + +bool isLicensedProduct() { + if (strToTrue(qEnvironmentVariable("SYNERGY_LICENSED_PRODUCT"))) { + return true; + } else { + return kLicensedProduct; + } +} + +bool isActivationEnabled() { + if (strToTrue(qEnvironmentVariable("SYNERGY_ENABLE_ACTIVATION"))) { + return true; + } else { + return kEnableActivation; + } +} + +} // namespace synergy::gui::license diff --git a/src/lib/gui/license/license_config.h b/src/lib/gui/license/license_config.h new file mode 100644 index 000000000..16fddf629 --- /dev/null +++ b/src/lib/gui/license/license_config.h @@ -0,0 +1,25 @@ +/* + * synergy -- mouse and keyboard sharing utility + * Copyright (C) 2024 Synergy Ltd. + * + * This package is free software; you can redistribute it and/or + * modify it under the terms of the GNU General Public License + * found in the file LICENSE that should have accompanied this file. + * + * This package is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#pragma once + +namespace synergy::gui::license { + +bool isLicensedProduct(); +bool isActivationEnabled(); + +} // namespace synergy::gui::license diff --git a/src/lib/gui/messages.cpp b/src/lib/gui/messages.cpp index 56ac6f28c..b03e18e8d 100644 --- a/src/lib/gui/messages.cpp +++ b/src/lib/gui/messages.cpp @@ -20,6 +20,7 @@ #include "Logger.h" #include "common/version.h" #include "constants.h" +#include "gui/license/license_config.h" #include "styles.h" #include @@ -30,6 +31,8 @@ #include #include +using namespace synergy::gui::license; + namespace synergy::gui::messages { struct Errors { @@ -60,7 +63,7 @@ void showErrorDialog( text = "

Sorry, a critical error has occurred.

"; } - if (kLicensedProduct) { + if (isLicensedProduct()) { text += QString(R"(

Please contact us)" " and copy/paste the following error:

") .arg(kUrlContact, kColorSecondary); diff --git a/src/lib/gui/tls/TlsUtility.cpp b/src/lib/gui/tls/TlsUtility.cpp index ebe20a423..9cad1fe82 100644 --- a/src/lib/gui/tls/TlsUtility.cpp +++ b/src/lib/gui/tls/TlsUtility.cpp @@ -18,20 +18,22 @@ #include "TlsUtility.h" #include "TlsCertificate.h" -#include "constants.h" +#include "gui/license/license_config.h" #include #include +using namespace synergy::license; +using namespace synergy::gui::license; + namespace synergy::gui { -TlsUtility::TlsUtility( - const IAppConfig &appConfig, const license::ILicense &license) +TlsUtility::TlsUtility(const IAppConfig &appConfig, const ILicense &license) : m_appConfig(appConfig), m_license(license) {} bool TlsUtility::isAvailable() const { - return !kEnableActivation || m_license.isTlsAvailable(); + return !isActivationEnabled() || m_license.isTlsAvailable(); } bool TlsUtility::isAvailableAndEnabled() const { diff --git a/src/lib/gui/tls/TlsUtility.h b/src/lib/gui/tls/TlsUtility.h index 575039801..3192fcf61 100644 --- a/src/lib/gui/tls/TlsUtility.h +++ b/src/lib/gui/tls/TlsUtility.h @@ -20,18 +20,18 @@ #include "gui/config/IAppConfig.h" #include "TlsCertificate.h" -#include "license/License.h" +#include "license/ILicense.h" #include namespace synergy::gui { class TlsUtility : public QObject { + using ILicense = synergy::license::ILicense; Q_OBJECT public: - explicit TlsUtility( - const IAppConfig &appConfig, const license::ILicense &license); + explicit TlsUtility(const IAppConfig &appConfig, const ILicense &license); bool generateCertificate(); bool persistCertificate(); @@ -52,7 +52,7 @@ public: private: const IAppConfig &m_appConfig; - const license::ILicense &m_license; + const ILicense &m_license; TlsCertificate m_certificate; };