Skip to content

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

feat: add robust update checker popup

Samir Hossainsc7a4643663bc
diff --git a/Cargo.lock b/Cargo.lock
index f58471f..b3c0ee0 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -1268,6 +1268,25 @@ version = "2.12.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d98f6fed1fde3f8c21bc40a1abb88dd75e67924f9cffc3ef95607bad8017f8e2"
+[[package]]
+name = "is-docker"
+version = "0.2.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "928bae27f42bc99b60d9ac7334e3a21d10ad8f1835a4e12ec3ec0464765ed1b3"
+dependencies = [
+ "once_cell",
+]
+
+[[package]]
+name = "is-wsl"
+version = "0.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "173609498df190136aa7dea1a91db051746d339e18476eed5ca40521f02d7aa5"
+dependencies = [
+ "is-docker",
+ "once_cell",
+]
+
[[package]]
name = "itertools"
version = "0.14.0"
@@ -1588,6 +1607,7 @@ dependencies = [
"lru",
"md-5",
"mimalloc",
+ "open",
"rand 0.10.2",
"ratatui",
"ratatui-image",
@@ -1685,6 +1705,16 @@ version = "1.21.4"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
+[[package]]
+name = "open"
+version = "5.4.0"
+source = "registry+https://github.com/rust-lang/crates.io-index"
+checksum = "a0b3d059e795d52b8a72fef45658620edd4d9c359b338564aa14391ffa511ed5"
+dependencies = [
+ "is-wsl",
+ "libc",
+]
+
[[package]]
name = "openssl-probe"
version = "0.2.1"
@@ -2025,7 +2055,7 @@ dependencies = [
"once_cell",
"socket2",
"tracing",
- "windows-sys 0.52.0",
+ "windows-sys 0.61.2",
]
[[package]]
diff --git a/Cargo.toml b/Cargo.toml
index b289eb9..efdeb6a 100644
--- a/Cargo.toml
+++ b/Cargo.toml
@@ -36,6 +36,7 @@ url = "2.5.8"
unicode-segmentation = "1.12.0"
unicode-width = "0.2.0"
mimalloc = "0.1.52"
+open = "5.4.0"
[lib]
name = "moviebox_tui"
diff --git a/src/cache.rs b/src/cache.rs
index 11e4e13..522acfb 100644
--- a/src/cache.rs
+++ b/src/cache.rs
@@ -58,6 +58,45 @@ fn stream_payload_has_results(data: &serde_json::Value) -> bool {
})
}
+pub fn get_image_cache_path(url: &str) -> PathBuf {
+ let mut path = dirs::cache_dir().unwrap_or_else(std::env::temp_dir);
+ path.push("moviebox-tui");
+ path.push("images");
+ if !path.exists() {
+ let _ = fs::create_dir_all(&path);
+ }
+ path.push(format!("{}.img", hash_key(url)));
+ path
+}
+
+pub fn read_image_cache(url: &str) -> Option<Vec<u8>> {
+ let path = get_image_cache_path(url);
+ if path.exists() {
+ if let Ok(bytes) = fs::read(&path) {
+ return Some(bytes);
+ }
+ }
+ None
+}
+
+pub fn write_image_cache(url: &str, data: &[u8]) {
+ let path = get_image_cache_path(url);
+ let stamp = std::time::SystemTime::now()
+ .duration_since(std::time::UNIX_EPOCH)
+ .unwrap_or_default()
+ .as_nanos();
+ let temporary = path.with_extension(format!("tmp-{}-{stamp}", std::process::id()));
+ if fs::write(&temporary, data).is_err() {
+ return;
+ }
+ if fs::rename(&temporary, &path).is_err() {
+ let _ = fs::remove_file(&path);
+ if fs::rename(&temporary, &path).is_err() {
+ let _ = fs::remove_file(temporary);
+ }
+ }
+}
+
pub fn get_cache_dir(subdir: &str) -> PathBuf {
get_provider_cache_dir(ProviderKind::MovieBox, subdir)
}
diff --git a/src/tui/action.rs b/src/tui/action.rs
index 3523601..b5ca86c 100644
--- a/src/tui/action.rs
+++ b/src/tui/action.rs
@@ -103,7 +103,7 @@ pub enum Action {
),
PosterSuccess(String, std::sync::Arc<image::DynamicImage>),
SearchPosterLoaded(String, Option<std::sync::Arc<image::DynamicImage>>),
- UpdateAvailable(String),
+ UpdateAvailable(String, String),
CheckForUpdates,
SetStatus(String),
Refresh,
diff --git a/src/tui/app.rs b/src/tui/app.rs
index 8d9ac95..5324649 100644
--- a/src/tui/app.rs
+++ b/src/tui/app.rs
@@ -913,6 +913,21 @@ impl App {
return None;
}
+ if let Some((version, _)) = &self.state.update_available {
+ match key.code {
+ KeyCode::Enter | KeyCode::Esc => {
+ self.state.update_available = None;
+ }
+ KeyCode::Char('o') | KeyCode::Char('O') => {
+ let url = format!("https://github.com/mesamirh/MovieBox-Tui/releases/tag/v{}", version);
+ let _ = open::that(&url);
+ self.state.update_available = None;
+ }
+ _ => {}
+ }
+ return None;
+ }
+
if key.code == KeyCode::F(1) {
self.action_sender.send(Action::ToggleHelp).ok();
return None;
@@ -4501,23 +4516,23 @@ impl App {
}
match result {
- Ok(Some(version)) => {
- update_sender.send(Action::UpdateAvailable(version)).ok();
+ Ok(Some((version, notes))) => {
+ update_sender.send(Action::UpdateAvailable(version, notes)).ok();
}
Ok(None) => {
update_sender
- .send(Action::UpdateAvailable("none".into()))
+ .send(Action::UpdateAvailable("none".into(), "".into()))
.ok();
}
Err(error) => {
update_sender
- .send(Action::UpdateAvailable(format!("error:{}", error)))
+ .send(Action::UpdateAvailable(format!("error:{}", error), "".into()))
.ok();
}
}
});
}
- Action::UpdateAvailable(version) => {
+ Action::UpdateAvailable(version, notes) => {
if self.state.active_screen == Screen::Startup {
self.state.active_screen = Screen::Home;
}
@@ -4543,12 +4558,7 @@ impl App {
self.state.manual_update_check = false;
} else {
self.state.manual_update_check = false;
- self.state.update_available = Some(version.clone());
- self.state.notify(
- NotificationKind::Info,
- "Update Available",
- format!("Version v{} is available! Download at github.com/mesamirh/MovieBox-Tui", version),
- );
+ self.state.update_available = Some((version, notes));
}
}
}
@@ -4676,6 +4686,72 @@ impl App {
);
}
+ if let Some((version, notes)) = &self.state.update_available {
+ use ratatui::layout::{Constraint, Direction, Layout, Alignment};
+ use ratatui::widgets::{Block, Borders, Paragraph, Clear};
+ use ratatui::text::{Line, Span};
+
+ let popup_width = 65;
+ let popup_height = 20;
+
+ let h_chunks = Layout::default()
+ .direction(Direction::Horizontal)
+ .constraints([
+ Constraint::Min(0),
+ Constraint::Length(popup_width),
+ Constraint::Min(0),
+ ])
+ .split(area);
+
+ let v_chunks = Layout::default()
+ .direction(Direction::Vertical)
+ .constraints([
+ Constraint::Min(0),
+ Constraint::Length(popup_height),
+ Constraint::Min(0),
+ ])
+ .split(h_chunks[1]);
+
+ let popup_area = v_chunks[1];
+ frame.render_widget(Clear, popup_area);
+
+ 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."),
+ Line::from(""),
+ Line::from(format!("Current: v{}", env!("CARGO_PKG_VERSION"))),
+ Line::from(format!("Latest: v{}", version)),
+ Line::from(""),
+ Line::from(Span::styled("Release Notes:", self.theme.highlight)),
+ ];
+
+ let note_lines = notes.lines().filter(|l| !l.trim().is_empty()).take(3).collect::<Vec<_>>();
+ for line in note_lines {
+ let mut truncated = line.to_string();
+ if truncated.len() > 55 {
+ truncated.truncate(55);
+ truncated.push_str("...");
+ }
+ text.push(Line::from(truncated));
+ }
+ if notes.lines().count() > 3 {
+ text.push(Line::from(Span::styled("... (read more on GitHub)", self.theme.text_dim)));
+ }
+
+ text.push(Line::from(""));
+ text.push(Line::from(Span::styled("[Enter] Close popup [o] Open in Browser", self.theme.accent)).alignment(Alignment::Center));
+
+ let popup = Paragraph::new(text)
+ .block(
+ Block::default()
+ .borders(Borders::ALL)
+ .border_style(self.theme.border)
+ );
+
+ frame.render_widget(popup, popup_area);
+ }
+
crate::tui::overlay::notifications(
frame,
area,
diff --git a/src/tui/state.rs b/src/tui/state.rs
index 7d4eaac..11822b3 100644
--- a/src/tui/state.rs
+++ b/src/tui/state.rs
@@ -125,7 +125,7 @@ pub struct AppState {
pub status_message: String,
pub status_timer: usize,
pub notifications: std::collections::VecDeque<crate::tui::overlay::Notification>,
- pub update_available: Option<String>,
+ pub update_available: Option<(String, String)>,
pub auto_update: bool,
pub last_update_check: u64,
pub manual_update_check: bool,
diff --git a/src/tui/updater.rs b/src/tui/updater.rs
index eacff7c..12c117a 100644
--- a/src/tui/updater.rs
+++ b/src/tui/updater.rs
@@ -1,14 +1,14 @@
const OWNER: &str = "mesamirh";
const REPOSITORY: &str = "MovieBox-Tui";
-pub async fn check(current: &str) -> Result<Option<String>, String> {
+pub async fn check(current: &str) -> Result<Option<(String, String)>, String> {
let release = fetch_release().await?;
if !is_newer(current, &release.version) {
return Ok(None);
}
- Ok(Some(release.version.clone()))
+ Ok(Some((release.version.clone(), release.notes.clone())))
}
fn is_newer(current: &str, other: &str) -> bool {
@@ -40,8 +40,10 @@ async fn fetch_release() -> Result<Release, String> {
let item: serde_json::Value = resp.json().await.map_err(|e| format!("bad JSON: {e}"))?;
let tag = item["tag_name"].as_str().ok_or("missing tag_name")?;
+ let body = item["body"].as_str().unwrap_or("").to_string();
Ok(Release {
version: tag.trim_start_matches('v').to_string(),
+ notes: body,
})
}
@@ -56,4 +58,5 @@ fn http_client() -> Result<reqwest::Client, String> {
struct Release {
version: String,
+ notes: String,
}