feat: add optional feature flags for clipboard and url-open (P5.15)

Implemented feature flags to make dependencies optional:
- clipboard feature: controls arboard dependency
- url-open feature: controls open dependency
- Both enabled by default for backward compatibility

Changes:
- Cargo.toml: Added [features] section with optional deps
- src/input/main_input.rs: Conditional compilation for open::that() and copy_to_clipboard()
- tests/copy.rs: Clipboard tests only compile with feature enabled
- Graceful degradation: user-friendly error messages when features disabled

Benefits:
- Smaller binary size when features disabled
- Modular functionality
- Better platform compatibility

Progress: Priority 5: 1/3 tasks, Total: 17/20 (85%)

Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This commit is contained in:
Mikhail Kilin
2026-02-01 02:23:17 +03:00
parent 38b18e35ea
commit 56bddabbe1
5 changed files with 63 additions and 22 deletions

View File

@@ -138,15 +138,24 @@ pub async fn handle(app: &mut App, key: KeyEvent) {
"https://t.me/{}",
username.trim_start_matches('@')
);
match open::that(&url) {
Ok(_) => {
app.status_message = Some(format!("Открыто: {}", url));
}
Err(e) => {
app.error_message =
Some(format!("Ошибка открытия браузера: {}", e));
#[cfg(feature = "url-open")]
{
match open::that(&url) {
Ok(_) => {
app.status_message = Some(format!("Открыто: {}", url));
}
Err(e) => {
app.error_message =
Some(format!("Ошибка открытия браузера: {}", e));
}
}
}
#[cfg(not(feature = "url-open"))]
{
app.error_message = Some(
"Открытие URL недоступно (требуется feature 'url-open')".to_string()
);
}
}
return;
}
@@ -1057,6 +1066,7 @@ fn get_available_actions_count(profile: &crate::tdlib::ProfileInfo) -> usize {
}
/// Копирует текст в системный буфер обмена
#[cfg(feature = "clipboard")]
fn copy_to_clipboard(text: &str) -> Result<(), String> {
use arboard::Clipboard;
@@ -1069,6 +1079,12 @@ fn copy_to_clipboard(text: &str) -> Result<(), String> {
Ok(())
}
/// Заглушка для copy_to_clipboard когда feature "clipboard" выключена
#[cfg(not(feature = "clipboard"))]
fn copy_to_clipboard(_text: &str) -> Result<(), String> {
Err("Копирование в буфер обмена недоступно (требуется feature 'clipboard')".to_string())
}
/// Форматирует сообщение для копирования с контекстом
fn format_message_for_clipboard(msg: &crate::tdlib::MessageInfo) -> String {
let mut result = String::new();