feat(config): Allow users to set AP port (#1420)

* added support for ap-port conf

* chore: Reindent table

* feat: Only set `ap_port` in session config if supplied by user

* docs: Update CHANGELOG

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
This commit is contained in:
gilcu3
2024-03-30 19:03:29 +01:00
committed by GitHub
parent ba89e50e10
commit 9624c03264
5 changed files with 16 additions and 5 deletions

View File

@@ -7,6 +7,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
## Unreleased
### Added
- Add configuration variable to set Librespot AP port
### Fixed
- All requests are correctly proxied when the relevant environment variables are set

View File

@@ -266,6 +266,7 @@ Possible configuration values are:
| `[notification_format]` | Set the text displayed in notifications<sup>[4]</sup> | See [notification formatting](#notification-formatting) | |
| `[theme]` | Custom theme | See [custom theme](#theming) | |
| `[keybindings]` | Custom keybindings | See [custom keybindings](#custom-keybindings) | |
| `ap-port` | Set ap-port for librespot (for restrictive firewalls) | `80`, `443`, `4070` | |
1. If built with the `cover` feature.
2. By default the statusbar will show a play icon when a track is playing and

View File

@@ -45,7 +45,7 @@ pub fn get_credentials(configuration: &Config) -> Result<RespotCredentials, Stri
}
};
while let Err(error) = Spotify::test_credentials(credentials.clone()) {
while let Err(error) = Spotify::test_credentials(configuration, credentials.clone()) {
let error_msg = format!("{error}");
credentials = credentials_prompt(Some(error_msg))?;
}

View File

@@ -102,6 +102,7 @@ pub struct ConfigValues {
pub library_tabs: Option<Vec<LibraryTab>>,
pub hide_display_names: Option<bool>,
pub credentials: Option<Credentials>,
pub ap_port: Option<u16>,
}
/// Commands used to obtain user credentials automatically.

View File

@@ -128,7 +128,7 @@ impl Spotify {
}
/// Generate the librespot [SessionConfig] used when creating a [Session].
pub fn session_config() -> SessionConfig {
pub fn session_config(cfg: &config::Config) -> SessionConfig {
let mut session_config = SessionConfig::default();
match env::var("http_proxy") {
Ok(proxy) => {
@@ -137,12 +137,18 @@ impl Spotify {
}
Err(_) => debug!("No HTTP proxy set"),
}
if let Some(ap_port) = cfg.values().ap_port {
session_config.ap_port = Some(ap_port)
}
session_config
}
/// Test whether `credentials` are valid Spotify credentials.
pub fn test_credentials(credentials: Credentials) -> Result<Session, SessionError> {
let config = Self::session_config();
pub fn test_credentials(
cfg: &config::Config,
credentials: Credentials,
) -> Result<Session, SessionError> {
let config = Self::session_config(cfg);
ASYNC_RUNTIME
.get()
.unwrap()
@@ -172,7 +178,7 @@ impl Spotify {
)
.expect("Could not create cache");
debug!("opening spotify session");
let session_config = Self::session_config();
let session_config = Self::session_config(cfg);
Session::connect(session_config, credentials, Some(cache), true)
.await
.map(|r| r.0)