Skip to content

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

fix(tui): prevent duplicate stream playback launches on double-click and rapid input

Samir Hossains07749723e1d0
diff --git a/CHANGELOG.md b/CHANGELOG.md
index a9eb0fc..719a127 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,7 +4,7 @@
### Added
- **Comprehensive QA & Regression Test Architecture**:
- - Introduced a 61-test automated suite covering critical algorithmic boundaries, end-to-end user journeys, error handling, addon manifest validation, mouse interactions, modal dismissals, TUI rendering across terminal size matrices, state reconciliation, crypto HMAC signing, download chunk arithmetic, and URL/stem security.
+ - Introduced a 62-test automated suite covering critical algorithmic boundaries, end-to-end user journeys, duplicate action & rapid double-click debounce protection, error handling, addon manifest validation, mouse interactions, modal dismissals, TUI rendering across terminal size matrices, state reconciliation, crypto HMAC signing, download chunk arithmetic, and URL/stem security.
- Added structured integration tests in `tests/` (`error_handling.rs`, `tui_acceptance.rs`, `history_reconciliation.rs`, `cache_lifecycle.rs`, `player_integration.rs`, `m3u_integration.rs`, `addons_manifest.rs`, `download_integration.rs`, `url_security.rs`) and test fixtures (`tests/fixtures/`).
- Added [`docs/testing.md`](docs/testing.md) detailing test architecture, command references, and manual QA procedures.
- **Playback Tracking & Watch History Progress**:
diff --git a/src/tui/app/mouse.rs b/src/tui/app/mouse.rs
index c543177..5f7d6a8 100644
--- a/src/tui/app/mouse.rs
+++ b/src/tui/app/mouse.rs
@@ -708,7 +708,10 @@ impl App {
let prev_selected = self.state.resource_list_state.selected();
self.state.resource_list_state.select(Some(target_idx));
- if prev_selected == Some(target_idx) {
+ if prev_selected == Some(target_idx)
+ && !self.state.is_resolving_playback
+ && self.state.last_playback_launch.elapsed().as_millis() >= 500
+ {
self.action_sender.send(Action::PlayStream(false)).ok();
}
}
diff --git a/src/tui/app/playback.rs b/src/tui/app/playback.rs
index f00e4b4..97e512a 100644
--- a/src/tui/app/playback.rs
+++ b/src/tui/app/playback.rs
@@ -291,9 +291,12 @@ impl App {
pub(super) async fn handle_playback(&mut self, action: Action) -> Option<()> {
match action {
Action::PlayStream(open_with) => {
- if self.state.is_resolving_playback {
+ if self.state.is_resolving_playback
+ || self.state.last_playback_launch.elapsed().as_millis() < 500
+ {
return None;
}
+ self.state.last_playback_launch = std::time::Instant::now();
self.state.is_resolving_playback = true;
if self.current_subject_provider() == ProviderKind::FourKHdHub
|| self.current_subject_provider() == ProviderKind::Addons
@@ -508,6 +511,10 @@ impl App {
}
}
Action::LaunchMpv(link, subtitle_url) => {
+ if self.state.last_playback_launch.elapsed().as_millis() < 500 {
+ return None;
+ }
+ self.state.last_playback_launch = std::time::Instant::now();
self.state.is_resolving_playback = false;
let player = self.state.available_players.first().cloned();
match player {
@@ -578,11 +585,13 @@ impl App {
Action::LaunchPlayer(kind, link, sub) => {
self.state.is_resolving_playback = false;
self.state.player_picker_popup = false;
+ self.state.last_playback_launch = std::time::Instant::now();
self.launch_player(kind, link, sub, Vec::new());
}
Action::LaunchPlayback(kind, source) => {
self.state.is_resolving_playback = false;
self.state.player_picker_popup = false;
+ self.state.last_playback_launch = std::time::Instant::now();
if !crate::tui::player::supports_headers(kind, &source.headers) {
self.state.set_status(
format!(
diff --git a/src/tui/state.rs b/src/tui/state.rs
index b7970c5..d3c9824 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -128,6 +128,7 @@ pub struct AppState {
pub default_player: Option<String>,
pub is_loading: bool,
pub is_resolving_playback: bool,
+ pub last_playback_launch: std::time::Instant,
pub status_message: String,
pub status_timer: usize,
pub notifications: std::collections::VecDeque<crate::tui::overlay::Notification>,
@@ -266,6 +267,9 @@ impl Default for AppState {
dirty: true,
is_loading: false,
is_resolving_playback: false,
+ last_playback_launch: std::time::Instant::now()
+ .checked_sub(std::time::Duration::from_secs(5))
+ .unwrap_or_else(std::time::Instant::now),
status_message: String::new(),
status_timer: 0,
notifications: std::collections::VecDeque::new(),
diff --git a/tests/error_handling.rs b/tests/error_handling.rs
index 29652d1..b36b369 100644
--- a/tests/error_handling.rs
+++ b/tests/error_handling.rs
@@ -117,3 +117,14 @@ async fn test_invalid_url_schemes_rejected_by_security_filter() {
assert!(is_http_url("http://example.com"));
assert!(is_http_url("https://example.com/manifest.json"));
}
+
+#[tokio::test]
+async fn test_rapid_playback_invocations_debounced_and_single_flight() {
+ let mut app = App::new();
+ app.state_mut().last_playback_launch = std::time::Instant::now();
+ app.state_mut().is_resolving_playback = false;
+
+ let res = app.handle_action(Action::PlayStream(false)).await;
+ assert_eq!(res, None);
+ assert!(!app.state().is_resolving_playback);
+}