Skip to content

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

feat(config): persist and restore last active mode and provider on startup

Samir Hossainsba9d028e387c
diff --git a/src/config.rs b/src/config.rs
index b7ba3d1..b08122f 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -5,6 +5,7 @@ use std::path::PathBuf;
pub struct Config {
pub auto_update: bool,
pub last_update_check: u64,
+ pub active_mode: String,
pub active_provider: ProviderKind,
pub active_theme: String,
pub bdix_enabled: bool,
@@ -20,6 +21,7 @@ impl Default for Config {
Self {
auto_update: true,
last_update_check: 0,
+ active_mode: "streaming".to_string(),
active_provider: ProviderKind::MovieBox,
active_theme: String::new(),
bdix_enabled: false,
@@ -58,6 +60,9 @@ pub fn load() -> Config {
if let Some(v) = value.get("last_update_check").and_then(|v| v.as_u64()) {
config.last_update_check = v;
}
+ if let Some(v) = value.get("active_mode").and_then(|v| v.as_str()) {
+ config.active_mode = v.to_string();
+ }
if let Some(provider) = value.get("active_provider").and_then(|v| v.as_str()) {
config.active_provider = ProviderKind::parse(provider).unwrap_or(config.active_provider);
}
@@ -97,6 +102,7 @@ pub fn save(config: &Config) {
let json = serde_json::json!({
"auto_update": config.auto_update,
"last_update_check": config.last_update_check,
+ "active_mode": config.active_mode,
"active_provider": config.active_provider.cache_key(),
"active_theme": config.active_theme,
"bdix_enabled": config.bdix_enabled,
diff --git a/src/tui/app/addons.rs b/src/tui/app/addons.rs
index 32e64cf..cd94f5d 100644
--- a/src/tui/app/addons.rs
+++ b/src/tui/app/addons.rs
@@ -43,12 +43,15 @@ impl App {
150,
);
}
+ self.persist_config();
}
Action::SwitchToStreamingMode => {
self.reset_mode_state();
self.state.set_mode(crate::tui::state::AppMode::Streaming);
- self.state.active_provider = crate::providers::models::ProviderKind::MovieBox;
+ if self.state.active_provider == crate::providers::models::ProviderKind::Addons {
+ self.state.active_provider = crate::providers::models::ProviderKind::MovieBox;
+ }
self.state.set_status(
format!(
"Streaming mode active ({}).",
@@ -56,6 +59,7 @@ impl App {
),
150,
);
+ self.persist_config();
}
Action::ShowAddonManager => {
diff --git a/src/tui/app/mod.rs b/src/tui/app/mod.rs
index 7880d0a..25099a3 100644
--- a/src/tui/app/mod.rs
+++ b/src/tui/app/mod.rs
@@ -64,6 +64,28 @@ impl App {
} else {
config.active_provider
};
+
+ match config.active_mode.as_str() {
+ "tv" if state.tv_enabled => {
+ state.set_mode(crate::tui::state::AppMode::Tv);
+ }
+ "addon" if state.addons_enabled => {
+ state.set_mode(crate::tui::state::AppMode::Addon);
+ state.active_provider = crate::providers::models::ProviderKind::Addons;
+ }
+ _ => {
+ if state.streaming_enabled {
+ state.set_mode(crate::tui::state::AppMode::Streaming);
+ } else if state.tv_enabled {
+ state.set_mode(crate::tui::state::AppMode::Tv);
+ } else if state.addons_enabled {
+ state.set_mode(crate::tui::state::AppMode::Addon);
+ state.active_provider = crate::providers::models::ProviderKind::Addons;
+ } else {
+ state.set_mode(crate::tui::state::AppMode::Streaming);
+ }
+ }
+ }
state.active_theme_kind = config.active_theme;
state.default_player = config.default_player;
state.download_dir = config.download_dir.map(std::path::PathBuf::from);
@@ -84,7 +106,7 @@ impl App {
let service = std::sync::Arc::new(crate::service::MovieBoxService::new());
- let app = Self {
+ let mut app = Self {
theme,
state,
client: service.client.clone(),
@@ -98,6 +120,12 @@ impl App {
if app.fourk_client.is_none() {
log::warn!("4KHDHub client unavailable; provider will be disabled");
}
+ if app.state.is_tv_mode {
+ app.load_tv_playlists_from_config();
+ app.reload_tv_playlists();
+ } else if app.state.is_addon_mode {
+ app.load_installed_addons_from_config();
+ }
if provider_was_sanitized {
app.persist_config();
}
@@ -117,9 +145,15 @@ impl App {
}
fn persist_config(&self) {
+ let active_mode = match self.state.mode() {
+ crate::tui::state::AppMode::Tv => "tv",
+ crate::tui::state::AppMode::Addon => "addon",
+ crate::tui::state::AppMode::Streaming => "streaming",
+ };
let config = crate::tui::config::Config {
auto_update: self.state.auto_update,
last_update_check: self.state.last_update_check,
+ active_mode: active_mode.to_string(),
active_provider: self.state.active_provider,
active_theme: self.state.active_theme_kind.clone(),
bdix_enabled: self.state.bdix_enabled,
diff --git a/src/tui/app/tv.rs b/src/tui/app/tv.rs
index c878eb0..e94a7e4 100644
--- a/src/tui/app/tv.rs
+++ b/src/tui/app/tv.rs
@@ -78,7 +78,11 @@ impl App {
self.state.tv_config_popup = false;
self.state.search_query.clear();
self.state.search_results.clear();
- self.state.active_provider = crate::providers::models::ProviderKind::MovieBox;
+ if self.state.active_provider == crate::providers::models::ProviderKind::Addons
+ {
+ self.state.active_provider =
+ crate::providers::models::ProviderKind::MovieBox;
+ }
self.state.set_status(
format!(
"Streaming mode active ({}).",
@@ -87,6 +91,7 @@ impl App {
150,
);
}
+ self.persist_config();
}
Action::ShowTvConfig => {