Skip to content

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

feat(tui): remove startup screen delay and modernize in-place update modal

Samir Hossains533d57c3bdd4
diff --git a/src/tui/app/keyboard.rs b/src/tui/app/keyboard.rs
index 3bb12f0..d62006b 100644
--- a/src/tui/app/keyboard.rs
+++ b/src/tui/app/keyboard.rs
@@ -200,7 +200,6 @@ impl App {
_ => {}
},
InputMode::Normal => match self.state.active_screen {
- Screen::Startup => {}
Screen::Home => {
if self.state.tv_config_popup {
if self.state.tv_input_active {
diff --git a/src/tui/app/navigation.rs b/src/tui/app/navigation.rs
index 38032c8..65508cf 100644
--- a/src/tui/app/navigation.rs
+++ b/src/tui/app/navigation.rs
@@ -420,7 +420,6 @@ impl App {
return None;
}
match self.state.active_screen {
- Screen::Startup => {}
Screen::Home => {
if !self.state.search_results.is_empty()
|| !self.state.search_query.is_empty()
@@ -514,7 +513,6 @@ impl App {
return None;
}
match self.state.active_screen {
- Screen::Startup => {}
Screen::Home => {
let current = self.state.search_list_state.selected().unwrap_or(0);
if current > 0 {
@@ -589,7 +587,6 @@ impl App {
return None;
}
match self.state.active_screen {
- Screen::Startup => {}
Screen::Home => {
let current = self.state.search_list_state.selected().unwrap_or(0);
if current + 1 < self.state.search_results.len() {
diff --git a/src/tui/app/run.rs b/src/tui/app/run.rs
index 9591511..bd4802a 100644
--- a/src/tui/app/run.rs
+++ b/src/tui/app/run.rs
@@ -306,9 +306,6 @@ impl App {
}
match self.state.active_screen {
- Screen::Startup => {
- crate::tui::screens::startup::draw(frame, main_area, &mut self.state, &self.theme);
- }
Screen::Home => {
crate::tui::screens::home::draw(frame, main_area, &mut self.state, &self.theme);
}
@@ -378,60 +375,68 @@ impl App {
}
if let Some((version, notes)) = &self.state.update_available {
- use ratatui::layout::{Alignment, Constraint, Direction, Layout};
+ use ratatui::layout::Alignment;
use ratatui::text::{Line, Span};
- use ratatui::widgets::{Block, Borders, Clear, Paragraph};
+ use ratatui::widgets::{Block, BorderType, Borders, Paragraph};
- let popup_width = 70;
- let popup_height = 20;
+ let note_lines: Vec<&str> = notes
+ .lines()
+ .map(|l| l.trim())
+ .filter(|l| !l.is_empty())
+ .collect();
- let h_chunks = Layout::default()
- .direction(Direction::Horizontal)
- .constraints([
- Constraint::Min(0),
- Constraint::Length(popup_width),
- Constraint::Min(0),
- ])
- .split(area);
+ let min_w: u16 = 46;
+ let max_w: u16 = 72;
+ let desired_w = max_w.min(area.width.saturating_sub(4)).max(min_w);
- let v_chunks = Layout::default()
- .direction(Direction::Vertical)
- .constraints([
- Constraint::Min(0),
- Constraint::Length(popup_height),
- Constraint::Min(0),
- ])
- .split(h_chunks[1]);
+ let header_rows: u16 = 5;
+ 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(2, 10);
- let popup_area = v_chunks[1];
- frame.render_widget(Clear, popup_area);
+ let display_count = note_lines.len().min(available_note_rows);
+ let has_more = note_lines.len() > display_count;
+ let total_rows =
+ header_rows + (display_count as u16) + (if has_more { 1 } else { 0 }) + footer_rows;
+ let desired_h = total_rows.clamp(10, available_height.max(10));
+
+ let popup_area =
+ crate::tui::overlay::centered(area, desired_w, desired_h, min_w, max_w);
+ crate::tui::clear_area(frame, area, &self.theme);
let mut text = vec![
- Line::from(Span::styled("Update Available!", self.theme.accent))
- .alignment(Alignment::Center),
- Line::from(""),
- Line::from("A new version of MovieBox-Tui is available.")
- .alignment(Alignment::Center),
- Line::from(""),
+ Line::from(vec![Span::styled(
+ "A new version of MovieBox-Tui is available",
+ self.theme
+ .header
+ .add_modifier(ratatui::style::Modifier::BOLD),
+ )])
+ .alignment(Alignment::Center),
Line::from(vec![
- Span::raw(format!("Current: v{} ", env!("CARGO_PKG_VERSION"))),
- Span::styled("→", self.theme.accent),
- Span::raw(format!(" Latest: v{}", version)),
+ Span::styled("Installed: ", self.theme.text_dim),
+ Span::styled(format!("v{}", env!("CARGO_PKG_VERSION")), self.theme.text),
+ Span::styled(" → ", self.theme.accent),
+ Span::styled("Latest: ", self.theme.text_dim),
+ Span::styled(
+ format!("v{version}"),
+ self.theme
+ .accent
+ .add_modifier(ratatui::style::Modifier::BOLD),
+ ),
])
.alignment(Alignment::Center),
Line::from(""),
- Line::from(Span::styled(
- "─ Release Notes ──────────────────────────────────────────────────",
- self.theme.border,
- ))
- .alignment(Alignment::Center),
- Line::from(""),
+ Line::from(vec![Span::styled(
+ "Release Notes:",
+ self.theme
+ .subtext1
+ .add_modifier(ratatui::style::Modifier::BOLD),
+ )]),
];
- let note_lines: Vec<&str> = notes.lines().filter(|l| !l.trim().is_empty()).collect();
-
- let take_count = 6;
- for line in note_lines.iter().take(take_count) {
+ let line_width = popup_area.width.saturating_sub(6) as usize;
+ for line in note_lines.iter().take(display_count) {
let trimmed = line.trim();
let mut spans = vec![Span::raw(" ")];
@@ -440,52 +445,64 @@ impl App {
|| trimmed.starts_with("# ")
{
let text_start = trimmed.find(' ').unwrap_or(0);
- spans.push(Span::styled("▌", self.theme.accent));
+ spans.push(Span::styled("▌ ", self.theme.accent));
spans.push(Span::styled(
- crate::tui::text::truncate_width(&trimmed[text_start..], 60),
+ crate::tui::text::truncate_width(
+ &trimmed[text_start..],
+ line_width.saturating_sub(4),
+ ),
self.theme.highlight,
));
} else if trimmed.starts_with("- ") || trimmed.starts_with("* ") {
let text_start = trimmed.find(' ').unwrap_or(0) + 1;
spans.push(Span::styled("• ", self.theme.accent));
spans.push(Span::raw(crate::tui::text::truncate_width(
- &trimmed[text_start..],
- 60,
+ trimmed[text_start..].trim_start(),
+ line_width.saturating_sub(4),
)));
} else {
- spans.push(Span::raw(crate::tui::text::truncate_width(trimmed, 64)));
+ spans.push(Span::raw(crate::tui::text::truncate_width(
+ trimmed,
+ line_width.saturating_sub(2),
+ )));
}
text.push(Line::from(spans));
}
- if note_lines.len() > take_count {
- text.push(Line::from(""));
+ if has_more {
text.push(
Line::from(Span::styled(
- "... (read more on GitHub)",
+ "... (read more on GitHub release page)",
self.theme.text_dim,
))
.alignment(Alignment::Center),
);
- } else {
- text.push(Line::from(""));
}
text.push(Line::from(""));
text.push(
- Line::from(Span::styled(
- "[Enter] Close popup [o] Open in Browser",
- self.theme.accent,
- ))
+ Line::from(vec![
+ Span::styled("[o]", self.theme.shortcut),
+ Span::styled(" Open Release Page ", self.theme.text),
+ Span::styled("[Esc / Enter]", self.theme.shortcut),
+ Span::styled(" Dismiss", self.theme.text),
+ ])
.alignment(Alignment::Center),
);
- let popup = Paragraph::new(text).block(
- Block::default()
- .borders(Borders::ALL)
- .border_style(self.theme.border),
- );
+ let block = Block::default()
+ .title(" Update Available ")
+ .title_alignment(Alignment::Center)
+ .title_style(self.theme.title)
+ .borders(Borders::ALL)
+ .border_type(if self.state.basic_terminal {
+ BorderType::Plain
+ } else {
+ BorderType::Rounded
+ })
+ .border_style(self.theme.border_focus);
+ let popup = Paragraph::new(text).block(block);
frame.render_widget(popup, popup_area);
}
diff --git a/src/tui/app/search.rs b/src/tui/app/search.rs
index 4c86776..1424de0 100644
--- a/src/tui/app/search.rs
+++ b/src/tui/app/search.rs
@@ -163,9 +163,10 @@ impl App {
if lower_query == "/update" {
self.state.search_query.clear();
self.state.input_mode = InputMode::Normal;
- self.state.active_screen = Screen::Startup;
self.state.update_available = None;
self.state.manual_update_check = true;
+ self.state
+ .set_status("Checking GitHub for updates...".to_string(), 180);
self.action_sender.send(Action::CheckForUpdates).ok();
return Some(true);
}
diff --git a/src/tui/app/system.rs b/src/tui/app/system.rs
index 663164f..32d6137 100644
--- a/src/tui/app/system.rs
+++ b/src/tui/app/system.rs
@@ -195,7 +195,6 @@ impl App {
.ok();
}
}
- _ => {}
},
Action::ClearCache => {
@@ -324,14 +323,7 @@ impl App {
Action::CheckForUpdates => {
let update_sender = self.action_sender.clone();
tokio::spawn(async move {
- let start = tokio::time::Instant::now();
let result = crate::tui::updater::check(env!("CARGO_PKG_VERSION")).await;
-
- let elapsed = start.elapsed();
- if elapsed.as_millis() < 1500 {
- tokio::time::sleep(std::time::Duration::from_millis(1500) - elapsed).await;
- }
-
match result {
Ok(Some((version, notes))) => {
update_sender
@@ -356,27 +348,36 @@ impl App {
}
Action::UpdateAvailable(version, notes) => {
- if self.state.active_screen == Screen::Startup {
- self.state.active_screen = Screen::Home;
- }
+ self.state.last_update_check = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_secs();
+ self.persist_config();
if version == "none" {
- self.state.last_update_check = std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .unwrap_or_default()
- .as_secs();
- self.persist_config();
if self.state.manual_update_check {
+ self.state.set_status(
+ format!(
+ "MovieBox-Tui is up to date (v{}).",
+ env!("CARGO_PKG_VERSION")
+ ),
+ 180,
+ );
self.state.notify(
NotificationKind::Success,
"Up to date",
- "You are using the latest version.",
+ format!(
+ "MovieBox-Tui v{} is the latest version.",
+ env!("CARGO_PKG_VERSION")
+ ),
);
}
self.state.manual_update_check = false;
} else if version.starts_with("error:") {
let err = version.trim_start_matches("error:");
if self.state.manual_update_check {
+ self.state
+ .set_status(format!("Update check failed: {err}"), 180);
self.state.notify(
NotificationKind::Error,
"Update check failed",
@@ -385,12 +386,8 @@ impl App {
}
self.state.manual_update_check = false;
} else {
- self.state.last_update_check = std::time::SystemTime::now()
- .duration_since(std::time::UNIX_EPOCH)
- .unwrap_or_default()
- .as_secs();
- self.persist_config();
self.state.manual_update_check = false;
+ self.reset_transient_overlays();
self.state.update_available = Some((version, notes));
}
}
diff --git a/src/tui/mod.rs b/src/tui/mod.rs
index 0ac0af6..126cd01 100644
--- a/src/tui/mod.rs
+++ b/src/tui/mod.rs
@@ -18,5 +18,4 @@ pub mod screens {
pub mod details;
pub mod help;
pub mod home;
- pub mod startup;
}
diff --git a/src/tui/screens/startup.rs b/src/tui/screens/startup.rs
deleted file mode 100644
index 4c01ea0..0000000
--- a/src/tui/screens/startup.rs
+++ /dev/null
@@ -1,78 +0,0 @@
-use crate::tui::{state::AppState, theme::Theme};
-use ratatui::{
- Frame,
- layout::{Alignment, Constraint, Direction, Layout, Rect},
- style::Modifier,
- text::{Line, Span},
- widgets::{Block, BorderType, Borders, Padding, Paragraph},
-};
-
-pub fn draw(frame: &mut Frame, area: Rect, state: &mut AppState, theme: &Theme) {
- let panel = centered_rect(68.min(area.width.saturating_sub(4)), 10, area);
- let block = Block::default()
- .title(Line::from(vec![
- Span::styled(" MOVIEBOX ", theme.title),
- Span::styled("· STARTUP ", theme.text_dim),
- ]))
- .title_alignment(Alignment::Center)
- .borders(Borders::ALL)
- .border_type(BorderType::Rounded)
- .border_style(theme.border_focus)
- .padding(Padding::new(3, 3, 1, 1));
- let inner = block.inner(panel);
- frame.render_widget(block, panel);
-
- let rows = Layout::default()
- .direction(Direction::Vertical)
- .constraints([
- Constraint::Min(0),
- Constraint::Length(1),
- Constraint::Min(0),
- ])
- .split(inner);
-
- let dots = state.loading_dots();
-
- frame.render_widget(
- Paragraph::new(Line::from(vec![Span::styled(
- format!("Checking GitHub for a newer release{dots}"),
- theme.text,
- )]))
- .alignment(Alignment::Center),
- rows[1],
- );
-
- let footer = Rect {
- x: panel.x,
- y: panel.y.saturating_add(panel.height),
- width: panel.width,
- height: 1,
- };
- let auto_update_label = if state.auto_update {
- " • AUTOMATIC UPDATES ON"
- } else {
- " • AUTOMATIC UPDATES OFF"
- };
-
- frame.render_widget(
- Paragraph::new(Line::from(vec![
- Span::styled("CURRENT ", theme.muted),
- Span::styled(
- format!("v{}", env!("CARGO_PKG_VERSION")),
- theme.text_dim.add_modifier(Modifier::BOLD),
- ),
- Span::styled(auto_update_label, theme.muted),
- ]))
- .alignment(Alignment::Center),
- footer,
- );
-}
-
-fn centered_rect(width: u16, height: u16, area: Rect) -> Rect {
- Rect {
- x: area.x + area.width.saturating_sub(width) / 2,
- y: area.y + area.height.saturating_sub(height) / 2,
- width,
- height: height.min(area.height),
- }
-}
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 9e625eb..88a2e24 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -41,7 +41,6 @@ impl PlayerKind {
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
pub enum Screen {
- Startup,
Home,
Details,
}
@@ -279,7 +278,7 @@ impl Default for AppState {
Self {
active_provider: ProviderKind::MovieBox,
provider_generation: 0,
- active_screen: Screen::Startup,
+ active_screen: Screen::Home,
input_mode: InputMode::Normal,
search_query: String::new(),
last_suggest_query: String::new(),