Skip to content

Commit

Permalink
feat(config): Allow users to set AP port (#1420)
Browse files Browse the repository at this point in the history
* 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 <[email protected]>
  • Loading branch information
gilcu3 and hrkfdn authored Mar 30, 2024
1 parent ba89e50 commit 9624c03
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 5 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions doc/users.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/authentication.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))?;
}
Expand Down
1 change: 1 addition & 0 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
14 changes: 10 additions & 4 deletions src/spotify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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) => {
Expand All @@ -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()
Expand Down Expand Up @@ -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)
Expand Down

0 comments on commit 9624c03

Please sign in to comment.