From 96b448237c92ba5af8babf9dacc462c238dfa594 Mon Sep 17 00:00:00 2001 From: Elias Steurer Date: Sat, 9 Jul 2022 18:24:14 +0200 Subject: [PATCH] Restore build info feature --- CMakeLists.txt | 30 ++++++++++++++------- ScreenPlay/inc/public/ScreenPlay/settings.h | 30 ++++++++++++--------- ScreenPlay/qml/Settings/Settings.qml | 2 +- ScreenPlay/src/settings.cpp | 7 +++-- 4 files changed, 43 insertions(+), 26 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 2d330ada..f70a5044 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -77,28 +77,38 @@ endif() find_package(Git REQUIRED) if(WIN32) - set(date_command "CMD") - set(date_arg "/c date /t") + set(DATE_COMMAND "CMD") + set(DATE_ARG "/c date /t") elseif(APPLE) - set(date_command "date") - set(date_arg "") + set(DATE_COMMAND "date") + set(DATE_ARG " +%y.%m.%d") elseif(UNIX) - set(date_command "date") - set(date_arg "") + set(DATE_COMMAND "date") + set(DATE_ARG "") endif() execute_process( - COMMAND ${date_command} ${date_arg} + COMMAND ${DATE_COMMAND} ${DATE_ARG} WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE BUILD_DATE - OUTPUT_STRIP_TRAILING_WHITESPACE) + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) execute_process( - COMMAND "${GIT_EXECUTABLE}" describe --always + COMMAND "${GIT_EXECUTABLE}" rev-parse --abbrev-ref HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE GIT_BRANCH_NAME + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) + +execute_process( + COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" OUTPUT_VARIABLE GIT_COMMIT_HASH - OUTPUT_STRIP_TRAILING_WHITESPACE) + ERROR_QUIET OUTPUT_STRIP_TRAILING_WHITESPACE) +add_compile_definitions(BUILD_TYPE="${CMAKE_BUILD_TYPE}") +add_compile_definitions(BUILD_DATE="${BUILD_DATE}") +add_compile_definitions(GIT_BRANCH_NAME="${GIT_BRANCH_NAME}") +add_compile_definitions(GIT_COMMIT_HASH="${GIT_COMMIT_HASH}") if(UNIX AND NOT APPLE) # Fixes QWebEngine linker errors on Ubuntu 20.04 diff --git a/ScreenPlay/inc/public/ScreenPlay/settings.h b/ScreenPlay/inc/public/ScreenPlay/settings.h index aaae8530..d64cf0bc 100644 --- a/ScreenPlay/inc/public/ScreenPlay/settings.h +++ b/ScreenPlay/inc/public/ScreenPlay/settings.h @@ -92,7 +92,7 @@ class Settings : public QObject { Q_PROPERTY(Theme theme READ theme WRITE setTheme NOTIFY themeChanged) Q_PROPERTY(QString decoder READ decoder WRITE setDecoder NOTIFY decoderChanged) - Q_PROPERTY(QString gitBuildHash READ gitBuildHash WRITE setGitBuildHash NOTIFY gitBuildHashChanged) + Q_PROPERTY(QString buildInfos READ buildInfos WRITE setBuildInfos NOTIFY buildInfosChanged) Q_PROPERTY(QString font READ font WRITE setFont NOTIFY fontChanged) public: @@ -144,7 +144,6 @@ public: bool autostart() const { return m_autostart; } bool highPriorityStart() const { return m_highPriorityStart; } QString decoder() const { return m_decoder; } - QString gitBuildHash() const { return m_gitBuildHash; } bool silentStart() const { return m_silentStart; } bool anonymousTelemetry() const { return m_anonymousTelemetry; } bool checkWallpaperVisible() const { return m_checkWallpaperVisible; } @@ -157,6 +156,11 @@ public: void setupLanguage(); + const QString &buildInfos() const + { + return m_buildInfos; + } + signals: void requestRetranslation(); void resetInstalledListmodel(); @@ -167,7 +171,6 @@ signals: void decoderChanged(QString decoder); void setMainWindowVisible(bool visible); void offlineModeChanged(bool offlineMode); - void gitBuildHashChanged(QString gitBuildHash); void silentStartChanged(bool silentStart); void anonymousTelemetryChanged(bool anonymousTelemetry); void checkWallpaperVisibleChanged(bool checkWallpaperVisible); @@ -178,6 +181,8 @@ signals: void steamVersionChanged(bool steamVersion); void desktopEnvironmentChanged(DesktopEnvironment desktopEnvironment); + void buildInfosChanged(const QString &buildInfos); + public slots: void writeJsonFileFromResource(const QString& filename); void setupWidgetAndWindowPaths(); @@ -304,15 +309,6 @@ public slots: emit offlineModeChanged(m_offlineMode); } - void setGitBuildHash(QString gitBuildHash) - { - if (m_gitBuildHash == gitBuildHash) - return; - - m_gitBuildHash = gitBuildHash; - emit gitBuildHashChanged(m_gitBuildHash); - } - void setSilentStart(bool silentStart) { if (m_silentStart == silentStart) @@ -404,6 +400,14 @@ public slots: emit desktopEnvironmentChanged(m_desktopEnvironment); } + void setBuildInfos(const QString &buildInfos) + { + if (m_buildInfos == buildInfos) + return; + m_buildInfos = buildInfos; + emit buildInfosChanged(m_buildInfos); + } + private: void restoreDefault(const QString& appConfigLocation, const QString& settingsFileType); void initInstalledPath(); @@ -422,7 +426,6 @@ private: bool m_silentStart { false }; bool m_anonymousTelemetry { true }; - QString m_gitBuildHash; QString m_decoder; ScreenPlay::FillMode::FillMode m_videoFillMode { ScreenPlay::FillMode::FillMode::Cover }; Language m_language { Language::En_US }; @@ -430,5 +433,6 @@ private: QString m_font { "Roboto" }; bool m_steamVersion { false }; DesktopEnvironment m_desktopEnvironment = DesktopEnvironment::Unknown; + QString m_buildInfos; }; } diff --git a/ScreenPlay/qml/Settings/Settings.qml b/ScreenPlay/qml/Settings/Settings.qml index 6aabba7d..1dfd225b 100644 --- a/ScreenPlay/qml/Settings/Settings.qml +++ b/ScreenPlay/qml/Settings/Settings.qml @@ -448,7 +448,7 @@ Item { SettingsButton { icon.source: "qrc:/qml/ScreenPlayApp/assets/icons/icon_launch.svg" headline: qsTr("Version") - description: qsTr("ScreenPlay Build Version \n") + App.settings.gitBuildHash + description: App.settings.buildInfos buttonText: qsTr("Open Changelog") onButtonPressed: Qt.openUrlExternally( "https://gitlab.com/kelteseth/ScreenPlay/-/releases") diff --git a/ScreenPlay/src/settings.cpp b/ScreenPlay/src/settings.cpp index f6614e7c..4d1bda3a 100644 --- a/ScreenPlay/src/settings.cpp +++ b/ScreenPlay/src/settings.cpp @@ -40,8 +40,11 @@ Settings::Settings(const std::shared_ptr& globalVariables, : QObject(parent) , m_globalVariables { globalVariables } { - const QString qtVersion = QString("Qt Version: %1.%2.%3").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH); - setGitBuildHash(COMPILE_INFO + qtVersion); + const QString qtVersion = QString("Qt Version: %1.%2.%3\n").arg(QT_VERSION_MAJOR).arg(QT_VERSION_MINOR).arg(QT_VERSION_PATCH); + const QString buildType = QString("Build type: %1\n").arg(BUILD_TYPE); + const QString buildDate = QString("Build date: %1\n").arg(BUILD_DATE); + const QString commitHash = QString("Git commit hash: %1").arg(GIT_COMMIT_HASH); + setBuildInfos(qtVersion + buildType + buildDate + commitHash); #ifdef SCREENPLAY_STEAM setSteamVersion(true); #endif