diff --git a/src/apps/deskflow-daemon/CMakeLists.txt b/src/apps/deskflow-daemon/CMakeLists.txt index 1e3b3c821..523f34d98 100644 --- a/src/apps/deskflow-daemon/CMakeLists.txt +++ b/src/apps/deskflow-daemon/CMakeLists.txt @@ -25,6 +25,7 @@ if(WIN32) net platform app + common ${libs} Qt6::Core) diff --git a/src/apps/deskflow-daemon/deskflow-daemon.cpp b/src/apps/deskflow-daemon/deskflow-daemon.cpp index c5389a205..68b3ac2f6 100644 --- a/src/apps/deskflow-daemon/deskflow-daemon.cpp +++ b/src/apps/deskflow-daemon/deskflow-daemon.cpp @@ -8,6 +8,7 @@ #include "arch/Arch.h" #include "base/Log.h" #include "common/constants.h" +#include "common/version.h" #include "deskflow/DaemonApp.h" #include "deskflow/ipc/DaemonIpcServer.h" @@ -61,7 +62,7 @@ int main(int argc, char **argv) // which is not useful for troubleshooting Windows services. // It's important to write the version number to the log file so we can be certain the old daemon // was uninstalled, since sometimes Windows services can get stuck and fail to be removed. - LOG_PRINT("%s Daemon (v%s)", kAppName, kVersion); + LOG_PRINT("%s Daemon v%s", kAppName, displayVersion().toStdString().c_str()); switch (initResult) { using enum DaemonApp::InitResult; diff --git a/src/apps/deskflow-gui/CMakeLists.txt b/src/apps/deskflow-gui/CMakeLists.txt index 6b77ddd00..7b0901888 100644 --- a/src/apps/deskflow-gui/CMakeLists.txt +++ b/src/apps/deskflow-gui/CMakeLists.txt @@ -107,6 +107,7 @@ add_executable(${target} WIN32 MACOSX_BUNDLE target_link_libraries( ${target} gui + common Qt6::Core Qt6::Widgets Qt6::Network) diff --git a/src/apps/deskflow-gui/dialogs/AboutDialog.cpp b/src/apps/deskflow-gui/dialogs/AboutDialog.cpp index fff4e4bc3..4fce649ac 100644 --- a/src/apps/deskflow-gui/dialogs/AboutDialog.cpp +++ b/src/apps/deskflow-gui/dialogs/AboutDialog.cpp @@ -10,7 +10,7 @@ #include "ui_AboutDialog.h" #include "common/constants.h" -#include "gui/style_utils.h" +#include "common/version.h" #include #include @@ -32,15 +32,7 @@ AboutDialog::AboutDialog(QWidget *parent) : QDialog(parent), ui{std::make_unique ui->btnCopyVersion->setIcon(QIcon::fromTheme(QIcon::ThemeIcon::EditCopy)); connect(ui->btnCopyVersion, &QPushButton::clicked, this, &AboutDialog::copyVersionText); - // Set up the displayed version number - auto versionString = QString(kVersion); - if (versionString.endsWith(QStringLiteral(".0"))) { - versionString.chop(2); - } else { - versionString.append(QStringLiteral(" (%1)").arg(kVersionGitSha)); - } - - ui->lblVersion->setText(versionString); + ui->lblVersion->setText(displayVersion()); ui->lblDescription->setText(kAppDescription); ui->lblCopyright->setText(kCopyright); diff --git a/src/lib/common/CMakeLists.txt b/src/lib/common/CMakeLists.txt index e9e1bdae9..4dd661ca1 100644 --- a/src/lib/common/CMakeLists.txt +++ b/src/lib/common/CMakeLists.txt @@ -7,6 +7,7 @@ configure_file(constants.h.in constants.h @ONLY) add_library(common INTERFACE common.h + version.h IInterface.h stdbitset.h stddeque.h @@ -24,7 +25,9 @@ add_library(common INTERFACE ${CMAKE_CURRENT_BINARY_DIR}/constants.h ) +find_package(Qt6 COMPONENTS Core) +target_link_libraries(common INTERFACE Qt6::Core) + if(APPLE) target_sources(common INTERFACE MacOSXPrecomp.h) endif() - diff --git a/src/lib/common/common.h b/src/lib/common/common.h index 9356e73d3..5912d1b56 100644 --- a/src/lib/common/common.h +++ b/src/lib/common/common.h @@ -41,11 +41,12 @@ enum kExitArgs = 3, // bad arguments kExitConfig = 4, // cannot read configuration }; +namespace deskflow::common { #if WINAPI_MSWINDOWS -namespace deskflow::common { const auto kCloseEventName = "Global\\DeskflowClose"; -} #endif + +} // namespace deskflow::common diff --git a/src/lib/common/version.h b/src/lib/common/version.h new file mode 100644 index 000000000..92260fa7b --- /dev/null +++ b/src/lib/common/version.h @@ -0,0 +1,28 @@ +/* + * Deskflow -- mouse and keyboard sharing utility + * SPDX-FileCopyrightText: (C) 2025 Symless Ltd. + * SPDX-License-Identifier: GPL-2.0-only WITH LicenseRef-OpenSSL-Exception + */ + +#pragma once + +#include "common/constants.h" + +#include + +/** + * @brief Get the version number string for display. + * + * If the version number ends with ".0", the ".0" is removed. + * If the version number does not end with ".0", the git SHA is appended in parentheses. + */ +inline QString displayVersion() +{ + auto versionString = QString(kVersion); + if (versionString.endsWith(QStringLiteral(".0"))) { + versionString.chop(2); + } else { + versionString.append(QStringLiteral(" (%1)").arg(kVersionGitSha)); + } + return versionString; +}