feat: log out of or forget a saved server, and pick one on the login screen
The queue button on a server row in Settings opens a prompt with Cancel, Log out and Forget, replacing the double-press Remove. Log out keeps the address and username without credentials; Forget also deletes the server's saved queue and cover cache. The login screen lists the saved servers beside the form, and a saved login the server turns down at startup is logged out and opens the login screen prefilled. Bumps the version to 0.10.0.
This commit is contained in:
+24
-1
@@ -57,12 +57,22 @@ impl SavedQueues {
|
||||
pub fn set(&mut self, client: &Client, queue: SavedQueue) {
|
||||
self.servers.insert(key(client), queue);
|
||||
}
|
||||
|
||||
/// Drops the queue of a forgotten server, by its address as
|
||||
/// `Client::base` gives it. Returns whether there was one.
|
||||
pub fn forget(&mut self, base: &str, user: &str) -> bool {
|
||||
self.servers.remove(&key_of(base, user)).is_some()
|
||||
}
|
||||
}
|
||||
|
||||
/// Song ids are only unique within one server, and two users of a server
|
||||
/// have their own queues.
|
||||
fn key(client: &Client) -> String {
|
||||
format!("{}@{}", client.user(), client.base())
|
||||
key_of(client.base(), client.user())
|
||||
}
|
||||
|
||||
fn key_of(base: &str, user: &str) -> String {
|
||||
format!("{user}@{base}")
|
||||
}
|
||||
|
||||
pub fn path() -> Option<PathBuf> {
|
||||
@@ -156,6 +166,19 @@ mod tests {
|
||||
let _ = fs::remove_dir_all(path.parent().unwrap());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn forgetting_a_server_drops_only_its_queue() {
|
||||
let home = Client::new("https://home", "u", Auth::Password("p".into()));
|
||||
let other = Client::new("https://other", "u", Auth::Password("p".into()));
|
||||
let mut queues = SavedQueues::default();
|
||||
queues.set(&home, SavedQueue::default());
|
||||
queues.set(&other, SavedQueue::default());
|
||||
assert!(queues.forget(home.base(), home.user()));
|
||||
assert!(!queues.forget(home.base(), home.user()));
|
||||
assert!(queues.get(&home).is_none());
|
||||
assert!(queues.get(&other).is_some());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_queue_saved_before_shuffle_loads_unshuffled() {
|
||||
let path = temp("before-shuffle");
|
||||
|
||||
Reference in New Issue
Block a user