From 94fc240086c798fc00d93cac27788eff0325f5cc Mon Sep 17 00:00:00 2001 From: Dmitry Date: Fri, 24 Apr 2026 14:47:01 +0300 Subject: [PATCH] Show build version in app header --- CMakeLists.txt | 26 +++++++++++++++++++++++++- src/app_auth.cpp | 3 ++- src/app_shell.cpp | 6 +++++- src/build_config.h.in | 1 + 4 files changed, 33 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index bd02f2f..0799e4e 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,6 +7,7 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_EXTENSIONS OFF) find_program(CLANG_FORMAT_BIN clang-format) +find_package(Git QUIET) include(FetchContent) @@ -16,6 +17,7 @@ set(TELEGRAM_TUI_TDLIB_ROOT "" set(CURSES_NEED_WIDE TRUE) find_package(Curses REQUIRED) +find_package(Threads REQUIRED) find_package(nlohmann_json QUIET) if(NOT nlohmann_json_FOUND) @@ -37,6 +39,27 @@ endif() set(TELEGRAM_TUI_BUILD_API_ID "") set(TELEGRAM_TUI_BUILD_API_HASH "") +set(TELEGRAM_TUI_BUILD_VERSION "${PROJECT_VERSION}") +set(TELEGRAM_TUI_BUILD_COMMIT "") +if(GIT_FOUND AND EXISTS "${CMAKE_SOURCE_DIR}/.git") + execute_process( + COMMAND "${GIT_EXECUTABLE}" rev-parse --short HEAD + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE TELEGRAM_TUI_BUILD_COMMIT + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + execute_process( + COMMAND "${GIT_EXECUTABLE}" describe --tags --always --dirty + WORKING_DIRECTORY "${CMAKE_SOURCE_DIR}" + OUTPUT_VARIABLE TELEGRAM_TUI_GIT_DESCRIBE + OUTPUT_STRIP_TRAILING_WHITESPACE + ERROR_QUIET + ) + if(TELEGRAM_TUI_GIT_DESCRIBE) + set(TELEGRAM_TUI_BUILD_VERSION "${PROJECT_VERSION}+${TELEGRAM_TUI_GIT_DESCRIBE}") + endif() +endif() if(TELEGRAM_TUI_APP_CONFIG_PATH AND EXISTS "${TELEGRAM_TUI_APP_CONFIG_PATH}") file(READ "${TELEGRAM_TUI_APP_CONFIG_PATH}" TELEGRAM_TUI_APP_CONFIG_JSON) @@ -130,7 +153,8 @@ if(CLANG_FORMAT_BIN) endif() target_include_directories(shinoa PRIVATE ${CURSES_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR}) -target_link_libraries(shinoa PRIVATE ${CURSES_LIBRARIES} nlohmann_json::nlohmann_json) +target_link_libraries(shinoa PRIVATE ${CURSES_LIBRARIES} Threads::Threads + nlohmann_json::nlohmann_json) if(TELEGRAM_TUI_USE_SYSTEM_TDLIB) target_link_libraries(shinoa PRIVATE Td::TdJson) diff --git a/src/app_auth.cpp b/src/app_auth.cpp index 9cf7fa7..43b4e72 100644 --- a/src/app_auth.cpp +++ b/src/app_auth.cpp @@ -9,6 +9,7 @@ #include +#include "build_config.h" #include "util.h" namespace telegram_tui { @@ -242,7 +243,7 @@ void App::send_tdlib_parameters() { {"system_language_code", "en"}, {"device_model", "shinoa"}, {"system_version", "Linux"}, - {"application_version", "0.1.0"}, + {"application_version", TELEGRAM_TUI_BUILD_VERSION}, {"enable_storage_optimizer", true}, {"ignore_file_names", false}, }); diff --git a/src/app_shell.cpp b/src/app_shell.cpp index 2a3797a..4682d96 100644 --- a/src/app_shell.cpp +++ b/src/app_shell.cpp @@ -6,6 +6,7 @@ #include #include "app_ui.h" +#include "build_config.h" #include "util.h" namespace telegram_tui { @@ -88,7 +89,10 @@ void App::draw() { attron(A_REVERSE); mvhline(header_y, 0, ' ', width); - const std::string header_label = use_test_dc_ ? "shinoa [TEST DC]" : "shinoa"; + std::string header_label = std::string("shinoa ") + TELEGRAM_TUI_BUILD_VERSION; + if (use_test_dc_) { + header_label += " [TEST DC]"; + } mvprintw(header_y, 1, "%s", header_label.c_str()); const std::string auth_label = authorized_ ? "ready" : current_auth_label(); const int auth_x = std::max(1, width - static_cast(auth_label.size()) - 2); diff --git a/src/build_config.h.in b/src/build_config.h.in index 3bdf9c4..0ee5fb3 100644 --- a/src/build_config.h.in +++ b/src/build_config.h.in @@ -1,4 +1,5 @@ #pragma once +#define TELEGRAM_TUI_BUILD_VERSION "@TELEGRAM_TUI_BUILD_VERSION@" #define TELEGRAM_TUI_BUILD_API_ID "@TELEGRAM_TUI_BUILD_API_ID@" #define TELEGRAM_TUI_BUILD_API_HASH "@TELEGRAM_TUI_BUILD_API_HASH@"