Skip to content

Terminal interface to find, download, and stream movies, TV shows, and live TV using local media players.

fix(player): prioritize android intent player on termux and refine diagnostics

Samir Hossains2d5f7a69ce4a
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 85afd68..a747bfe 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -15,6 +15,11 @@
- Updated the WebM walkthrough video attachment link to the latest asset URL across all localized READMEs and documentation.
- Moved the `#optional-support` anchor target inside the collapsible `<details>` container with `tabindex="-1"`, enabling native browser ancestor-revealing and keyboard focus navigation to automatically expand the crypto donation section when clicking the Donate badge.
+- **Termux Android Player Prioritization and Compact Error Diagnostics**:
+ - Prioritized `PlayerKind::AndroidIntent` at index 0 in `player::detect()` when running inside Termux, preventing auto-selection of headless CLI `mpv` or `vlc` when CLI packages are installed without an active X11/Wayland display server.
+ - Piped stdout in addition to stderr for `AndroidIntent` process spawning in `src/tui/app/playback.rs`, capturing intent dispatcher errors (`ActivityNotFoundException`, `no activity found to handle Intent`, `am.sock` socket connection failures) previously discarded by `Stdio::null()`.
+ - Replaced generic `Crash code: 1` modals with compact, player-neutral diagnostics for missing video player apps (`No Video Player: Install a video player on Android.`), unconfigured Termux intent tools (`Termux Setup Needed: Run: pkg install -y termux-am`), and headless mpv execution in Termux (`CLI mpv Unsupported: Switch to Android Player in /settings.`).
+ - Tuned mobile toast message height constraints in `src/tui/overlay.rs` (`max_msg_lines = 2` when `area.height >= 20` and `area.width < 65`), ensuring two-line diagnostics are rendered without premature truncation on mobile portrait screens.
## [0.1.19] - 2026-09-13
### Added
diff --git a/docs/cross-platform.md b/docs/cross-platform.md
index e9f7ee7..ba90439 100644
--- a/docs/cross-platform.md
+++ b/docs/cross-platform.md
@@ -13,7 +13,7 @@ the release checks in [`release-checklist.md`](release-checklist.md).
| macOS | IINA preferred player (via the installed IINA `iina-cli`); VLC/mpv `.app` paths detected. `process_group(0)` on spawn. |
| Windows | mpv/VLC detected via Program Files + `%LOCALAPPDATA%`; path-safe file stems; static MSVC CRT linking (`+crt-static`) for zero-dependency standalone binaries; handle-safe atomic download replacement (dropping file handles before renames); background process spawning (registry queries, yt-dlp downloader, and update helper) hardened with canonical `CREATE_NO_WINDOW` (`0x08000000`). |
| Linux | Flatpak mpv/VLC supported (`flatpak run …`); xdg data/cache dirs. Linux ARM64 binaries (`MovieBox_Linux_arm64.tar.gz`) are fully static musl executables linked with 64KB ELF segment alignment (`-Wl,-z,max-page-size=65536`) for compatibility across 4KB, 16KB, and 64KB page kernels. |
-| Android (Termux) | Targets `aarch64-linux-android` linked against the Android NDK (Clang API 24+) and system Bionic `libc.so`, producing a native ELF executable with a valid `PT_PHDR` program header table and `/system/bin/linker64` dynamic loader. This eliminates `Could not find a PHDR: broken executable?` crashes and executes natively without on-device compilation. Includes a pure-Rust DNS resolver that reads system configuration and falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution. Android playback delegates to external video players (VLC for Android, Just Player, MX Player, MPV Android) via Termux intent dispatchers (`termux-open`, `termux-open-url`, `termux-am`), requiring `pkg install -y termux-tools termux-am`. To protect against Android 10+ SELinux execute restrictions (exit code 126), system `/system/bin/am` fallbacks are strictly avoided in Termux; `LD_PRELOAD` is preserved for Termux applets while `PATH` is sanitized for system calls. Android intent playback supports unauthenticated streams (CircleFTP, DhakaFlix, IPTV) and standard CDN streams (4KHDHub). Real-device chooser behavior is a release prerequisite. |
+| Android (Termux) | Targets `aarch64-linux-android` linked against the Android NDK (Clang API 24+) and system Bionic `libc.so`, producing a native ELF executable with a valid `PT_PHDR` program header table and `/system/bin/linker64` dynamic loader. This eliminates `Could not find a PHDR: broken executable?` crashes and executes natively without on-device compilation. Includes a pure-Rust DNS resolver that reads system configuration and falls back to public resolvers (Cloudflare, Google, Quad9) for zero-config name resolution. Android playback delegates to external video players via Termux intent dispatchers (`termux-open`, `termux-open-url`, `termux-am`), requiring `pkg install -y termux-tools termux-am`. Detection prioritizes the native Android player bridge ahead of headless CLI players, with dual stdout/stderr capturing surfacing compact diagnostics for missing player apps, unconfigured intent tools, and headless mpv in Termux. |
## Terminal capabilities
diff --git a/docs/players.md b/docs/players.md
index 9e877bd..b96df57 100644
--- a/docs/players.md
+++ b/docs/players.md
@@ -10,7 +10,7 @@ builds the exact command; `tui/app/playback.rs` spawns it.
- macOS: IINA (if present), then mpv, then VLC (probing `/Applications`, `~/Applications`, Homebrew `/opt/homebrew/bin`, MacPorts `/opt/local/bin`, Nix profiles `~/.nix-profile/bin` and `/run/current-system/sw/bin`, and standard `/bin`).
- Linux: mpv, then VLC (probing native `$PATH`, user `.local/bin`, Flathub/Flatpak user & system exports `org.videolan.VLC` / `io.mpv.Mpv`, Snap `/snap/bin/*`, Nix profiles, standard `/bin`, and `flatpak run`).
- Windows: mpv, then VLC (probing executable-adjacent binaries, WinGet Links & Packages directory `%LOCALAPPDATA%\Microsoft\WinGet\Packages`, `%USERPROFILE%\Downloads` and `%USERPROFILE%\Desktop` extractions, `Program Files` including `mpv`, `mpv-player`, `mpv.net`, and `VideoLAN\VLC`, `LOCALAPPDATA\Programs`, portable drive roots `C:\mpv`, `C:\vlc`, `C:\tools`, Scoop shims & apps, Chocolatey, and Windows Registry `App Paths` and `Environment\Path`).
-- Android/Termux: Android intent chooser (`termux-open`, `termux-open-url`, or `termux-am`). Streams play via external Android video players (VLC for Android, Just Player, MX Player, MPV Android APK).
+- Android/Termux: Android intent chooser (`termux-open`, `termux-open-url`, or `termux-am`), prioritized at index 0 ahead of CLI `mpv` and `vlc` to avoid selecting headless players lacking display servers. Streams play via external Android video players.
Resolution caches detected paths across runs while allowing newly installed players to be discovered dynamically when opening or navigating the Settings Hub (`/settings`), without requiring an application restart. A preferred player can be forced via `MOVIEBOX_PLAYER` env or `default_player` in config (e.g. `mpv`, `iina`, `vlc`, `android`), which reorders the list. The media player picker in the Settings Hub lists every detected player on your system and saves your selection to `config.json`. Playback launches directly using the preferred compatible player without intermediate modal dialogs.
@@ -53,10 +53,11 @@ When launching media with in-progress watch history, the player command automati
- **Isolated Tracker vs Fallback Reconciliation**: Players with active Lua trackers (`mpv`, `iina-cli`) rely strictly on state file reconciliation, eliminating wall-clock progress overwrite races during pauses or seeks. Process elapsed time is used strictly as a guarded fallback for players without tracker scripts (e.g. VLC).
## Spawning
-`launch_player` spawns the player with null stdin/stdout, piped stderr, and its own
-process group (Unix) or no-console flag (Windows). A blocking task reads stderr and
-reports every non-zero process exit as a player error, including failures with no
-diagnostic output. Watch progress is reconciled only after a successful exit.
+`launch_player` spawns the player with null stdin, piped stderr (plus piped stdout for
+`PlayerKind::AndroidIntent` to intercept intent dispatcher error text), and its own
+process group (Unix) or no-console flag (Windows). A blocking task reads output and
+reports every non-zero process exit as a player error, surfacing compact, actionable
+diagnostics on mobile terminals. Watch progress is reconciled only after a successful exit.
## Android / Termux Playback Architecture
@@ -67,4 +68,8 @@ On Android (Termux), terminal sessions do not have access to an X11 or Wayland d
- **Prerequisites**: Termux requires `pkg install -y termux-tools termux-am`.
- `termux-open` (from `termux-tools`) broadcasts an `android.intent.action.VIEW` intent to `TermuxOpenReceiver`, presenting Android's native app chooser.
- `termux-am` (from `termux-am`) connects directly to `termux-app`'s local Unix domain socket (`am.sock`), allowing intent parameter passing (including `User-Agent`, `Referer`, and subtitles).
+- **Actionable Mobile Diagnostics**: MovieBox-TUI parses intent dispatcher output and failure status codes, surfacing compact, player-neutral diagnostics formatted for mobile viewports:
+ - **Missing video player app**: Surfaces `No Video Player` (`Install a video player on Android.`).
+ - **Missing intent bridge / socket**: Surfaces `Termux Setup Needed` (`Run: pkg install -y termux-am`).
+ - **Headless CLI mpv**: Detects video output initialization failures and surfaces `CLI mpv Unsupported` (`Switch to Android Player in /settings.`).
- **SELinux & Exit Code 126 Protection**: On Android 10+, executing `/system/bin/am` directly from an unrooted Termux environment causes Android's system shell to call `cmd activity`, which is blocked by SELinux when executing Termux app data binaries (`Permission denied`, exit code 126). MovieBox-TUI detects Termux environments, prevents illegal system `am` invocations, preserves `LD_PRELOAD` for Termux applet compatibility, and surfaces actionable remediation notifications.
diff --git a/src/player.rs b/src/player.rs
index 8462d12..adf3f09 100644
--- a/src/player.rs
+++ b/src/player.rs
@@ -45,6 +45,11 @@ impl PlayerKind {
pub fn detect() -> Vec<PlayerKind> {
let mut players = Vec::new();
+ let is_termux = crate::updater::artifact::is_termux_environment();
+ if is_termux && android_opener().is_some() {
+ players.push(PlayerKind::AndroidIntent);
+ }
+
#[cfg(target_os = "macos")]
if iina_available() {
players.push(PlayerKind::Iina);
@@ -58,7 +63,7 @@ pub fn detect() -> Vec<PlayerKind> {
players.push(PlayerKind::Vlc);
}
- if android_opener().is_some() {
+ if !is_termux && android_opener().is_some() {
players.push(PlayerKind::AndroidIntent);
}
@@ -1452,6 +1457,29 @@ mod tests {
assert!(args.contains(&"https://example.test/video.mp4".to_string()));
}
+ #[test]
+ fn test_detect_prioritizes_android_intent_on_termux() {
+ let temp_dir = std::env::temp_dir().join(format!("termux_test_{}", std::process::id()));
+ let bin_dir = temp_dir.join("bin");
+ std::fs::create_dir_all(&bin_dir).unwrap();
+ let termux_am = bin_dir.join("termux-am");
+ std::fs::write(&termux_am, "#!/bin/sh\nexit 0").unwrap();
+
+ unsafe {
+ std::env::set_var("TERMUX_VERSION", "0.118.0");
+ std::env::set_var("PREFIX", temp_dir.to_str().unwrap());
+ }
+ let detected = detect();
+ unsafe {
+ std::env::remove_var("TERMUX_VERSION");
+ std::env::remove_var("PREFIX");
+ }
+ let _ = std::fs::remove_dir_all(&temp_dir);
+
+ assert!(!detected.is_empty());
+ assert_eq!(detected[0], PlayerKind::AndroidIntent);
+ }
+
#[test]
fn test_windows_mpv_candidate_paths_comprehensive() {
let home = PathBuf::from(r"C:\Users\TestUser");
diff --git a/src/tui/app/playback.rs b/src/tui/app/playback.rs
index dd15094..739ccca 100644
--- a/src/tui/app/playback.rs
+++ b/src/tui/app/playback.rs
@@ -388,8 +388,13 @@ impl App {
resume_seconds,
tracker_ref,
);
+ let capture_stdout = matches!(kind, crate::tui::state::PlayerKind::AndroidIntent);
command.stdin(std::process::Stdio::null());
- command.stdout(std::process::Stdio::null());
+ if capture_stdout {
+ command.stdout(std::process::Stdio::piped());
+ } else {
+ command.stdout(std::process::Stdio::null());
+ }
command.stderr(std::process::Stdio::piped());
#[cfg(unix)]
@@ -402,12 +407,24 @@ impl App {
Ok(mut child) => {
let start_time = std::time::Instant::now();
let stderr_stream = child.stderr.take();
+ let stdout_stream = child.stdout.take();
tokio::task::spawn_blocking(move || {
let mut error_output = String::new();
+ if let Some(mut stdout) = stdout_stream {
+ use std::io::Read;
+ let _ = stdout.read_to_string(&mut error_output);
+ }
if let Some(mut stderr) = stderr_stream {
use std::io::Read;
- let _ = stderr.read_to_string(&mut error_output);
+ let mut stderr_output = String::new();
+ let _ = stderr.read_to_string(&mut stderr_output);
+ if !stderr_output.is_empty() {
+ if !error_output.is_empty() {
+ error_output.push('\n');
+ }
+ error_output.push_str(&stderr_output);
+ }
}
let result = child.wait();
@@ -821,16 +838,45 @@ impl App {
.unwrap_or_else(|| "unknown".into());
log::error!("player crashed (code {code_str}): {error_msg}");
- let is_termux_perm_crash = crate::updater::artifact::is_termux_environment()
+ let is_termux = crate::updater::artifact::is_termux_environment();
+ let is_missing_activity = is_termux
+ && (error_msg.contains("No Activity found")
+ || error_msg.contains("ActivityNotFoundException")
+ || error_msg.contains("no activity found"));
+
+ let is_termux_tool_crash = is_termux
&& (code == Some(126)
|| error_msg.contains("Permission denied")
|| error_msg.contains("/system/bin/am")
- || error_msg.contains("termux-open"));
-
- let (title, message) = if is_termux_perm_crash {
+ || error_msg.contains("termux-open")
+ || error_msg.contains("termux-am")
+ || error_msg.contains("am.sock")
+ || error_msg.contains("Could not connect to socket")
+ || (code == Some(1)
+ && (error_msg.is_empty()
+ || error_msg.contains("status code 1")
+ || error_msg.contains("broadcast"))));
+
+ let is_headless_mpv = is_termux
+ && (error_msg.contains("Failed to open display")
+ || error_msg.contains("video_out")
+ || error_msg.contains("vo/gpu")
+ || error_msg.contains("vo=gpu"));
+
+ let (title, message) = if is_missing_activity {
+ (
+ "No Video Player",
+ "Install a video player on Android.".to_string(),
+ )
+ } else if is_termux_tool_crash {
(
- "Termux Player Setup Required",
- "Install player intent tools: 'pkg install -y termux-tools termux-am' and ensure an Android player (VLC, MX Player, or Just Player) is installed.".to_string(),
+ "Termux Setup Needed",
+ "Run: pkg install -y termux-am".to_string(),
+ )
+ } else if is_headless_mpv {
+ (
+ "CLI mpv Unsupported",
+ "Switch to Android Player in /settings.".to_string(),
)
} else {
let display_err = if error_msg.is_empty() {
@@ -838,10 +884,13 @@ impl App {
} else {
error_msg.lines().last().unwrap_or(&error_msg).to_string()
};
- (
- "Player Error",
- format!("Crash code: {code_str}\n{display_err}"),
- )
+ let formatted_msg = if display_err.starts_with("Player exited with status code")
+ {
+ display_err
+ } else {
+ format!("{display_err} (code {code_str})")
+ };
+ ("Playback Failed", formatted_msg)
};
self.state.set_status(format!("{title}: {message}"), 300);
@@ -1167,14 +1216,85 @@ mod tests {
.notifications
.back()
.expect("expected notification");
- assert_eq!(last_notification.title, "Termux Player Setup Required");
- assert!(
- last_notification
- .message
- .contains("pkg install -y termux-tools termux-am")
+ assert_eq!(last_notification.title, "Termux Setup Needed");
+ assert_eq!(last_notification.message, "Run: pkg install -y termux-am");
+ }
+
+ #[tokio::test]
+ async fn test_player_crashed_termux_missing_activity() {
+ let mut app = crate::tui::app::App::new();
+ unsafe {
+ std::env::set_var("TERMUX_VERSION", "0.118.0");
+ }
+ app.handle_playback(super::Action::PlayerCrashed(
+ Some(1),
+ "Error: Activity not started, no activity found to handle Intent".to_string(),
+ ))
+ .await;
+ unsafe {
+ std::env::remove_var("TERMUX_VERSION");
+ }
+ let last_notification = app
+ .state
+ .notifications
+ .back()
+ .expect("expected notification");
+ assert_eq!(last_notification.title, "No Video Player");
+ assert_eq!(
+ last_notification.message,
+ "Install a video player on Android."
+ );
+ }
+
+ #[tokio::test]
+ async fn test_player_crashed_termux_headless_mpv() {
+ let mut app = crate::tui::app::App::new();
+ unsafe {
+ std::env::set_var("TERMUX_VERSION", "0.118.0");
+ }
+ app.handle_playback(super::Action::PlayerCrashed(
+ Some(1),
+ "Error opening/initializing the selected video_out (--vo) device.".to_string(),
+ ))
+ .await;
+ unsafe {
+ std::env::remove_var("TERMUX_VERSION");
+ }
+ let last_notification = app
+ .state
+ .notifications
+ .back()
+ .expect("expected notification");
+ assert_eq!(last_notification.title, "CLI mpv Unsupported");
+ assert_eq!(
+ last_notification.message,
+ "Switch to Android Player in /settings."
);
}
+ #[tokio::test]
+ async fn test_player_crashed_termux_exit_code_1_generic() {
+ let mut app = crate::tui::app::App::new();
+ unsafe {
+ std::env::set_var("TERMUX_VERSION", "0.118.0");
+ }
+ app.handle_playback(super::Action::PlayerCrashed(
+ Some(1),
+ "Player exited with status code 1.".to_string(),
+ ))
+ .await;
+ unsafe {
+ std::env::remove_var("TERMUX_VERSION");
+ }
+ let last_notification = app
+ .state
+ .notifications
+ .back()
+ .expect("expected notification");
+ assert_eq!(last_notification.title, "Termux Setup Needed");
+ assert_eq!(last_notification.message, "Run: pkg install -y termux-am");
+ }
+
#[tokio::test]
async fn test_playback_captures_active_subject_and_episode() {
let mut app = crate::tui::app::App::new();
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index 50ec435..3cf0338 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -1094,6 +1094,12 @@ impl App {
.lines()
.map(|l| l.trim())
.filter(|l| !l.is_empty())
+ .filter(|l| {
+ let lower = l.to_ascii_lowercase();
+ !lower.contains("read full changelog")
+ && !lower.contains("press [o]")
+ && !lower.contains("press o to")
+ })
.collect();
let inner_area = crate::tui::widgets::ModalFrame::new(
@@ -1196,7 +1202,6 @@ impl App {
.add_modifier(ratatui::style::Modifier::BOLD),
),
]));
- let line_width = (inner_area.width as usize).saturating_sub(6);
let basic = self.state.basic_terminal;
for line in note_lines.iter().take(display_count) {
@@ -1208,7 +1213,7 @@ impl App {
|| trimmed.starts_with("# ")
{
let title = trimmed.trim_start_matches('#').trim();
- spans.push(Span::raw(" "));
+ spans.push(Span::raw(" "));
if title.eq_ignore_ascii_case("Added") {
spans.push(Span::styled(
"[Added]",
@@ -1254,7 +1259,7 @@ impl App {
}
} else if trimmed.starts_with("- ") || trimmed.starts_with("* ") {
let bullet = trimmed[2..].trim();
- spans.push(Span::raw(" "));
+ spans.push(Span::raw(" "));
spans.push(Span::styled(
if basic { "- " } else { "• " },
self.theme.accent,
@@ -1277,10 +1282,9 @@ impl App {
spans.push(Span::styled(colon, self.theme.subtext1));
}
if !clean_rest.is_empty() {
- let budget = line_width
- .saturating_sub(8)
- .saturating_sub(crate::tui::text::width(title))
- .saturating_sub(colon.len());
+ let prefix_w = 4 + 2 + crate::tui::text::width(title) + colon.len();
+ let budget =
+ (inner_area.width as usize).saturating_sub(prefix_w + 2);
if budget > 0 {
spans.push(Span::styled(
crate::tui::text::truncate_width(&clean_rest, budget)
@@ -1291,29 +1295,26 @@ impl App {
}
} else {
let clean = bullet.replace('`', "");
+ let budget = (inner_area.width as usize).saturating_sub(4 + 2 + 2);
spans.push(Span::styled(
- crate::tui::text::truncate_width(
- &clean,
- line_width.saturating_sub(8),
- )
- .into_owned(),
+ crate::tui::text::truncate_width(&clean, budget).into_owned(),
self.theme.text,
));
}
} else {
let clean = bullet.replace('`', "");
+ let budget = (inner_area.width as usize).saturating_sub(4 + 2 + 2);
spans.push(Span::styled(
- crate::tui::text::truncate_width(&clean, line_width.saturating_sub(8))
- .into_owned(),
+ crate::tui::text::truncate_width(&clean, budget).into_owned(),
self.theme.text,
));
}
} else {
let clean = trimmed.replace('`', "");
- spans.push(Span::raw(" "));
+ let budget = (inner_area.width as usize).saturating_sub(4 + 2);
+ spans.push(Span::raw(" "));
spans.push(Span::styled(
- crate::tui::text::truncate_width(&clean, line_width.saturating_sub(6))
- .into_owned(),
+ crate::tui::text::truncate_width(&clean, budget).into_owned(),
self.theme.text_dim,
));
}
@@ -1399,7 +1400,7 @@ impl App {
};
text.push(Line::from(buttons).alignment(Alignment::Center));
-
+ text.push(Line::from(""));
let popup = Paragraph::new(text);
frame.render_widget(popup, inner_area);
}
@@ -1414,9 +1415,9 @@ impl App {
use ratatui::text::{Line, Span};
use ratatui::widgets::Paragraph;
- let width = 56.min(area.width.saturating_sub(4)).max(36);
- let height = 9.min(area.height.saturating_sub(2)).max(7);
- let popup_area = crate::tui::overlay::centered(area, width, height, 36, 56);
+ let width = 50.min(area.width.saturating_sub(4)).max(36);
+ let height = 7.min(area.height.saturating_sub(2)).max(5);
+ let popup_area = crate::tui::overlay::centered(area, width, height, 36, 50);
let inner_area = crate::tui::widgets::ModalFrame::new(
"Self-Update in Progress",
@@ -1485,8 +1486,8 @@ impl App {
),
])
.alignment(Alignment::Center),
+ Line::from(""),
];
-
let popup = Paragraph::new(text);
frame.render_widget(popup, inner_area);
}
diff --git a/src/tui/overlay.rs b/src/tui/overlay.rs
index 0f9759f..821b15c 100644
--- a/src/tui/overlay.rs
+++ b/src/tui/overlay.rs
@@ -332,8 +332,10 @@ pub fn notifications(
let bottom_offset = if download_active { 5 } else { 2 };
let mut y = area.bottom().saturating_sub(bottom_offset);
- let (max_visible, max_card_w, max_msg_lines) = if area.height < 20 || area.width < 65 {
+ let (max_visible, max_card_w, max_msg_lines) = if area.height < 20 {
(1, 42.min(area.width.saturating_sub(4) as usize), 1)
+ } else if area.width < 65 {
+ (1, 42.min(area.width.saturating_sub(4) as usize), 2)
} else if area.height < 30 {
(2, 56.min(area.width.saturating_sub(4) as usize), 2)
} else {
@@ -563,8 +565,10 @@ pub fn notification_rects(
let mut y = area.bottom().saturating_sub(bottom_offset);
let theme_placeholder = Theme::default();
- let (max_visible, max_card_w, max_msg_lines) = if area.height < 20 || area.width < 65 {
+ let (max_visible, max_card_w, max_msg_lines) = if area.height < 20 {
(1, 42.min(area.width.saturating_sub(4) as usize), 1)
+ } else if area.width < 65 {
+ (1, 42.min(area.width.saturating_sub(4) as usize), 2)
} else if area.height < 30 {
(2, 56.min(area.width.saturating_sub(4) as usize), 2)
} else {
@@ -641,23 +645,29 @@ pub fn update_modal_layout(area: Rect, notes: &str) -> UpdateModalLayout {
.lines()
.map(|l| l.trim())
.filter(|l| !l.is_empty())
+ .filter(|l| {
+ let lower = l.to_ascii_lowercase();
+ !lower.contains("read full changelog")
+ && !lower.contains("press [o]")
+ && !lower.contains("press o to")
+ })
.count();
- let min_w: u16 = 46;
+ let min_w: u16 = 50;
let max_w: u16 = 76;
let available_w = area.width.saturating_sub(4);
let desired_w = max_w.min(available_w).max(min_w.min(available_w));
- let header_rows: u16 = 6;
- let footer_rows: u16 = 4;
+ let header_rows: u16 = 3;
+ let footer_rows: u16 = 3;
let available_height = area.height.saturating_sub(4);
let available_note_rows =
- (available_height.saturating_sub(header_rows + footer_rows) as usize).clamp(3, 12);
+ (available_height.saturating_sub(header_rows + footer_rows + 2) as usize).clamp(3, 16);
let display_count = note_lines_count.min(available_note_rows);
let has_more = note_lines_count > display_count;
- let total_rows = header_rows + (display_count as u16) + footer_rows;
- let desired_h = total_rows.clamp(12, available_height.max(12));
+ let total_rows = header_rows + (display_count as u16) + footer_rows + 2;
+ let desired_h = total_rows.min(available_height.max(8));
const UPDATE_SEGMENT: u16 = 18;
const OPEN_SEGMENT: u16 = 26;
@@ -671,7 +681,7 @@ pub fn update_modal_layout(area: Rect, notes: &str) -> UpdateModalLayout {
};
let footer_width = update_seg + open_seg + dismiss_seg;
- let button_row_y = popup_area.y + popup_area.height.saturating_sub(2);
+ let button_row_y = popup_area.y + popup_area.height.saturating_sub(3);
let inner_width = popup_area.width.saturating_sub(2);
let footer_start = popup_area.x + 1 + inner_width.saturating_sub(footer_width) / 2;
let update_btn_end_x = footer_start + update_seg;
@@ -701,10 +711,10 @@ mod tests {
assert_eq!(layout.popup_area.width, 76);
assert_eq!(layout.display_count, 4);
assert!(!layout.has_more);
- assert_eq!(layout.popup_area.height, 14);
+ assert_eq!(layout.popup_area.height, 12);
assert_eq!(layout.popup_area.x, (80 - 76) / 2);
- assert_eq!(layout.popup_area.y, (24 - 14) / 2);
- assert_eq!(layout.button_row_y, layout.popup_area.y + 12);
+ assert_eq!(layout.popup_area.y, (24 - 12) / 2);
+ assert_eq!(layout.button_row_y, layout.popup_area.y + 9);
let footer_start = layout.popup_area.x + 1 + (74 - 58) / 2;
assert_eq!(layout.update_btn_end_x, footer_start + 18);
assert_eq!(layout.open_btn_end_x, layout.update_btn_end_x + 26);
@@ -940,4 +950,18 @@ mod tests {
let large_rects = notification_rects(large_area, &queue, false, false);
assert_eq!(large_rects.len(), 3);
}
+
+ #[test]
+ fn test_notification_rects_mobile_portrait() {
+ let mut queue = std::collections::VecDeque::new();
+ queue.push_back(Notification::new(
+ NotificationKind::Error,
+ "Title",
+ "Line 1\nLine 2",
+ ));
+ let mobile_portrait = Rect::new(0, 0, 40, 26);
+ let rects = notification_rects(mobile_portrait, &queue, false, false);
+ assert_eq!(rects.len(), 1);
+ assert!(rects[0].1.height >= 5);
+ }
}