Compare commits
4 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
| 5a5677a994 | |||
| 94fc240086 | |||
| c39071b61a | |||
| 7b35201799 |
@@ -16,7 +16,8 @@ jobs:
|
|||||||
RELEASE_TAG: latest
|
RELEASE_TAG: latest
|
||||||
ARCHIVE_NAME: shinoa-linux-x86_64.tar.gz
|
ARCHIVE_NAME: shinoa-linux-x86_64.tar.gz
|
||||||
CHECKSUM_NAME: shinoa-linux-x86_64.tar.gz.sha256
|
CHECKSUM_NAME: shinoa-linux-x86_64.tar.gz.sha256
|
||||||
TDLIB_ARCHIVE_URL: ${{ gitea.server_url }}/${{ gitea.repository }}/releases/download/tdlib/tdlib-linux-x86_64.tar.gz
|
TDLIB_RELEASE_TAG: v1.8.63
|
||||||
|
TDLIB_ARCHIVE_URL: https://git.mshq.dev/AxiFisk/shinoa-tdlib/releases/download/${{ env.TDLIB_RELEASE_TAG }}/tdlib-linux-x86_64.tar.gz
|
||||||
steps:
|
steps:
|
||||||
- name: Check out repository
|
- name: Check out repository
|
||||||
uses: https://github.com/actions/checkout@v4
|
uses: https://github.com/actions/checkout@v4
|
||||||
@@ -54,12 +55,19 @@ jobs:
|
|||||||
test -f tdlib/lib/libtdjson.so
|
test -f tdlib/lib/libtdjson.so
|
||||||
|
|
||||||
- name: Build release bundle
|
- name: Build release bundle
|
||||||
|
env:
|
||||||
|
TELEGRAM_TUI_BUILD_API_ID: ${{ secrets.TELEGRAM_API_ID }}
|
||||||
|
TELEGRAM_TUI_BUILD_API_HASH: ${{ secrets.TELEGRAM_API_HASH }}
|
||||||
run: |
|
run: |
|
||||||
set -euo pipefail
|
set -euo pipefail
|
||||||
rm -rf build dist
|
rm -rf build dist
|
||||||
|
|
||||||
|
test -n "${TELEGRAM_TUI_BUILD_API_ID}"
|
||||||
|
test -n "${TELEGRAM_TUI_BUILD_API_HASH}"
|
||||||
|
|
||||||
cmake -S . -B build \
|
cmake -S . -B build \
|
||||||
-DCMAKE_BUILD_TYPE=Release \
|
-DCMAKE_BUILD_TYPE=Release \
|
||||||
|
-DTELEGRAM_TUI_REQUIRE_BUILD_CREDENTIALS=ON \
|
||||||
-DTELEGRAM_TUI_TDLIB_ROOT="$PWD/tdlib"
|
-DTELEGRAM_TUI_TDLIB_ROOT="$PWD/tdlib"
|
||||||
cmake --build build -j"$(nproc)"
|
cmake --build build -j"$(nproc)"
|
||||||
|
|
||||||
|
|||||||
@@ -7,15 +7,30 @@ set(CMAKE_CXX_STANDARD_REQUIRED ON)
|
|||||||
set(CMAKE_CXX_EXTENSIONS OFF)
|
set(CMAKE_CXX_EXTENSIONS OFF)
|
||||||
|
|
||||||
find_program(CLANG_FORMAT_BIN clang-format)
|
find_program(CLANG_FORMAT_BIN clang-format)
|
||||||
|
find_package(Git QUIET)
|
||||||
|
|
||||||
include(FetchContent)
|
include(FetchContent)
|
||||||
|
|
||||||
option(TELEGRAM_TUI_USE_SYSTEM_TDLIB "Use an installed TDLib package instead of fetching it." OFF)
|
option(TELEGRAM_TUI_USE_SYSTEM_TDLIB "Use an installed TDLib package instead of fetching it." OFF)
|
||||||
|
option(TELEGRAM_TUI_REQUIRE_BUILD_CREDENTIALS
|
||||||
|
"Fail configure if build credentials are not provided." OFF)
|
||||||
set(TELEGRAM_TUI_TDLIB_ROOT ""
|
set(TELEGRAM_TUI_TDLIB_ROOT ""
|
||||||
CACHE PATH "Path to a prebuilt TDLib root containing include/ and lib/ directories.")
|
CACHE PATH "Path to a prebuilt TDLib root containing include/ and lib/ directories.")
|
||||||
|
|
||||||
set(CURSES_NEED_WIDE TRUE)
|
set(CURSES_NEED_WIDE TRUE)
|
||||||
find_package(Curses REQUIRED)
|
find_package(Curses REQUIRED)
|
||||||
|
find_package(Threads REQUIRED)
|
||||||
|
|
||||||
|
find_package(nlohmann_json QUIET)
|
||||||
|
if(NOT nlohmann_json_FOUND)
|
||||||
|
FetchContent_Declare(
|
||||||
|
nlohmann_json
|
||||||
|
GIT_REPOSITORY https://github.com/nlohmann/json.git
|
||||||
|
GIT_TAG v3.11.3
|
||||||
|
GIT_SHALLOW TRUE
|
||||||
|
)
|
||||||
|
FetchContent_MakeAvailable(nlohmann_json)
|
||||||
|
endif()
|
||||||
|
|
||||||
set(TELEGRAM_TUI_APP_CONFIG_PATH "")
|
set(TELEGRAM_TUI_APP_CONFIG_PATH "")
|
||||||
if(DEFINED ENV{XDG_DATA_HOME} AND NOT "$ENV{XDG_DATA_HOME}" STREQUAL "")
|
if(DEFINED ENV{XDG_DATA_HOME} AND NOT "$ENV{XDG_DATA_HOME}" STREQUAL "")
|
||||||
@@ -26,22 +41,67 @@ endif()
|
|||||||
|
|
||||||
set(TELEGRAM_TUI_BUILD_API_ID "")
|
set(TELEGRAM_TUI_BUILD_API_ID "")
|
||||||
set(TELEGRAM_TUI_BUILD_API_HASH "")
|
set(TELEGRAM_TUI_BUILD_API_HASH "")
|
||||||
if(TELEGRAM_TUI_APP_CONFIG_PATH AND EXISTS "${TELEGRAM_TUI_APP_CONFIG_PATH}")
|
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(DEFINED ENV{TELEGRAM_TUI_BUILD_API_ID} AND NOT "$ENV{TELEGRAM_TUI_BUILD_API_ID}" STREQUAL "")
|
||||||
|
set(TELEGRAM_TUI_BUILD_API_ID "$ENV{TELEGRAM_TUI_BUILD_API_ID}")
|
||||||
|
elseif(DEFINED ENV{TELEGRAM_API_ID} AND NOT "$ENV{TELEGRAM_API_ID}" STREQUAL "")
|
||||||
|
set(TELEGRAM_TUI_BUILD_API_ID "$ENV{TELEGRAM_API_ID}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if(DEFINED ENV{TELEGRAM_TUI_BUILD_API_HASH} AND NOT "$ENV{TELEGRAM_TUI_BUILD_API_HASH}" STREQUAL "")
|
||||||
|
set(TELEGRAM_TUI_BUILD_API_HASH "$ENV{TELEGRAM_TUI_BUILD_API_HASH}")
|
||||||
|
elseif(DEFINED ENV{TELEGRAM_API_HASH} AND NOT "$ENV{TELEGRAM_API_HASH}" STREQUAL "")
|
||||||
|
set(TELEGRAM_TUI_BUILD_API_HASH "$ENV{TELEGRAM_API_HASH}")
|
||||||
|
endif()
|
||||||
|
|
||||||
|
if((TELEGRAM_TUI_BUILD_API_ID STREQUAL "" OR TELEGRAM_TUI_BUILD_API_HASH STREQUAL "") AND
|
||||||
|
TELEGRAM_TUI_APP_CONFIG_PATH AND EXISTS "${TELEGRAM_TUI_APP_CONFIG_PATH}")
|
||||||
file(READ "${TELEGRAM_TUI_APP_CONFIG_PATH}" TELEGRAM_TUI_APP_CONFIG_JSON)
|
file(READ "${TELEGRAM_TUI_APP_CONFIG_PATH}" TELEGRAM_TUI_APP_CONFIG_JSON)
|
||||||
|
|
||||||
string(REGEX MATCH "\"api_id\"[ \t\r\n]*:[ \t\r\n]*\"?([0-9]+)\"?"
|
if(TELEGRAM_TUI_BUILD_API_ID STREQUAL "")
|
||||||
TELEGRAM_TUI_APP_CONFIG_API_ID_MATCH "${TELEGRAM_TUI_APP_CONFIG_JSON}")
|
string(REGEX MATCH "\"api_id\"[ \t\r\n]*:[ \t\r\n]*\"?([0-9]+)\"?"
|
||||||
if(CMAKE_MATCH_1)
|
TELEGRAM_TUI_APP_CONFIG_API_ID_MATCH "${TELEGRAM_TUI_APP_CONFIG_JSON}")
|
||||||
set(TELEGRAM_TUI_BUILD_API_ID "${CMAKE_MATCH_1}")
|
if(CMAKE_MATCH_1)
|
||||||
|
set(TELEGRAM_TUI_BUILD_API_ID "${CMAKE_MATCH_1}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
string(REGEX MATCH "\"api_hash\"[ \t\r\n]*:[ \t\r\n]*\"([^\"]+)\""
|
if(TELEGRAM_TUI_BUILD_API_HASH STREQUAL "")
|
||||||
TELEGRAM_TUI_APP_CONFIG_API_HASH_MATCH "${TELEGRAM_TUI_APP_CONFIG_JSON}")
|
string(REGEX MATCH "\"api_hash\"[ \t\r\n]*:[ \t\r\n]*\"([^\"]+)\""
|
||||||
if(CMAKE_MATCH_1)
|
TELEGRAM_TUI_APP_CONFIG_API_HASH_MATCH "${TELEGRAM_TUI_APP_CONFIG_JSON}")
|
||||||
set(TELEGRAM_TUI_BUILD_API_HASH "${CMAKE_MATCH_1}")
|
if(CMAKE_MATCH_1)
|
||||||
|
set(TELEGRAM_TUI_BUILD_API_HASH "${CMAKE_MATCH_1}")
|
||||||
|
endif()
|
||||||
endif()
|
endif()
|
||||||
endif()
|
endif()
|
||||||
|
|
||||||
|
if(TELEGRAM_TUI_REQUIRE_BUILD_CREDENTIALS AND
|
||||||
|
(TELEGRAM_TUI_BUILD_API_ID STREQUAL "" OR TELEGRAM_TUI_BUILD_API_HASH STREQUAL ""))
|
||||||
|
message(FATAL_ERROR
|
||||||
|
"Build credentials are required. Set TELEGRAM_TUI_BUILD_API_ID and "
|
||||||
|
"TELEGRAM_TUI_BUILD_API_HASH (or TELEGRAM_API_ID/TELEGRAM_API_HASH).")
|
||||||
|
endif()
|
||||||
|
|
||||||
configure_file(
|
configure_file(
|
||||||
${CMAKE_SOURCE_DIR}/src/build_config.h.in
|
${CMAKE_SOURCE_DIR}/src/build_config.h.in
|
||||||
${CMAKE_CURRENT_BINARY_DIR}/build_config.h
|
${CMAKE_CURRENT_BINARY_DIR}/build_config.h
|
||||||
@@ -119,7 +179,8 @@ if(CLANG_FORMAT_BIN)
|
|||||||
endif()
|
endif()
|
||||||
|
|
||||||
target_include_directories(shinoa PRIVATE ${CURSES_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
|
target_include_directories(shinoa PRIVATE ${CURSES_INCLUDE_DIRS} ${CMAKE_CURRENT_BINARY_DIR})
|
||||||
target_link_libraries(shinoa PRIVATE ${CURSES_LIBRARIES})
|
target_link_libraries(shinoa PRIVATE ${CURSES_LIBRARIES} Threads::Threads
|
||||||
|
nlohmann_json::nlohmann_json)
|
||||||
|
|
||||||
if(TELEGRAM_TUI_USE_SYSTEM_TDLIB)
|
if(TELEGRAM_TUI_USE_SYSTEM_TDLIB)
|
||||||
target_link_libraries(shinoa PRIVATE Td::TdJson)
|
target_link_libraries(shinoa PRIVATE Td::TdJson)
|
||||||
|
|||||||
15
README.md
15
README.md
@@ -31,6 +31,9 @@ cmake --build build -j
|
|||||||
During configure, CMake also checks the app config at
|
During configure, CMake also checks the app config at
|
||||||
`$XDG_DATA_HOME/telegram-tui/config.json` or `~/.local/share/telegram-tui/config.json`.
|
`$XDG_DATA_HOME/telegram-tui/config.json` or `~/.local/share/telegram-tui/config.json`.
|
||||||
If that file contains `api_id` and `api_hash`, they are embedded into the build.
|
If that file contains `api_id` and `api_hash`, they are embedded into the build.
|
||||||
|
For CI or release builds, prefer setting `TELEGRAM_TUI_BUILD_API_ID` and
|
||||||
|
`TELEGRAM_TUI_BUILD_API_HASH` in the environment so credentials come from secrets instead of
|
||||||
|
local config.
|
||||||
|
|
||||||
## Run
|
## Run
|
||||||
|
|
||||||
@@ -64,10 +67,12 @@ archive plus checksum to the Gitea Generic Package Registry under the `tdlib` pa
|
|||||||
It also refreshes a `latest/tdlib-latest.json` manifest with the newest published version.
|
It also refreshes a `latest/tdlib-latest.json` manifest with the newest published version.
|
||||||
|
|
||||||
The repository also includes [`.gitea/workflows/release-app.yaml`](.gitea/workflows/release-app.yaml),
|
The repository also includes [`.gitea/workflows/release-app.yaml`](.gitea/workflows/release-app.yaml),
|
||||||
which downloads a prebuilt TDLib bundle from this repository's `tdlib` release tag, builds a
|
which downloads a prebuilt TDLib bundle from the `shinoa-tdlib` repository using a pinned
|
||||||
|
version tag such as `v1.8.63`, builds a
|
||||||
rolling `latest` app release, and publishes an archive containing `usr/bin/shinoa` plus the
|
rolling `latest` app release, and publishes an archive containing `usr/bin/shinoa` plus the
|
||||||
bundled `usr/lib/libtdjson.so*`. The root `PKGBUILD` installs that prebuilt release as
|
bundled `usr/lib/libtdjson.so*`. The root `PKGBUILD` installs that prebuilt release as
|
||||||
`shinoa-bin`.
|
`shinoa-bin`. That workflow expects Gitea secrets named `TELEGRAM_API_ID` and
|
||||||
|
`TELEGRAM_API_HASH`. Release builds are configured to fail if those secrets are missing.
|
||||||
|
|
||||||
To prepare the TDLib bundle on your own machine:
|
To prepare the TDLib bundle on your own machine:
|
||||||
|
|
||||||
@@ -78,8 +83,10 @@ cmake --install td-build
|
|||||||
./scripts/package-tdlib.sh td-install tdlib-linux-x86_64.tar.gz
|
./scripts/package-tdlib.sh td-install tdlib-linux-x86_64.tar.gz
|
||||||
```
|
```
|
||||||
|
|
||||||
Upload `tdlib-linux-x86_64.tar.gz` to a release tagged `tdlib` in this repository. After that,
|
Publish `tdlib-linux-x86_64.tar.gz` to the `shinoa-tdlib` repository under a versioned tag such
|
||||||
the `Release App` workflow can consume it and publish the app bundle.
|
as `v1.8.63`. Then update `TDLIB_RELEASE_TAG` in
|
||||||
|
[`.gitea/workflows/release-app.yaml`](.gitea/workflows/release-app.yaml) and run the
|
||||||
|
`Release App` workflow.
|
||||||
|
|
||||||
## Keys
|
## Keys
|
||||||
|
|
||||||
|
|||||||
87
src/app.cpp
87
src/app.cpp
@@ -1,5 +1,9 @@
|
|||||||
#include "app.h"
|
#include "app.h"
|
||||||
|
|
||||||
|
#include <array>
|
||||||
|
#include <cstdio>
|
||||||
|
#include <future>
|
||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
|
||||||
#include "build_config.h"
|
#include "build_config.h"
|
||||||
@@ -14,6 +18,66 @@ bool is_truthy_env_value(const std::string &value) {
|
|||||||
value == "YES" || value == "on" || value == "ON";
|
value == "YES" || value == "on" || value == "ON";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string shell_quote(const std::string &value) {
|
||||||
|
std::string quoted = "'";
|
||||||
|
for (char ch : value) {
|
||||||
|
if (ch == '\'') {
|
||||||
|
quoted += "'\\''";
|
||||||
|
} else {
|
||||||
|
quoted.push_back(ch);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
quoted.push_back('\'');
|
||||||
|
return quoted;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string run_command_capture(const std::string &command) {
|
||||||
|
FILE *pipe = popen(command.c_str(), "r");
|
||||||
|
if (pipe == nullptr) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string output;
|
||||||
|
std::array<char, 4096> buffer{};
|
||||||
|
while (std::fgets(buffer.data(), static_cast<int>(buffer.size()), pipe) != nullptr) {
|
||||||
|
output += buffer.data();
|
||||||
|
}
|
||||||
|
if (pclose(pipe) != 0) {
|
||||||
|
return {};
|
||||||
|
}
|
||||||
|
return output;
|
||||||
|
}
|
||||||
|
|
||||||
|
std::optional<std::string> fetch_update_notice() {
|
||||||
|
static constexpr const char *kLatestReleaseApiUrl =
|
||||||
|
"https://git.mshq.dev/api/v1/repos/AxiFisk/shinoa/releases/tags/latest";
|
||||||
|
|
||||||
|
if (std::string(TELEGRAM_TUI_BUILD_COMMIT).empty()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
const std::string response =
|
||||||
|
run_command_capture("curl -fsSL " + shell_quote(kLatestReleaseApiUrl) + " 2>/dev/null");
|
||||||
|
if (response.empty()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
const json release = json::parse(response, nullptr, true, true);
|
||||||
|
const std::string target_commit = safe_string(release, "target_commitish");
|
||||||
|
if (target_commit.empty()) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
const std::string current_commit = TELEGRAM_TUI_BUILD_COMMIT;
|
||||||
|
if (target_commit == current_commit || target_commit.rfind(current_commit, 0) == 0) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
return std::string("Update available");
|
||||||
|
} catch (const json::exception &) {
|
||||||
|
return std::nullopt;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
App::App() {
|
App::App() {
|
||||||
@@ -49,6 +113,8 @@ App::App() {
|
|||||||
if (use_test_dc_) {
|
if (use_test_dc_) {
|
||||||
status_line_ = "Starting TDLib in test DC mode...";
|
status_line_ = "Starting TDLib in test DC mode...";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
start_update_check();
|
||||||
}
|
}
|
||||||
|
|
||||||
int App::run() {
|
int App::run() {
|
||||||
@@ -80,6 +146,27 @@ int App::run() {
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void App::start_update_check() {
|
||||||
|
update_check_future_ =
|
||||||
|
std::async(std::launch::async, []() { return fetch_update_notice(); });
|
||||||
|
}
|
||||||
|
|
||||||
|
bool App::refresh_update_check_result() {
|
||||||
|
if (!update_check_future_.valid()) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (update_check_future_.wait_for(std::chrono::seconds(0)) != std::future_status::ready) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
const auto notice = update_check_future_.get();
|
||||||
|
if (notice == update_notice_) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
update_notice_ = notice.value_or(std::string());
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
std::optional<std::int64_t> App::highlighted_chat_id() const {
|
std::optional<std::int64_t> App::highlighted_chat_id() const {
|
||||||
if (sorted_chat_ids_.empty()) {
|
if (sorted_chat_ids_.empty()) {
|
||||||
return std::nullopt;
|
return std::nullopt;
|
||||||
|
|||||||
@@ -3,6 +3,7 @@
|
|||||||
#include <cstdint>
|
#include <cstdint>
|
||||||
#include <chrono>
|
#include <chrono>
|
||||||
#include <filesystem>
|
#include <filesystem>
|
||||||
|
#include <future>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <optional>
|
#include <optional>
|
||||||
#include <tuple>
|
#include <tuple>
|
||||||
@@ -38,6 +39,8 @@ class App {
|
|||||||
|
|
||||||
void init_curses();
|
void init_curses();
|
||||||
void shutdown_curses();
|
void shutdown_curses();
|
||||||
|
void start_update_check();
|
||||||
|
bool refresh_update_check_result();
|
||||||
bool process_updates();
|
bool process_updates();
|
||||||
void handle_td_object(const json &object);
|
void handle_td_object(const json &object);
|
||||||
void handle_authorization_state();
|
void handle_authorization_state();
|
||||||
@@ -197,6 +200,7 @@ class App {
|
|||||||
std::string input_prompt_;
|
std::string input_prompt_;
|
||||||
std::string input_buffer_;
|
std::string input_buffer_;
|
||||||
std::string status_line_ = "Starting TDLib...";
|
std::string status_line_ = "Starting TDLib...";
|
||||||
|
std::string update_notice_;
|
||||||
std::string attachment_preview_graphics_data_;
|
std::string attachment_preview_graphics_data_;
|
||||||
std::string attachment_viewer_title_;
|
std::string attachment_viewer_title_;
|
||||||
std::string attachment_preview_signature_;
|
std::string attachment_preview_signature_;
|
||||||
@@ -217,6 +221,7 @@ class App {
|
|||||||
std::size_t attachment_viewer_frame_index_ = 0;
|
std::size_t attachment_viewer_frame_index_ = 0;
|
||||||
std::string attachment_viewer_send_caption_;
|
std::string attachment_viewer_send_caption_;
|
||||||
std::vector<std::int64_t> forward_message_ids_;
|
std::vector<std::int64_t> forward_message_ids_;
|
||||||
|
std::future<std::optional<std::string>> update_check_future_;
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace telegram_tui
|
} // namespace telegram_tui
|
||||||
|
|||||||
@@ -9,6 +9,7 @@
|
|||||||
|
|
||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
|
||||||
|
#include "build_config.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace telegram_tui {
|
namespace telegram_tui {
|
||||||
@@ -242,7 +243,7 @@ void App::send_tdlib_parameters() {
|
|||||||
{"system_language_code", "en"},
|
{"system_language_code", "en"},
|
||||||
{"device_model", "shinoa"},
|
{"device_model", "shinoa"},
|
||||||
{"system_version", "Linux"},
|
{"system_version", "Linux"},
|
||||||
{"application_version", "0.1.0"},
|
{"application_version", TELEGRAM_TUI_BUILD_VERSION},
|
||||||
{"enable_storage_optimizer", true},
|
{"enable_storage_optimizer", true},
|
||||||
{"ignore_file_names", false},
|
{"ignore_file_names", false},
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -6,6 +6,7 @@
|
|||||||
#include <curses.h>
|
#include <curses.h>
|
||||||
|
|
||||||
#include "app_ui.h"
|
#include "app_ui.h"
|
||||||
|
#include "build_config.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
|
|
||||||
namespace telegram_tui {
|
namespace telegram_tui {
|
||||||
@@ -88,10 +89,25 @@ void App::draw() {
|
|||||||
|
|
||||||
attron(A_REVERSE);
|
attron(A_REVERSE);
|
||||||
mvhline(header_y, 0, ' ', width);
|
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());
|
mvprintw(header_y, 1, "%s", header_label.c_str());
|
||||||
const std::string auth_label = authorized_ ? "ready" : current_auth_label();
|
const std::string auth_label = authorized_ ? "ready" : current_auth_label();
|
||||||
const int auth_x = std::max(1, width - static_cast<int>(auth_label.size()) - 2);
|
const int auth_x = std::max(1, width - static_cast<int>(auth_label.size()) - 2);
|
||||||
|
if (!update_notice_.empty()) {
|
||||||
|
const std::string centered_notice =
|
||||||
|
truncate_to_width(update_notice_, std::max(1, width - 4));
|
||||||
|
const int notice_x =
|
||||||
|
std::max(1, (width - static_cast<int>(centered_notice.size())) / 2);
|
||||||
|
if (notice_x > 1 + static_cast<int>(header_label.size()) &&
|
||||||
|
notice_x + static_cast<int>(centered_notice.size()) < auth_x - 1) {
|
||||||
|
attron(A_BOLD);
|
||||||
|
mvprintw(header_y, notice_x, "%s", centered_notice.c_str());
|
||||||
|
attroff(A_BOLD);
|
||||||
|
}
|
||||||
|
}
|
||||||
mvprintw(header_y, auth_x, "%s", auth_label.c_str());
|
mvprintw(header_y, auth_x, "%s", auth_label.c_str());
|
||||||
attroff(A_REVERSE);
|
attroff(A_REVERSE);
|
||||||
|
|
||||||
|
|||||||
@@ -25,7 +25,7 @@ std::string format_download_progress(std::int64_t downloaded_size, std::int64_t
|
|||||||
} // namespace
|
} // namespace
|
||||||
|
|
||||||
bool App::process_updates() {
|
bool App::process_updates() {
|
||||||
bool changed = false;
|
bool changed = refresh_update_check_result();
|
||||||
while (true) {
|
while (true) {
|
||||||
auto update = td_.receive(0.0);
|
auto update = td_.receive(0.0);
|
||||||
if (!update.has_value()) {
|
if (!update.has_value()) {
|
||||||
|
|||||||
@@ -1,4 +1,6 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#define TELEGRAM_TUI_BUILD_COMMIT "@TELEGRAM_TUI_BUILD_COMMIT@"
|
||||||
|
#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_ID "@TELEGRAM_TUI_BUILD_API_ID@"
|
||||||
#define TELEGRAM_TUI_BUILD_API_HASH "@TELEGRAM_TUI_BUILD_API_HASH@"
|
#define TELEGRAM_TUI_BUILD_API_HASH "@TELEGRAM_TUI_BUILD_API_HASH@"
|
||||||
|
|||||||
Reference in New Issue
Block a user