Compare commits
1
Commits
v0.3.5
...
federation
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
292f17fee1 |
No files matched your search
@@ -21,6 +21,10 @@ pub(super) struct RefreshState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl RefreshState {
|
impl RefreshState {
|
||||||
|
pub(super) fn is_loading(&self, card: Card) -> bool {
|
||||||
|
matches!(self.requests.get(&card), Some(None))
|
||||||
|
}
|
||||||
|
|
||||||
fn begin(&mut self, visible: Option<Card>, now: Instant) -> bool {
|
fn begin(&mut self, visible: Option<Card>, now: Instant) -> bool {
|
||||||
let reopened = self.visible != visible;
|
let reopened = self.visible != visible;
|
||||||
self.visible = visible;
|
self.visible = visible;
|
||||||
|
|||||||
@@ -1718,6 +1718,18 @@ pub struct AppState {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl AppState {
|
impl AppState {
|
||||||
|
pub fn artist_federation_loading(&self, id: i64) -> bool {
|
||||||
|
self.card_enrichment
|
||||||
|
.is_loading(super::enrichment::Card::Artist(id))
|
||||||
|
|| matches!(self.artist_fed_views.get(&id), Some(Loadable::Loading))
|
||||||
|
}
|
||||||
|
|
||||||
|
pub fn release_federation_loading(&self, id: i64) -> bool {
|
||||||
|
self.card_enrichment
|
||||||
|
.is_loading(super::enrichment::Card::Release(id))
|
||||||
|
|| matches!(self.release_fed_views.get(&id), Some(Loadable::Loading))
|
||||||
|
}
|
||||||
|
|
||||||
pub fn advance_spinner(&mut self) {
|
pub fn advance_spinner(&mut self) {
|
||||||
self.spinner_frame = self.spinner_frame.wrapping_add(1);
|
self.spinner_frame = self.spinner_frame.wrapping_add(1);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1281,3 +1281,68 @@ fn card_enrichment_refreshes_local_only_success_while_still_open() {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn render_enrichment_card(state: &AppState) -> String {
|
||||||
|
use ratatui::{Terminal, backend::TestBackend};
|
||||||
|
let mut terminal = Terminal::new(TestBackend::new(160, 40)).unwrap();
|
||||||
|
terminal
|
||||||
|
.draw(|frame| crate::ui::global::draw(frame, frame.area(), state))
|
||||||
|
.unwrap();
|
||||||
|
terminal
|
||||||
|
.backend()
|
||||||
|
.buffer()
|
||||||
|
.content
|
||||||
|
.iter()
|
||||||
|
.map(|cell| cell.symbol())
|
||||||
|
.collect()
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn local_card_explains_source_filter_instead_of_waiting_for_a_request() {
|
||||||
|
use crate::app::enrichment;
|
||||||
|
let mut state = enrichment_state(false);
|
||||||
|
state.global.filters.source_mode = crate::config::settings::LibrarySourceMode::Local;
|
||||||
|
assert!(enrichment::prepare(&mut state, std::time::Instant::now()).is_none());
|
||||||
|
let text = render_enrichment_card(&state);
|
||||||
|
assert!(
|
||||||
|
!text.contains("federation: pending"),
|
||||||
|
"Local mode must not promise a request that is disabled"
|
||||||
|
);
|
||||||
|
assert!(
|
||||||
|
text.contains("Local"),
|
||||||
|
"the card must explain why network results are hidden"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn card_refresh_animates_while_previous_results_stay_visible() {
|
||||||
|
use crate::app::enrichment::{self, Card};
|
||||||
|
use std::time::{Duration, Instant};
|
||||||
|
for release in [false, true] {
|
||||||
|
let mut state = enrichment_state(release);
|
||||||
|
let now = Instant::now();
|
||||||
|
assert!(enrichment::prepare(&mut state, now).is_some());
|
||||||
|
let card = if release {
|
||||||
|
Card::Release(1)
|
||||||
|
} else {
|
||||||
|
Card::Artist(1)
|
||||||
|
};
|
||||||
|
state.card_enrichment.complete(card, now);
|
||||||
|
if release {
|
||||||
|
enrichment::store_result(&mut state.release_fed_views, 1, Ok(Default::default()));
|
||||||
|
} else {
|
||||||
|
enrichment::store_result(&mut state.artist_fed_views, 1, Ok(Default::default()));
|
||||||
|
}
|
||||||
|
assert!(enrichment::prepare(&mut state, now + Duration::from_secs(30)).is_some());
|
||||||
|
let first = render_enrichment_card(&state);
|
||||||
|
assert!(first.contains(&format!("{} searching peers", state.spinner())));
|
||||||
|
state.advance_spinner();
|
||||||
|
let next = render_enrichment_card(&state);
|
||||||
|
assert!(next.contains(&format!("{} searching peers", state.spinner())));
|
||||||
|
assert_ne!(first, next);
|
||||||
|
state
|
||||||
|
.card_enrichment
|
||||||
|
.complete(card, now + Duration::from_secs(31));
|
||||||
|
assert!(!render_enrichment_card(&state).contains("searching peers"));
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -537,6 +537,17 @@ fn draw_artist(frame: &mut Frame, area: Rect, state: &AppState, id: i64, cursor:
|
|||||||
about.push_str(&format!(" · appears on {}", detail.featured_tracks.len()));
|
about.push_str(&format!(" · appears on {}", detail.featured_tracks.len()));
|
||||||
}
|
}
|
||||||
let federation_line = match state.artist_fed_views.get(&id) {
|
let federation_line = match state.artist_fed_views.get(&id) {
|
||||||
|
_ if state.federation.settings.enabled
|
||||||
|
&& !state.global.filters.source_mode.includes_network() =>
|
||||||
|
{
|
||||||
|
Some(Line::styled(
|
||||||
|
"federation: hidden by Local filter",
|
||||||
|
theme::dim(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
_ if state.artist_federation_loading(id) => {
|
||||||
|
Some(super::loading_line(state, "searching peers…"))
|
||||||
|
}
|
||||||
Some(Loadable::Loading) => Some(super::loading_line(state, "searching peers…")),
|
Some(Loadable::Loading) => Some(super::loading_line(state, "searching peers…")),
|
||||||
Some(Loadable::Ready(card)) => {
|
Some(Loadable::Ready(card)) => {
|
||||||
let tracks: usize = card
|
let tracks: usize = card
|
||||||
@@ -839,6 +850,17 @@ fn draw_release(frame: &mut Frame, area: Rect, state: &AppState, id: i64, cursor
|
|||||||
let year = detail.year.map(|y| format!(" · {y}")).unwrap_or_default();
|
let year = detail.year.map(|y| format!(" · {y}")).unwrap_or_default();
|
||||||
let tracks = crate::app::state::release_tracks(state, id, detail);
|
let tracks = crate::app::state::release_tracks(state, id, detail);
|
||||||
let federation_line = match state.release_fed_views.get(&id) {
|
let federation_line = match state.release_fed_views.get(&id) {
|
||||||
|
_ if state.federation.settings.enabled
|
||||||
|
&& !state.global.filters.source_mode.includes_network() =>
|
||||||
|
{
|
||||||
|
Some(Line::styled(
|
||||||
|
"federation: hidden by Local filter",
|
||||||
|
theme::dim(),
|
||||||
|
))
|
||||||
|
}
|
||||||
|
_ if state.release_federation_loading(id) => {
|
||||||
|
Some(super::loading_line(state, "searching peers…"))
|
||||||
|
}
|
||||||
Some(Loadable::Loading) => Some(super::loading_line(state, "searching peers…")),
|
Some(Loadable::Loading) => Some(super::loading_line(state, "searching peers…")),
|
||||||
Some(Loadable::Ready(release)) if !release.tracks.is_empty() => Some(Line::styled(
|
Some(Loadable::Ready(release)) if !release.tracks.is_empty() => Some(Line::styled(
|
||||||
format!("federation: +{} tracks", release.tracks.len()),
|
format!("federation: +{} tracks", release.tracks.len()),
|
||||||
|
|||||||
+40
-15
@@ -1,7 +1,7 @@
|
|||||||
mod additional_settings;
|
mod additional_settings;
|
||||||
pub mod art;
|
pub mod art;
|
||||||
mod federation;
|
mod federation;
|
||||||
mod global;
|
pub(crate) mod global;
|
||||||
mod logs;
|
mod logs;
|
||||||
mod playlists;
|
mod playlists;
|
||||||
mod popup;
|
mod popup;
|
||||||
@@ -400,10 +400,12 @@ fn player_right_line(state: &AppState, width: u16) -> (Line<'static>, u16) {
|
|||||||
format!(" {} ", state.device_playback.role.label()),
|
format!(" {} ", state.device_playback.role.label()),
|
||||||
theme::role_pill(state.device_playback.role),
|
theme::role_pill(state.device_playback.role),
|
||||||
));
|
));
|
||||||
spans.push(Span::styled(
|
if width >= 160 {
|
||||||
format!(" · online {}", state.device_playback.online_devices.max(1)),
|
spans.push(Span::styled(
|
||||||
theme::dim(),
|
format!(" · online {}", state.device_playback.online_devices.max(1)),
|
||||||
));
|
theme::dim(),
|
||||||
|
));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Keep a gap between the flags and the username block to the right.
|
// Keep a gap between the flags and the username block to the right.
|
||||||
spans.push(Span::raw(" "));
|
spans.push(Span::raw(" "));
|
||||||
@@ -413,14 +415,34 @@ fn player_right_line(state: &AppState, width: u16) -> (Line<'static>, u16) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Reserve the source-mode badge first so playback details cannot clip it.
|
||||||
|
fn player_row_areas(row: Rect, state: &AppState) -> [Rect; 3] {
|
||||||
|
let badge_width = (format!(" federation: {} ", state.global.filters.source_mode.label()).len()
|
||||||
|
as u16)
|
||||||
|
.min(row.width);
|
||||||
|
let content = Rect::new(
|
||||||
|
row.x,
|
||||||
|
row.y,
|
||||||
|
row.width.saturating_sub(badge_width),
|
||||||
|
row.height,
|
||||||
|
);
|
||||||
|
let badge = Rect::new(content.right(), row.y, badge_width, row.height);
|
||||||
|
let (line, _) = player_right_line(state, content.width);
|
||||||
|
let right_width = line.width().min(usize::from(content.width)) as u16;
|
||||||
|
let [title, right] = Layout::horizontal([
|
||||||
|
Constraint::Min(8.min(content.width)),
|
||||||
|
Constraint::Length(right_width),
|
||||||
|
])
|
||||||
|
.areas(content);
|
||||||
|
[title, right, badge]
|
||||||
|
}
|
||||||
|
|
||||||
/// Shared geometry for rendering and background visualization requests.
|
/// Shared geometry for rendering and background visualization requests.
|
||||||
fn footer_areas(area: Rect, state: &AppState) -> [Rect; 3] {
|
fn footer_areas(area: Rect, state: &AppState) -> [Rect; 3] {
|
||||||
let [player_row, message_row] =
|
let [player_row, message_row] =
|
||||||
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).areas(area);
|
Layout::vertical([Constraint::Length(1), Constraint::Length(1)]).areas(area);
|
||||||
let (line, volume_offset) = player_right_line(state, area.width);
|
let [_, right, badge] = player_row_areas(player_row, state);
|
||||||
let right_width = line.width().min(usize::from(area.width)) as u16;
|
let (_, volume_offset) = player_right_line(state, area.width.saturating_sub(badge.width));
|
||||||
let [_, right] =
|
|
||||||
Layout::horizontal([Constraint::Min(8), Constraint::Length(right_width)]).areas(player_row);
|
|
||||||
let version_width = (env!("CARGO_PKG_VERSION").len() as u16 + 1).min(message_row.width);
|
let version_width = (env!("CARGO_PKG_VERSION").len() as u16 + 1).min(message_row.width);
|
||||||
let version = Rect::new(
|
let version = Rect::new(
|
||||||
message_row.x + message_row.width.saturating_sub(version_width) / 2,
|
message_row.x + message_row.width.saturating_sub(version_width) / 2,
|
||||||
@@ -469,11 +491,8 @@ fn draw_status(frame: &mut Frame, area: Rect, state: &AppState) {
|
|||||||
// Layout: track title left, time/progress/flags on the right. The
|
// Layout: track title left, time/progress/flags on the right. The
|
||||||
// right block is built first and gets a fixed width; the title
|
// right block is built first and gets a fixed width; the title
|
||||||
// truncates into whatever is left.
|
// truncates into whatever is left.
|
||||||
let (center, _) = player_right_line(state, area.width);
|
let [title_area, right_area, mode_area] = player_row_areas(player_row, state);
|
||||||
let center_width = (center.width() as u16).min(area.width);
|
let (center, _) = player_right_line(state, area.width.saturating_sub(mode_area.width));
|
||||||
let [title_area, right_area] =
|
|
||||||
Layout::horizontal([Constraint::Min(8), Constraint::Length(center_width)])
|
|
||||||
.areas(player_row);
|
|
||||||
|
|
||||||
let mut spans = Vec::new();
|
let mut spans = Vec::new();
|
||||||
match &player.current {
|
match &player.current {
|
||||||
@@ -498,6 +517,12 @@ fn draw_status(frame: &mut Frame, area: Rect, state: &AppState) {
|
|||||||
}
|
}
|
||||||
frame.render_widget(Paragraph::new(Line::from(spans)), title_area);
|
frame.render_widget(Paragraph::new(Line::from(spans)), title_area);
|
||||||
frame.render_widget(Paragraph::new(center), right_area);
|
frame.render_widget(Paragraph::new(center), right_area);
|
||||||
|
let mode = state.global.filters.source_mode;
|
||||||
|
frame.render_widget(
|
||||||
|
Paragraph::new(format!(" federation: {} ", mode.label()))
|
||||||
|
.style(theme::source_mode_pill(mode)),
|
||||||
|
mode_area,
|
||||||
|
);
|
||||||
draw_version(frame, version_area);
|
draw_version(frame, version_area);
|
||||||
if crate::visualizer::status::visible(state) {
|
if crate::visualizer::status::visible(state) {
|
||||||
state.status_visualizer.draw(frame, visual_area);
|
state.status_visualizer.draw(frame, visual_area);
|
||||||
@@ -550,7 +575,7 @@ fn active_artist_peer_search(state: &AppState) -> Option<String> {
|
|||||||
let Some(GlobalView::Artist { id, .. }) = state.global.stack.last() else {
|
let Some(GlobalView::Artist { id, .. }) = state.global.stack.last() else {
|
||||||
return None;
|
return None;
|
||||||
};
|
};
|
||||||
if !matches!(state.artist_fed_views.get(id), Some(Loadable::Loading)) {
|
if !state.artist_federation_loading(*id) {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let name = match state.artist_views.get(id) {
|
let name = match state.artist_views.get(id) {
|
||||||
|
|||||||
@@ -108,3 +108,35 @@ fn status_animation_requires_local_unpaused_playback() {
|
|||||||
state.device_playback.role = crate::app::state::DevicePlaybackRole::Control;
|
state.device_playback.role = crate::app::state::DevicePlaybackRole::Control;
|
||||||
assert!(!crate::visualizer::status::playing(&state));
|
assert!(!crate::visualizer::status::playing(&state));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn federation_mode_badge_stays_visible_at_the_right_edge() {
|
||||||
|
use crate::config::settings::LibrarySourceMode;
|
||||||
|
use ratatui::style::Color;
|
||||||
|
let mut state = playing_state();
|
||||||
|
for (mode, background) in [
|
||||||
|
(LibrarySourceMode::Local, Color::Yellow),
|
||||||
|
(LibrarySourceMode::My, Color::Cyan),
|
||||||
|
(LibrarySourceMode::Global, Color::Green),
|
||||||
|
] {
|
||||||
|
state.global.filters.source_mode = mode;
|
||||||
|
for width in [20, 40, 80, 160, 200] {
|
||||||
|
for playing in [false, true] {
|
||||||
|
state.player.playing = playing;
|
||||||
|
state.cmdline.active = !playing;
|
||||||
|
let mut terminal = Terminal::new(TestBackend::new(width, 2)).unwrap();
|
||||||
|
terminal
|
||||||
|
.draw(|frame| draw_status(frame, frame.area(), &state))
|
||||||
|
.unwrap();
|
||||||
|
let label = format!(" federation: {} ", mode.label());
|
||||||
|
let start = width - label.len() as u16;
|
||||||
|
for (offset, ch) in label.chars().enumerate() {
|
||||||
|
let cell = &terminal.backend().buffer()[(start + offset as u16, 0)];
|
||||||
|
assert_eq!(cell.symbol(), ch.to_string());
|
||||||
|
assert_eq!(cell.bg, background);
|
||||||
|
assert_eq!(cell.fg, Color::Black);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -73,6 +73,19 @@ pub fn role_pill(role: DevicePlaybackRole) -> Style {
|
|||||||
.add_modifier(Modifier::BOLD)
|
.add_modifier(Modifier::BOLD)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn source_mode_pill(mode: crate::config::settings::LibrarySourceMode) -> Style {
|
||||||
|
use crate::config::settings::LibrarySourceMode;
|
||||||
|
let bg = match mode {
|
||||||
|
LibrarySourceMode::Local => Color::Yellow,
|
||||||
|
LibrarySourceMode::My => Color::Cyan,
|
||||||
|
LibrarySourceMode::Global => Color::Green,
|
||||||
|
};
|
||||||
|
Style::new()
|
||||||
|
.fg(Color::Black)
|
||||||
|
.bg(bg)
|
||||||
|
.add_modifier(Modifier::BOLD)
|
||||||
|
}
|
||||||
|
|
||||||
fn accent_color_for(state: &AppState) -> Color {
|
fn accent_color_for(state: &AppState) -> Color {
|
||||||
match state.device_playback.role {
|
match state.device_playback.role {
|
||||||
DevicePlaybackRole::Jam => JAM_ACCENT,
|
DevicePlaybackRole::Jam => JAM_ACCENT,
|
||||||
|
|||||||
Reference in new issue
Block a user