Full Ofline swapping
This commit is contained in:
91
src/main.rs
91
src/main.rs
@@ -239,25 +239,8 @@ impl Default for App {
|
||||
view_stack,
|
||||
offline,
|
||||
|
||||
items: if offline {
|
||||
vec![
|
||||
"Downloaded".into(),
|
||||
"Settings".into(),
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
"Shows".into(),
|
||||
"Movies".into(),
|
||||
"Music".into(),
|
||||
"Playlists".into(),
|
||||
"Collections".into(),
|
||||
"Libraries".into(),
|
||||
"Continue Watching".into(),
|
||||
"Recently Added".into(),
|
||||
"Downloaded".into(),
|
||||
"Settings".into(),
|
||||
]
|
||||
},
|
||||
items: categories_for_mode(offline),
|
||||
|
||||
selected: 0,
|
||||
|
||||
login_user: String::new(),
|
||||
@@ -563,6 +546,51 @@ fn handle_key(app: &mut App, code: KeyCode) {
|
||||
app.status = if app.downloads_focus { "downloads: focus".into() } else { "downloads: unfocus".into() };
|
||||
return;
|
||||
}
|
||||
// Toggle offline/online mode.
|
||||
// - If currently online -> go offline immediately (latched until toggled back).
|
||||
// - If currently offline -> ping server; only switch to online if ping succeeds.
|
||||
if matches!(code, KeyCode::Char('o')) {
|
||||
let base_url = app
|
||||
.config
|
||||
.as_ref()
|
||||
.map(|c| c.base_url.clone())
|
||||
.unwrap_or_default();
|
||||
|
||||
if !app.offline {
|
||||
// Online -> Offline (no ping needed)
|
||||
app.offline = true;
|
||||
app.items = categories_for_mode(true);
|
||||
app.selected = 0;
|
||||
app.view_stack = vec![View::Categories];
|
||||
|
||||
// stop autoplay if it was running (offline shouldn't try to advance via network)
|
||||
app.autoplay = false;
|
||||
app.autoplay_next_index = None;
|
||||
app.autoplay_eof_latched = false;
|
||||
|
||||
app.status = "📴 Offline mode enabled".into();
|
||||
return;
|
||||
}
|
||||
|
||||
// Offline -> Online (must confirm server reachable)
|
||||
if base_url.is_empty() {
|
||||
app.status = "Cannot go online: missing base_url in config".into();
|
||||
return;
|
||||
}
|
||||
|
||||
let ok = core::jellyfin::JellyfinClient::ping_base_url(&base_url);
|
||||
if ok {
|
||||
app.offline = false;
|
||||
app.items = categories_for_mode(false);
|
||||
app.selected = 0;
|
||||
app.view_stack = vec![View::Categories];
|
||||
app.status = "✅ Online mode enabled".into();
|
||||
} else {
|
||||
app.status = "Still offline: server not reachable".into();
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// --------------------
|
||||
// Downloads Focus Modal
|
||||
@@ -1648,7 +1676,9 @@ fn ui(frame: &mut Frame, app: &App) {
|
||||
}
|
||||
|
||||
// ---- Bottom Right: always-on status/help ----
|
||||
let connected = if app.config.as_ref().and_then(|c| c.access_token.as_ref()).is_some() {
|
||||
let connected = if app.offline {
|
||||
"📴 Offline"
|
||||
} else if app.config.as_ref().and_then(|c| c.access_token.as_ref()).is_some() {
|
||||
"✅ Connected"
|
||||
} else {
|
||||
"❌ Disconnected"
|
||||
@@ -3092,3 +3122,24 @@ fn render_offline_library(
|
||||
right,
|
||||
);
|
||||
}
|
||||
|
||||
fn categories_for_mode(offline: bool) -> Vec<String> {
|
||||
if offline {
|
||||
vec![
|
||||
"Downloaded".into(),
|
||||
"Settings".into(),
|
||||
]
|
||||
} else {
|
||||
vec![
|
||||
"Shows".into(),
|
||||
"Movies".into(),
|
||||
"Music".into(),
|
||||
"Playlists".into(),
|
||||
"Collections".into(),
|
||||
"Libraries".into(),
|
||||
"Continue Watching".into(),
|
||||
"Recently Added".into(),
|
||||
"Settings".into(),
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user