Compare commits

...
1 Commits
Author SHA1 Message Date
Ansho Rei d4de15acd8 feat: keep several logins and switch between them
config.toml now holds a list of [[server]] logins and the active one.
The single-login file of earlier versions loads as the only entry.

Settings lists the servers first: confirm switches, the queue button
pressed twice removes, and Add server opens the login form, which can
now be cancelled. Removing the last login returns to the login screen.

A switch saves the queue of the server being left, stops the player and
restores the other server's saved queue paused. Player events sent
before the stop are dropped by an epoch, and cover loads started for the
old server by a generation, so nothing of one server shows on the other.
Covers are cached on disk per server, keyed like the saved queue.

The shoulder triggers wrap around the sections, which puts Settings one
press from the first section.
2026-11-04 18:23:30 +01:00
9 changed files with 473 additions and 50 deletions
+8
View File
@@ -2,6 +2,14 @@
One section per version, newest first.
## v0.8.0 (2026-11-04)
### Features
- Remus keeps several logins and switches between them from Settings, where the servers are listed first. Add server opens the login form, and Cancel goes back. Each server keeps its own queue: switching away stops it, and switching back brings it back paused where it was. A server is removed by pressing the queue button twice on its row.
- The shoulder triggers wrap around the sidebar, so Settings is one press back from Recently added.
- An existing login is kept as the first of the list, with nothing to re-enter.
## v0.7.0 (2026-11-04)
### Features
Generated
+1 -1
View File
@@ -4385,7 +4385,7 @@ checksum = "d6f6ff9a378485b298a5286656da665ba74413d36db0979633275d2e708145d4"
[[package]]
name = "remus"
version = "0.7.0"
version = "0.8.0"
dependencies = [
"anyhow",
"directories",
+1 -1
View File
@@ -1,6 +1,6 @@
[package]
name = "remus"
version = "0.7.0"
version = "0.8.0"
edition = "2024"
license = "MIT"
@@ -20,6 +20,7 @@
</supports>
<content_rating type="oars-1.1"/>
<releases>
<release version="0.8.0" date="2026-11-04"/>
<release version="0.7.0" date="2026-11-04"/>
<release version="0.6.8" date="2026-11-04"/>
<release version="0.6.7" date="2026-11-04"/>
+289 -37
View File
@@ -16,7 +16,7 @@ use slint::{Color, ComponentHandle, Image, ModelRc, Rgb8Pixel, SharedPixelBuffer
use tokio::runtime::Handle;
use tokio::sync::Semaphore;
use crate::config::{self, Config, Settings};
use crate::config::{self, Config, Logins, Settings};
use crate::inhibit::Inhibitor;
use crate::mpris::{self, Mpris};
use crate::palette::{Lab, Palette, Role, Tone};
@@ -135,6 +135,9 @@ enum Setting {
ShowHintBar,
/// The version, listed while the hint bar that normally shows it is off.
Version,
/// A saved login, by index into `Logins::servers`.
Server(usize),
AddServer,
}
/// How long the UI takes to change from one palette to the next.
@@ -218,7 +221,12 @@ struct Covers {
pending: HashSet<CoverKey>,
failed: HashSet<CoverKey>,
limit: Arc<Semaphore>,
/// Per server, under `root`, since ids are only unique within a server.
dir: Option<PathBuf>,
root: Option<PathBuf>,
/// Bumped on a server switch, so a load started for the old server is
/// dropped when it lands instead of filling the new server's cache.
generation: u64,
}
pub struct App {
@@ -230,6 +238,13 @@ pub struct App {
inhibitor: Option<Inhibitor>,
/// Media keys, headphone buttons and the desktop's media controls.
mpris: Mpris,
/// Every saved login and the one being browsed.
logins: Logins,
/// Bumped when the player is stopped for a server switch; player events
/// sent before that are dropped.
player_epoch: Arc<std::sync::atomic::AtomicU64>,
/// A server row whose remove button was pressed once, and when.
remove_armed: Option<(usize, Instant)>,
screen: Screen,
area: Area,
section: usize,
@@ -310,6 +325,9 @@ impl App {
player: None,
inhibitor: Some(inhibitor),
mpris,
logins: Logins::default(),
player_epoch: Arc::default(),
remove_armed: None,
screen: Screen::Login,
area: Area::Content,
section: 0,
@@ -326,7 +344,9 @@ impl App {
pending: HashSet::new(),
failed: HashSet::new(),
limit: Arc::new(Semaphore::new(6)),
dir,
dir: None,
root: dir,
generation: 0,
},
queue: Vec::new(),
current: None,
@@ -366,8 +386,18 @@ impl App {
let labels: Vec<SharedString> = SECTIONS.iter().map(|s| s.label().into()).collect();
self.ui.set_sections(ModelRc::new(VecModel::from(labels)));
match Player::spawn(|ev| {
let _ = slint::invoke_from_event_loop(move || with_app(move |app| app.player_event(ev)));
let epoch = self.player_epoch.clone();
match Player::spawn(move |ev| {
// Stamped when sent, so an event still on its way when the
// server is switched is recognised as the old server's.
let sent = epoch.load(std::sync::atomic::Ordering::Relaxed);
let _ = slint::invoke_from_event_loop(move || {
with_app(move |app| {
if app.player_epoch.load(std::sync::atomic::Ordering::Relaxed) == sent {
app.player_event(ev);
}
})
});
}) {
Ok(p) => self.player = Some(p),
Err(e) => {
@@ -378,15 +408,20 @@ impl App {
self.apply_volume();
match config::load() {
Ok(Some(cfg)) => {
log::info!("using saved login for {} on {}", cfg.username, cfg.url);
self.ui.set_login_server(cfg.url.clone().into());
self.ui.set_login_username(cfg.username.clone().into());
self.enter_browse(cfg.client());
}
Ok(None) => {
log::info!("no saved login, showing the login screen");
self.show_login();
Ok(logins) => {
self.logins = logins;
match self.logins.active().cloned() {
Some(cfg) => {
log::info!("using saved login for {} on {}", cfg.username, cfg.url);
self.ui.set_login_server(cfg.url.clone().into());
self.ui.set_login_username(cfg.username.clone().into());
self.enter_browse(cfg.client());
}
None => {
log::info!("no saved login, showing the login screen");
self.show_login();
}
}
}
Err(e) => {
log::error!("could not read the saved login: {e:#}");
@@ -414,9 +449,33 @@ impl App {
fn show_login(&mut self) {
self.screen = Screen::Login;
self.ui.set_screen(Screen::Login);
// Adding a server from inside the app: the bottom button goes back.
self.ui.set_login_can_cancel(self.client.is_some());
self.set_login_focus(0);
}
/// The login form, empty, for one more server.
fn add_server(&mut self) {
self.ui.set_login_server("".into());
self.ui.set_login_username("".into());
self.ui.set_login_password("".into());
self.ui.set_login_error("".into());
self.show_login();
}
/// Leaves the login form for the server that was being browsed.
fn cancel_login(&mut self) {
if self.client.is_none() {
return;
}
self.ui.set_login_password("".into());
self.ui.set_login_error("".into());
self.screen = Screen::Browse;
self.ui.set_screen(Screen::Browse);
let area = self.area;
self.set_area(area);
}
fn set_login_focus(&mut self, i: i32) {
self.login_focus = i.clamp(0, 4);
self.ui.set_login_focus(self.login_focus);
@@ -429,8 +488,10 @@ impl App {
Action::Up | Action::SectionPrev => self.set_login_focus(self.login_focus - 1),
Action::Down | Action::SectionNext => self.set_login_focus(self.login_focus + 1),
Action::Activate if self.login_focus < 2 => self.set_login_focus(self.login_focus + 1),
Action::Activate if self.login_focus == 4 && self.client.is_some() => self.cancel_login(),
Action::Activate if self.login_focus == 4 => self.action(Action::Quit),
Action::Activate => self.login_submit(),
Action::Back => self.cancel_login(),
_ => {}
}
}
@@ -463,10 +524,9 @@ impl App {
match r {
Ok(client) => {
app.ui.set_login_password("".into());
if let Err(e) = config::save(&Config::from_client(&client)) {
app.toast(format!("Could not save settings: {e:#}"));
}
app.enter_browse(client);
app.logins.add(Config::from_client(&client));
app.save_logins();
app.switch_server(client);
}
Err(e) => app.ui.set_login_error(login_error(&e).into()),
}
@@ -478,9 +538,20 @@ impl App {
let host = client.base().split("://").nth(1).unwrap_or(client.base()).to_string();
self.ui
.set_server_label(format!("{} on {}", client.user(), host).into());
// Keyed like the saved queue, by user and full address.
let key = sanitize(&format!("{}@{}", client.user(), client.base()));
self.covers.dir = self.covers.root.as_ref().map(|r| r.join(key));
if let Some(d) = &self.covers.dir
&& let Err(e) = std::fs::create_dir_all(d)
{
log::warn!("cover cache disabled, cannot create {}: {e}", d.display());
self.covers.dir = None;
}
self.client = Some(client);
self.covers.generation += 1;
self.covers.images.clear();
self.covers.tones.clear();
self.covers.prints.clear();
self.covers.pending.clear();
self.covers.failed.clear();
for stack in &mut self.stacks {
@@ -496,6 +567,107 @@ impl App {
}
}
/// Browses `client`'s server. The server being left keeps its queue on
/// disk and stops; the new one's saved queue comes back paused, so a
/// switch never starts music by itself.
fn switch_server(&mut self, client: Client) {
if self.client.is_some() {
self.save_queue();
self.stop_player();
self.queue.clear();
self.current = None;
self.queue_sel = 0;
self.position = 0.0;
self.duration = 0.0;
self.paused = false;
self.held = false;
self.scrobbled = false;
self.now_playing_due = false;
self.restoring = None;
self.art_shown = None;
self.flip_timer.stop();
self.ui.set_np_flip_out(false);
}
log::info!("browsing {} on {}", client.user(), client.base());
self.enter_browse(client);
self.render_player();
self.sync_queue(true);
self.sync_inhibit();
}
/// Stops playback for good, dropping whatever the player still has on
/// its way about the old queue.
fn stop_player(&self) {
if let Some(p) = &self.player {
p.stop();
}
self.player_epoch.fetch_add(1, std::sync::atomic::Ordering::Relaxed);
}
fn save_logins(&mut self) {
if let Err(e) = config::save(&self.logins) {
self.toast(format!("Could not save the logins: {e:#}"));
}
}
fn select_server(&mut self, i: usize) {
if i == self.logins.active {
return;
}
let Some(cfg) = self.logins.servers.get(i).cloned() else {
return;
};
self.logins.active = i;
self.save_logins();
self.switch_server(cfg.client());
self.toast(format!("Switched to {}", cfg.label()));
}
/// The first press arms, a second within a few seconds removes.
fn remove_server(&mut self, i: usize) {
let Some(cfg) = self.logins.servers.get(i).cloned() else {
return;
};
let armed = self
.remove_armed
.is_some_and(|(j, at)| j == i && at.elapsed() < Duration::from_secs(4));
if !armed {
self.remove_armed = Some((i, Instant::now()));
self.toast(format!("Press again to remove {}", cfg.label()));
return;
}
self.remove_armed = None;
let was_active = i == self.logins.active;
self.logins.remove(i);
self.save_logins();
self.toast(format!("Removed {}", cfg.label()));
if !was_active {
self.refresh_settings();
return;
}
match self.logins.active().cloned() {
Some(next) => self.switch_server(next.client()),
None => {
// Nothing left to browse: stop, keep the queue on disk.
self.save_queue();
self.stop_player();
self.queue.clear();
self.current = None;
self.client = None;
self.render_player();
self.add_server();
}
}
}
/// The section that `delta` steps away, wrapping around, so Settings is
/// one press back from the first section.
fn section_step(&self, delta: isize) -> usize {
let n = SECTIONS.len() as isize;
let from = self.section.min(SECTIONS.len() - 1) as isize;
(from + delta).rem_euclid(n) as usize
}
// ---------------------------------------------------------------- input
/// A key pressed in the window.
@@ -602,8 +774,10 @@ impl App {
}
match self.area {
Area::Sidebar => match a {
Action::Up | Action::SectionPrev => self.select_section(self.section.saturating_sub(1)),
Action::Down | Action::SectionNext => self.select_section((self.section + 1).min(SECTIONS.len() - 1)),
Action::Up => self.select_section(self.section.saturating_sub(1)),
Action::Down => self.select_section((self.section + 1).min(SECTIONS.len() - 1)),
Action::SectionPrev => self.select_section(self.section_step(-1)),
Action::SectionNext => self.select_section(self.section_step(1)),
Action::Activate if SECTIONS[self.section] == Section::Random => {
self.reload_root();
self.enter_content();
@@ -620,9 +794,12 @@ impl App {
}
Action::Activate => self.activate(),
Action::Back => self.back(),
Action::Queue => self.enqueue_selected(),
Action::SectionNext => self.select_section((self.section + 1).min(SECTIONS.len() - 1)),
Action::SectionPrev => self.select_section(self.section.saturating_sub(1)),
Action::Queue => match self.selected_setting() {
Some(Setting::Server(i)) => self.remove_server(i),
_ => self.enqueue_selected(),
},
Action::SectionNext => self.select_section(self.section_step(1)),
Action::SectionPrev => self.select_section(self.section_step(-1)),
_ => {}
},
Area::Search => match a {
@@ -636,8 +813,8 @@ impl App {
self.run_search(q);
}
Action::Back | Action::Left => self.set_area(Area::Sidebar),
Action::SectionNext => self.select_section((self.section + 1).min(SECTIONS.len() - 1)),
Action::SectionPrev => self.select_section(self.section.saturating_sub(1)),
Action::SectionNext => self.select_section(self.section_step(1)),
Action::SectionPrev => self.select_section(self.section_step(-1)),
_ => {}
},
}
@@ -910,6 +1087,14 @@ impl App {
}
}
fn selected_setting(&self) -> Option<Setting> {
let page = self.current_page()?;
match page.entries.get(page.sel)?.target {
Target::Setting(s) => Some(s),
_ => None,
}
}
/// The range setting under the selection, which left and right adjust.
fn selected_range_setting(&self) -> Option<Setting> {
let page = self.current_page()?;
@@ -925,6 +1110,8 @@ impl App {
match setting {
Setting::AlbumArtColours => self.settings.album_art_colours = !self.settings.album_art_colours,
Setting::ShowHintBar => self.settings.show_hint_bar = !self.settings.show_hint_bar,
Setting::Server(i) => return self.select_server(i),
Setting::AddServer => return self.add_server(),
// A range: left and right change it, confirm does nothing.
Setting::CoverBackdrop | Setting::Version => return,
}
@@ -941,7 +1128,11 @@ impl App {
}
self.settings.cover_backdrop = v;
}
Setting::AlbumArtColours | Setting::ShowHintBar | Setting::Version => return,
Setting::AlbumArtColours
| Setting::ShowHintBar
| Setting::Version
| Setting::Server(_)
| Setting::AddServer => return,
}
self.settings_changed();
}
@@ -951,19 +1142,28 @@ impl App {
if let Err(e) = config::save_settings(&self.settings) {
self.toast(format!("Could not save settings: {e:#}"));
}
let entries = settings_data(&self.settings).entries;
let index = SECTIONS.iter().position(|s| *s == Section::Settings).unwrap_or(0);
if let Some(page) = self.stacks[index].first_mut() {
page.entries = entries;
if self.section == index {
self.sync_items(true);
}
}
self.refresh_settings();
self.render_backdrop();
self.ui.set_show_hint_bar(self.settings.show_hint_bar);
self.update_theme();
}
/// Redraws the Settings rows, keeping the selection in range.
fn refresh_settings(&mut self) {
let entries = settings_data(&self.settings, &self.logins).entries;
let index = SECTIONS.iter().position(|s| *s == Section::Settings).unwrap_or(0);
if let Some(page) = self.stacks[index].first_mut() {
page.sel = page.sel.min(entries.len().saturating_sub(1));
page.entries = entries;
if self.section == index {
let sel = page.sel;
self.ui.set_selected(sel as i32);
self.sync_items(true);
self.render_hints();
}
}
}
fn render_backdrop(&self) {
let (opacity, left, right) = backdrop_look(self.settings.cover_backdrop);
self.ui.set_np_backdrop_opacity(opacity);
@@ -1135,7 +1335,7 @@ impl App {
fn load(&mut self, page_id: u64, source: Source) {
if matches!(source, Source::Section(Section::Settings)) {
let data = settings_data(&self.settings);
let data = settings_data(&self.settings, &self.logins);
self.page_loaded(page_id, Ok(data), true);
return;
}
@@ -1463,12 +1663,17 @@ impl App {
};
match self.screen {
Screen::Login => {
let adding = self.client.is_some();
let label = match self.login_focus {
0 | 1 => "Next",
4 if adding => "Cancel",
4 => "Exit",
_ => "Connect",
};
h(Control::Activate, label);
if adding {
h(Control::Back, "Cancel");
}
}
Screen::Browse => match self.area {
Area::Sidebar => {
@@ -1491,6 +1696,13 @@ impl App {
Some(Target::Song(_)) => h(Control::Activate, "Play"),
Some(Target::Setting(Setting::CoverBackdrop)) => h(Control::Seek, "Adjust"),
Some(Target::Setting(Setting::Version)) => {}
Some(Target::Setting(Setting::Server(i))) => {
if *i != self.logins.active {
h(Control::Activate, "Switch");
}
h(Control::Queue, "Remove");
}
Some(Target::Setting(Setting::AddServer)) => h(Control::Activate, "Add"),
Some(Target::Setting(_)) => h(Control::Activate, "Change"),
Some(_) => h(Control::Activate, "Open"),
None if self.current_page().is_some_and(|p| p.error.is_some()) => {
@@ -1587,6 +1799,7 @@ impl App {
.as_ref()
.map(|d| d.join(format!("{}_{px}", sanitize(id))));
let id = id.to_string();
let generation = self.covers.generation;
self.spawn(
async move {
let _permit = limit.acquire_owned().await?;
@@ -1604,7 +1817,11 @@ impl App {
let decoded = tokio::task::spawn_blocking(move || decode_cover(&bytes, px)).await??;
Ok(decoded)
},
move |app, r| app.cover_loaded(key, r),
move |app, r| {
if app.covers.generation == generation {
app.cover_loaded(key, r);
}
},
);
None
}
@@ -2285,8 +2502,41 @@ fn song_entry(s: &Song, index: usize) -> Entry {
}
}
fn settings_data(s: &Settings) -> PageData {
fn settings_data(s: &Settings, logins: &Logins) -> PageData {
let on_off = |on: bool| if on { "On" } else { "Off" }.to_string();
let mut servers: Vec<Entry> = logins
.servers
.iter()
.enumerate()
.map(|(i, cfg)| Entry {
title: cfg.label(),
subtitle: if i == logins.active {
"Browsing now".to_string()
} else {
"Saved login".to_string()
},
detail: if i == logins.active {
"Active".to_string()
} else {
String::new()
},
number: String::new(),
cover: None,
round: false,
show_art: false,
target: Target::Setting(Setting::Server(i)),
})
.collect();
servers.push(Entry {
title: "Add server".to_string(),
subtitle: "Log in to another Subsonic server, keeping this one".to_string(),
detail: String::new(),
number: String::new(),
cover: None,
round: false,
show_art: false,
target: Target::Setting(Setting::AddServer),
});
let mut data = PageData {
entries: vec![
Entry {
@@ -2326,6 +2576,8 @@ fn settings_data(s: &Settings) -> PageData {
],
..Default::default()
};
// Servers first, so switching is the shortest reach in Settings.
data.entries.splice(0..0, servers);
// The bar is where the version normally shows.
if !s.show_hint_bar {
data.entries.push(Entry {
@@ -2570,7 +2822,7 @@ mod tests {
show_hint_bar,
..Settings::default()
};
settings_data(&s)
settings_data(&s, &Logins::default())
.entries
.iter()
.any(|e| e.target == Target::Setting(Setting::Version))
+159 -9
View File
@@ -69,21 +69,104 @@ pub fn state_dir() -> Option<PathBuf> {
dirs().map(|d| d.state_dir().unwrap_or(d.data_dir()).to_path_buf())
}
pub fn load() -> Result<Option<Config>> {
let Some(path) = config_path() else { return Ok(None) };
impl Config {
/// Names the server and user, as the sidebar shows them.
pub fn label(&self) -> String {
let host = self.url.split("://").nth(1).unwrap_or(&self.url);
format!("{} on {}", self.username, host.trim_end_matches('/'))
}
fn same_login(&self, other: &Config) -> bool {
self.url == other.url && self.username == other.username
}
}
/// Every saved login, and which one is browsed.
#[derive(Debug, Clone, Default, PartialEq, Serialize, Deserialize)]
pub struct Logins {
/// Index into `servers`.
#[serde(default)]
pub active: usize,
/// `[[server]]` tables in the file.
#[serde(rename = "server", default)]
pub servers: Vec<Config>,
}
impl Logins {
pub fn active(&self) -> Option<&Config> {
self.servers.get(self.active)
}
/// Adds a login, or refreshes the saved one for the same server and user,
/// and makes it the active one.
pub fn add(&mut self, cfg: Config) {
match self.servers.iter().position(|s| s.same_login(&cfg)) {
Some(i) => {
self.servers[i] = cfg;
self.active = i;
}
None => {
self.servers.push(cfg);
self.active = self.servers.len() - 1;
}
}
}
/// Removes a login. The active one stays the same server where it can;
/// removing it makes the first remaining login active.
pub fn remove(&mut self, i: usize) {
if i >= self.servers.len() {
return;
}
self.servers.remove(i);
if i < self.active {
self.active -= 1;
} else if i == self.active {
self.active = 0;
}
}
}
/// The single login of earlier versions, or the list. Tried in that order:
/// every field of the list has a default, so it would take an old file as an
/// empty list, while the old shape needs `url` and `username` at the top.
#[derive(Deserialize)]
#[serde(untagged)]
enum Stored {
One(Config),
List(Logins),
}
fn parse_logins(text: &str) -> Result<Logins> {
Ok(match toml::from_str::<Stored>(text)? {
Stored::List(mut l) => {
if l.active >= l.servers.len() {
l.active = 0;
}
l
}
Stored::One(c) => Logins {
active: 0,
servers: vec![c],
},
})
}
pub fn load() -> Result<Logins> {
let Some(path) = config_path() else {
return Ok(Logins::default());
};
match fs::read_to_string(&path) {
Ok(text) => Ok(Some(
toml::from_str(&text).with_context(|| format!("parsing {}", path.display()))?,
)),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(None),
Ok(text) => parse_logins(&text).with_context(|| format!("parsing {}", path.display())),
Err(e) if e.kind() == std::io::ErrorKind::NotFound => Ok(Logins::default()),
Err(e) => Err(e).with_context(|| format!("reading {}", path.display())),
}
}
pub fn save(cfg: &Config) -> Result<()> {
pub fn save(logins: &Logins) -> Result<()> {
let path = config_path().context("no config directory")?;
write_atomic(&path, &toml::to_string(cfg)?)?;
log::info!("saved login to {}", path.display());
write_atomic(&path, &toml::to_string(logins)?)?;
log::info!("saved {} login(s) to {}", logins.servers.len(), path.display());
Ok(())
}
@@ -212,6 +295,73 @@ mod tests {
assert!(!text.contains("salt") && !text.contains("token"), "{text}");
}
fn login(url: &str, user: &str, auth: Auth) -> Config {
Config::from_client(&Client::new(url, user, auth))
}
#[test]
fn a_single_login_file_loads_as_the_only_login() {
let old = "url = \"https://h\"\nusername = \"u\"\nsalt = \"s\"\ntoken = \"t\"\n";
let l = parse_logins(old).unwrap();
assert_eq!(l.servers.len(), 1);
assert_eq!(l.active, 0);
assert_eq!(l.active().unwrap().username, "u");
let old = "url = \"https://h\"\nusername = \"u\"\npassword = \"p\"\n";
let l = parse_logins(old).unwrap();
assert_eq!(*l.active().unwrap().client().auth(), Auth::Password("p".into()));
}
#[test]
fn the_login_list_round_trips_with_both_auth_methods() {
let mut l = Logins::default();
l.add(login(
"https://a",
"u",
Auth::Token {
salt: "s".into(),
token: "t".into(),
},
));
l.add(login("https://b", "v", Auth::Password("p".into())));
let text = toml::to_string(&l).unwrap();
assert!(text.contains("[[server]]"), "{text}");
let back = parse_logins(&text).unwrap();
assert_eq!(back, l);
assert_eq!(back.active, 1);
}
#[test]
fn adding_the_same_login_again_replaces_it() {
let mut l = Logins::default();
l.add(login("https://a", "u", Auth::Password("old".into())));
l.add(login("https://b", "u", Auth::Password("p".into())));
l.add(login("https://a", "u", Auth::Password("new".into())));
assert_eq!(l.servers.len(), 2);
assert_eq!(l.active, 0);
assert_eq!(*l.servers[0].client().auth(), Auth::Password("new".into()));
}
#[test]
fn removing_keeps_the_active_server_where_it_can() {
let mut l = Logins::default();
for host in ["https://a", "https://b", "https://c"] {
l.add(login(host, "u", Auth::Password("p".into())));
}
l.active = 2;
l.remove(0);
assert_eq!(l.active().unwrap().url, "https://c");
l.remove(1);
assert_eq!(l.active().unwrap().url, "https://b");
l.remove(0);
assert!(l.active().is_none());
}
#[test]
fn an_out_of_range_active_index_falls_back_to_the_first() {
let text = "active = 5\n[[server]]\nurl = \"https://a\"\nusername = \"u\"\npassword = \"p\"\n";
assert_eq!(parse_logins(text).unwrap().active, 0);
}
#[test]
fn settings_default_when_fields_are_missing() {
let s: Settings = toml::from_str("").unwrap();
+1
View File
@@ -88,6 +88,7 @@ fn step(ui: slint::Weak<AppWindow>, steps: Vec<String>, i: usize) {
"next" => Action::Next,
"play-pause" => Action::PlayPause,
"section-next" => Action::SectionNext,
"section-prev" => Action::SectionPrev,
"now-playing" => Action::NowPlaying,
"search" => Action::Search,
"quit" => Action::Quit,
+7
View File
@@ -143,6 +143,13 @@ impl Player {
start(&self.playbin, &url);
}
/// Stops playback and forgets the queue, as when switching server. Going
/// to Null flushes the bus, so nothing from the old track reports later.
pub fn stop(&self) {
*lock(&self.queue) = Queue::default();
let _ = self.playbin.set_state(gst::State::Null);
}
pub fn toggle_pause(&self) {
// Toggles where the pipeline is heading, so play pressed while a
// paused track is still loading is not lost.
+6 -2
View File
@@ -841,6 +841,8 @@ component LoginView inherits Rectangle {
in property <int> focus-index;
in property <string> error;
in property <bool> busy;
// Adding a server from inside the app: the bottom button goes back.
in property <bool> can-cancel;
callback submit;
callback exit;
callback field-clicked(int);
@@ -920,7 +922,7 @@ component LoginView inherits Rectangle {
border-width: 2px * Theme.s;
border-color: root.focus-index == 4 ? Theme.focus : Theme.line;
Text {
text: "Exit";
text: root.can-cancel ? "Cancel" : "Exit";
font-size: 17px * Theme.s;
color: root.focus-index == 4 ? Theme.text : Theme.muted;
}
@@ -1144,6 +1146,7 @@ export component AppWindow inherits Window {
in property <int> login-focus;
in property <string> login-error;
in property <bool> login-busy;
in property <bool> login-can-cancel;
// Browse
in property <[string]> sections;
@@ -1267,7 +1270,8 @@ export component AppWindow inherits Window {
error: root.login-error;
busy: root.login-busy;
submit => { root.login-submit(); }
exit => { root.action(Action.quit); }
can-cancel: root.login-can-cancel;
exit => { root.action(root.login-can-cancel ? Action.back : Action.quit); }
field-clicked(i) => { root.login-field-clicked(i); }
}