Introduced new env vars for testing (#7436)

* New env vars for testing

* Update ChangeLog
This commit is contained in:
Nick Bolton 2024-08-11 22:34:48 +01:00 committed by GitHub
parent b7d64f962e
commit 30ea95fb3d
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
13 changed files with 133 additions and 46 deletions

View file

@ -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
#

View file

@ -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

View file

@ -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");
}

View file

@ -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

View file

@ -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 <QStandardPaths>
#include <QTimer>
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> deps)
IAppConfig &appConfig, IServerConfig &serverConfig, const ILicense &license,
std::shared_ptr<Deps> 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();
}

View file

@ -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 <QMutex>
#include <QObject>
@ -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> deps = std::make_shared<Deps>());
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<Deps> m_pDeps;
QString m_address;
ProcessState m_processState = ProcessState::Stopped;

View file

@ -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();

View file

@ -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();
};

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#include "license_config.h"
#include "string_utils.h"
#include <QString>
#include <QtGlobal>
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

View file

@ -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 <http://www.gnu.org/licenses/>.
*/
#pragma once
namespace synergy::gui::license {
bool isLicensedProduct();
bool isActivationEnabled();
} // namespace synergy::gui::license

View file

@ -20,6 +20,7 @@
#include "Logger.h"
#include "common/version.h"
#include "constants.h"
#include "gui/license/license_config.h"
#include "styles.h"
#include <QAction>
@ -30,6 +31,8 @@
#include <QTime>
#include <memory>
using namespace synergy::gui::license;
namespace synergy::gui::messages {
struct Errors {
@ -60,7 +63,7 @@ void showErrorDialog(
text = "<p>Sorry, a critical error has occurred.</p>";
}
if (kLicensedProduct) {
if (isLicensedProduct()) {
text += QString(R"(<p>Please <a href="%1" style="color: %2">contact us</a>)"
" and copy/paste the following error:</p>")
.arg(kUrlContact, kColorSecondary);

View file

@ -18,20 +18,22 @@
#include "TlsUtility.h"
#include "TlsCertificate.h"
#include "constants.h"
#include "gui/license/license_config.h"
#include <QFile>
#include <QString>
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 {

View file

@ -20,18 +20,18 @@
#include "gui/config/IAppConfig.h"
#include "TlsCertificate.h"
#include "license/License.h"
#include "license/ILicense.h"
#include <QObject>
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;
};