forked from Furumi/furumi-tui
Reworked settings menu
This commit is contained in:
1 parent
7d6af59e97
commit
5a193d839f
10 files changed
+387
-185
No files matched your search
@@ -1967,6 +1967,11 @@ fn perform_control_playback_effect(state: &mut AppState, runtime: &mut Runtime,
|
||||
}
|
||||
|
||||
fn clamp_settings_cursor(state: &mut AppState) {
|
||||
state.additional_settings_cursor = state.additional_settings_cursor.min(
|
||||
state::additional_settings_rows(state)
|
||||
.len()
|
||||
.saturating_sub(1),
|
||||
);
|
||||
let last = state::settings_rows(state).len().saturating_sub(1);
|
||||
state.settings_cursor = state.settings_cursor.min(last);
|
||||
}
|
||||
|
||||
+23
-14
@@ -926,6 +926,7 @@ impl FedRow {
|
||||
/// the config directory.
|
||||
#[derive(Debug, Clone, Copy, PartialEq, Eq)]
|
||||
pub enum SettingsRow {
|
||||
AdditionalSettings,
|
||||
CheckUpdate,
|
||||
InstallUpdate,
|
||||
MusicDirectory,
|
||||
@@ -1066,24 +1067,13 @@ pub fn device_status_order(state: &AppState) -> Vec<usize> {
|
||||
indices
|
||||
}
|
||||
|
||||
pub fn settings_rows(state: &AppState) -> Vec<SettingsRow> {
|
||||
/// Secondary settings share actions but have independent navigation.
|
||||
pub fn additional_settings_rows(state: &AppState) -> Vec<SettingsRow> {
|
||||
let mut rows = vec![
|
||||
SettingsRow::MusicDirectory,
|
||||
SettingsRow::CheckUpdate,
|
||||
SettingsRow::InstallUpdate,
|
||||
];
|
||||
rows.extend(SimilarityRow::ALL.into_iter().map(SettingsRow::Similarity));
|
||||
rows.extend(FedRow::ALL.into_iter().map(SettingsRow::Federation));
|
||||
rows.push(SettingsRow::DeviceName);
|
||||
rows.push(SettingsRow::DeviceInvite);
|
||||
rows.push(SettingsRow::DeviceConnect);
|
||||
rows.push(SettingsRow::DeviceSyncNow);
|
||||
rows.push(SettingsRow::DeviceLeaveGroup);
|
||||
rows.extend(
|
||||
device_status_order(state)
|
||||
.into_iter()
|
||||
.map(SettingsRow::Device),
|
||||
);
|
||||
rows.push(SettingsRow::VisualizationClock);
|
||||
rows.extend(
|
||||
state
|
||||
@@ -1097,7 +1087,23 @@ pub fn settings_rows(state: &AppState) -> Vec<SettingsRow> {
|
||||
if !state.visualizer.scripts.is_empty() {
|
||||
rows.push(SettingsRow::VisualizationEdit);
|
||||
}
|
||||
rows.push(SettingsRow::StatusDetails);
|
||||
rows
|
||||
}
|
||||
|
||||
pub fn settings_rows(state: &AppState) -> Vec<SettingsRow> {
|
||||
let mut rows = vec![SettingsRow::AdditionalSettings, SettingsRow::StatusDetails];
|
||||
rows.extend(FedRow::ALL.into_iter().map(SettingsRow::Federation));
|
||||
rows.push(SettingsRow::DeviceName);
|
||||
rows.push(SettingsRow::DeviceInvite);
|
||||
rows.push(SettingsRow::DeviceConnect);
|
||||
rows.push(SettingsRow::DeviceSyncNow);
|
||||
rows.push(SettingsRow::DeviceLeaveGroup);
|
||||
rows.extend(
|
||||
device_status_order(state)
|
||||
.into_iter()
|
||||
.map(SettingsRow::Device),
|
||||
);
|
||||
rows.extend(SimilarityRow::ALL.into_iter().map(SettingsRow::Similarity));
|
||||
rows
|
||||
}
|
||||
|
||||
@@ -1589,6 +1595,9 @@ pub struct AppState {
|
||||
pub status_message: Option<String>,
|
||||
pub spinner_frame: usize,
|
||||
pub settings_cursor: usize,
|
||||
/// Kept open underneath child dialogs and asynchronous confirmations.
|
||||
pub additional_settings_open: bool,
|
||||
pub additional_settings_cursor: usize,
|
||||
/// Root for music permanently downloaded from federation peers.
|
||||
pub music_dir: std::path::PathBuf,
|
||||
pub music_dir_changing: bool,
|
||||
|
||||
+56
-1
@@ -115,6 +115,22 @@ pub fn update(state: &mut AppState, action: Action) -> Option<Effect> {
|
||||
.take()
|
||||
.is_some_and(|deadline| Instant::now() <= deadline);
|
||||
state.status_message = None;
|
||||
if state.additional_settings_open
|
||||
&& !matches!(
|
||||
action,
|
||||
Action::PlayPause
|
||||
| Action::NextTrack
|
||||
| Action::PrevTrack
|
||||
| Action::SeekForward { .. }
|
||||
| Action::SeekBackward { .. }
|
||||
| Action::VolumeUp
|
||||
| Action::VolumeDown
|
||||
| Action::ToggleShuffle
|
||||
| Action::CycleRepeat
|
||||
)
|
||||
{
|
||||
return update_additional_settings(state, action);
|
||||
}
|
||||
match action {
|
||||
// While the help window is open, quit/back just close it.
|
||||
Action::Quit | Action::Back if state.help_visible => {
|
||||
@@ -2814,9 +2830,48 @@ fn fed_card_featured_artist_names(track: &crate::federation::FedCardTrack) -> Ve
|
||||
|
||||
/// Enter on Settings: toggle switches, open text inputs, run
|
||||
/// one-shot operations. The heavy lifting happens in perform_effect().
|
||||
fn update_additional_settings(state: &mut AppState, action: Action) -> Option<Effect> {
|
||||
if state.help_visible {
|
||||
if matches!(action, Action::Back | Action::Quit | Action::ToggleHelp) {
|
||||
state.help_visible = false;
|
||||
}
|
||||
return None;
|
||||
}
|
||||
let rows = super::state::additional_settings_rows(state);
|
||||
let last = rows.len().saturating_sub(1);
|
||||
let cursor = state.additional_settings_cursor.min(last);
|
||||
state.additional_settings_cursor = match action {
|
||||
Action::Back | Action::Quit => {
|
||||
state.additional_settings_open = false;
|
||||
return None;
|
||||
}
|
||||
Action::MoveUp | Action::PrevTab => cursor.saturating_sub(1),
|
||||
Action::MoveDown | Action::NextTab => (cursor + 1).min(last),
|
||||
Action::PageUp => cursor.saturating_sub(5),
|
||||
Action::PageDown => (cursor + 5).min(last),
|
||||
Action::SelectFirst => 0,
|
||||
Action::SelectLast => last,
|
||||
Action::Select => return select_settings_row(state, *rows.get(cursor)?),
|
||||
Action::ToggleHelp => {
|
||||
state.help_visible = true;
|
||||
cursor
|
||||
}
|
||||
_ => cursor,
|
||||
};
|
||||
None
|
||||
}
|
||||
|
||||
fn federation_select(state: &mut AppState) -> Option<Effect> {
|
||||
select_settings_row(state, *settings_rows(state).get(state.settings_cursor)?)
|
||||
}
|
||||
|
||||
fn select_settings_row(state: &mut AppState, row: super::state::SettingsRow) -> Option<Effect> {
|
||||
use super::state::{FedInputField, FedRow, Popup, SettingsRow, SimilarityRow};
|
||||
match settings_rows(state).get(state.settings_cursor).copied()? {
|
||||
match row {
|
||||
SettingsRow::AdditionalSettings => {
|
||||
state.additional_settings_open = true;
|
||||
None
|
||||
}
|
||||
SettingsRow::CheckUpdate => {
|
||||
if state.updater.busy || state.updater.installed {
|
||||
return None;
|
||||
|
||||
+58
-6
@@ -1,25 +1,77 @@
|
||||
use super::*;
|
||||
use crate::library::models::{ArtistCard, ArtistDetail, TrackItem};
|
||||
|
||||
#[test]
|
||||
fn additional_settings_preserve_main_navigation_and_child_dialog_parent() {
|
||||
use crate::app::state::{FedInputField, Popup, SettingsRow, additional_settings_rows};
|
||||
let mut state = AppState {
|
||||
active_tab: Tab::Federation,
|
||||
..AppState::default()
|
||||
};
|
||||
let main_rows = settings_rows(&state);
|
||||
assert!(!main_rows.contains(&SettingsRow::MusicDirectory));
|
||||
assert!(!main_rows.contains(&SettingsRow::CheckUpdate));
|
||||
assert!(!main_rows.contains(&SettingsRow::VisualizationClock));
|
||||
state.settings_cursor = main_rows
|
||||
.iter()
|
||||
.position(|r| *r == SettingsRow::AdditionalSettings)
|
||||
.unwrap();
|
||||
let main_cursor = state.settings_cursor;
|
||||
update(&mut state, Action::Select);
|
||||
assert!(state.additional_settings_open);
|
||||
update(&mut state, Action::Select);
|
||||
assert!(matches!(
|
||||
state.popup,
|
||||
Some(Popup::FedInput {
|
||||
field: FedInputField::MusicDirectory,
|
||||
..
|
||||
})
|
||||
));
|
||||
// Child dialogs own their input; closing one leaves the parent window intact.
|
||||
state.popup = None;
|
||||
assert!(state.additional_settings_open);
|
||||
update(&mut state, Action::SelectLast);
|
||||
assert_eq!(
|
||||
state.additional_settings_cursor,
|
||||
additional_settings_rows(&state).len() - 1
|
||||
);
|
||||
update(&mut state, Action::MoveDown);
|
||||
assert_eq!(
|
||||
state.additional_settings_cursor,
|
||||
additional_settings_rows(&state).len() - 1
|
||||
);
|
||||
update(&mut state, Action::ToggleHelp);
|
||||
update(&mut state, Action::Back);
|
||||
assert!(!state.help_visible);
|
||||
assert!(state.additional_settings_open);
|
||||
update(&mut state, Action::Back);
|
||||
assert!(!state.additional_settings_open);
|
||||
assert!(!state.should_quit);
|
||||
assert_eq!(state.settings_cursor, main_cursor);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn manual_update_check_is_single_flight_and_disabled_after_install() {
|
||||
let mut state = AppState::default();
|
||||
state.settings_cursor = settings_rows(&state)
|
||||
state.additional_settings_cursor = crate::app::state::additional_settings_rows(&state)
|
||||
.iter()
|
||||
.position(|row| *row == crate::app::state::SettingsRow::CheckUpdate)
|
||||
.unwrap();
|
||||
assert_eq!(federation_select(&mut state), Some(Effect::CheckUpdate));
|
||||
assert_eq!(
|
||||
update_additional_settings(&mut state, Action::Select),
|
||||
Some(Effect::CheckUpdate)
|
||||
);
|
||||
assert!(state.updater.busy);
|
||||
assert_eq!(federation_select(&mut state), None);
|
||||
assert_eq!(update_additional_settings(&mut state, Action::Select), None);
|
||||
state.updater.busy = false;
|
||||
state.updater.installed = true;
|
||||
assert_eq!(federation_select(&mut state), None);
|
||||
assert_eq!(update_additional_settings(&mut state, Action::Select), None);
|
||||
state.updater.installed = false;
|
||||
state.settings_cursor = settings_rows(&state)
|
||||
state.additional_settings_cursor = crate::app::state::additional_settings_rows(&state)
|
||||
.iter()
|
||||
.position(|row| *row == crate::app::state::SettingsRow::InstallUpdate)
|
||||
.unwrap();
|
||||
assert_eq!(federation_select(&mut state), None);
|
||||
assert_eq!(update_additional_settings(&mut state, Action::Select), None);
|
||||
}
|
||||
|
||||
fn with_artists(n: usize) -> AppState {
|
||||
|
||||
Reference in new issue
Block a user