Commit Graph

668 Commits

Author SHA1 Message Date
Henrik Friedrichsen
5d598e29bd chore: cargo clippy --fix 2025-04-11 10:14:16 +02:00
Henrik Friedrichsen
6e28b40635 chore: Tweak log levels a little
Use `Debug` level for all modules except `ncspot`, which shows `Trace` level
logs by default.
2025-03-16 12:13:47 +01:00
Henrik Friedrichsen
e3e75f7a17 fix: Skip unplayable tracks
I think this worked before but must have regressed. The value `is_playable` was
not taken into account and instead overshadowed by a dummy method.

Fixes #1552
2025-03-16 12:13:47 +01:00
Thomas Frans
9c3c7f7c87 chore: Update to edition 2024
* chore(deps): `cargo update`

* chore: update to Rust edition 2024 and apply fixes

Update the Rust edition and apply changes required in the new edition.
Also update the Cargo manifests to reflect the edition change, and
ensure changes automatically apply to workspace members in the future.

* chore: format all code with `rustfmt`

The new Rust edition comes with some new formatting defaults, which need
to be applied since the edition was increased.

* style: change suggested matches back to `if let`

There has been a breaking change in Rust edition 2024 that changed the
behavior of `if let` statements slightly. The new behavior is more in
line with what users would expect, but could lead to problems in
existing code. The automatic edition update therefore changed such `if
let` statements to match statements instead. That lead to deeply nested
code which was hard to reason about.

This changes most of them back to regular `if let` chains, as the new
behavior shouldn't cause problems for these cases.

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2025-03-11 09:06:39 +00:00
Henrik Friedrichsen
84a8e6443c chore: Remove unnecessary take() call 2025-02-26 20:16:18 +01:00
Memoyu
0f185ebb0b fix: Corrected incorrect comment 2025-02-19 11:07:07 +01:00
Henrik Friedrichsen
0cd44e3b52 chore: other small fixes 2025-02-17 11:01:11 +01:00
Henrik Friedrichsen
48e5aea9aa chore: adapt to rand changes 2025-02-17 11:01:11 +01:00
Henrik Friedrichsen
f08010cfe9 fix: Allow usage of deprecated related artists API
Until there is an alternative continue using it.
2025-01-20 23:35:48 +01:00
e5
75d6b946f7 feat: add %artist formatting option
* add %artist formating option to only show one artist

* add %artist formatting option to only show one artist + docs

* punctuation.
2024-12-29 22:07:12 +01:00
Henrik Friedrichsen
8638ee3cd5 chore(auth): Remove credential program leftovers
With the OAuth2 flow being default now the logic to fetch login credentials via
external programs (i.e. `pass`) has become obsolote.

This change removes documentation/config leftovers.
2024-12-22 19:01:51 +01:00
Henrik Friedrichsen
84f63eb8ce fix(auth): Switch back to Spotify client ID (#1560)
* Revert "feat(auth): use ncspot client id for HTTP requests"

This reverts commit fa298f4f44.

Fixes #1547

* chore: Update CHANGELOG
2024-12-07 15:03:32 +01:00
Henrik Friedrichsen
fa298f4f44 feat(auth): use ncspot client id for HTTP requests
With the newly added `get_token_with_client_id()` API we can pass the ncspot
client ID again to acquire a token for all Web API requests.
2024-10-31 17:32:43 +01:00
Henrik Friedrichsen
9325f0eb40 fix(mpris): Adapt to zbus 5.0.0 changes 2024-10-31 17:15:59 +01:00
Anton Nyström
6dc1229718 fix: Add mut to fix incorrect get of windowsize in cover 2024-10-29 12:19:47 +01:00
Henrik Friedrichsen
f8a0a31a01 fix: Handle librespot Seeked events
With librespot 0.5 the `PlayerEvent` behavior for track seeking seems to have
changed slightly and there is now a dedicated event. This broke seeking in
tracks.

With this change the dedicated event is processed and track position changes
should be picked up again.
2024-09-21 13:36:51 +02:00
elParaguayo
40644e1de1 feat(mpris): Emit Seeked signal
* Add Seeked signal to Mpris interface

The Mpris2 spec includes a `Seeked` signal which should be fired when
the track position changes in an unexpected way i.e. when the user
seeks to a different part of the track.

This PR implements this signal on seek events and also when a new track
begins. The latter is not strictly required but has been observed in
other players (e.g. VLC).

Closes #1492

* chore: Use `send_mpris()` and `Duration` for conversion

* doc: Update CHANGELOG

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2024-09-21 09:55:10 +00:00
Jonte Bergfeld
3893a0ef6d feat(mpris): Restructuring and cleanup
* MPRIS: Restructured existing implementation

My pr addresses some of the inconsistencies in ncspot's mpris
implementation. While the previous logic was technically good enough, it
was inflexible and reported redundant information.
This will make it easier for software, that processes mpris events in
some way, to accurately react to player updates.

- 'Metadata' and 'Playback' updates have been separated into there own
  command
- Mpris commands are only emitted from within spotify.rs
- Some parts of the application creation logic has been
  restructured to allow for mpris events to be emitted upon startup
    - The initial song loading code has been moved from 'Queue::new'
      into 'Application::new'.

* MPRIS: implemented most clippy suggestions

* Fix: applied clippy suggestions + format

* MPRIS: Renamed MprisCommands to be more resonable

I've added a clippy exception so it does not complain to us about enum
variants starting with the same prefix.

---------

Co-authored-by: haruInDisguise <--help>
2024-09-19 21:31:29 +00:00
Henrik Friedrichsen
8b83837a01 Implement OAuth2 login flow
The old user/password flow is deprecated and broken

Fixes #1500
2024-09-19 18:12:14 +02:00
Henrik Friedrichsen
ace23462f7 Migrate ncspot to librespot 0.5 breaking changes
- Set `client_id` via `SessionConfig`
- Use `TokenProvider` to obtain client token instead of custom Mercury call
- Other minor changes
2024-09-19 18:12:14 +02:00
Alexandre Bury
02f72b1c21 chore: Update cursive to 0.21.0
* Update cursive to 0.21.0

* Inject TERM=xterm in CI to help build ncurses backend
2024-08-04 17:27:58 +02:00
Henrik Friedrichsen
b823dfaf6c chore(toolchain): update (#1470)
* [create-pull-request] automated change

* chore: cargo clippy

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-06-22 18:55:12 +02:00
Bettehem
1ffa03daaf fix: support localized Spotify URLs (#1456)
* fix: support localized Spotify URLs

* Update changelog and format using cargo fmt
2024-05-17 21:01:06 +02:00
Henrik Friedrichsen
47403f0d13 chore(toolchain): update (#1452)
* [create-pull-request] automated change

* chore: fix clippy warnings

---------

Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
2024-05-10 15:38:53 +02:00
Twan Stok
2db47e3d39 fix: cfg fix for Linux
changed cfg!(linux) to cfg!(target_os = "linux")
2024-05-07 19:55:22 +02:00
cyqsimon
7f882ccaee style: warn enum_glob_use 2024-04-14 13:36:50 +02:00
Thomas Frans
e976509dae chore: remove todo and improve some code in src/library.rs 2024-04-04 21:56:46 +02:00
gilcu3
9624c03264 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>
2024-03-30 19:03:29 +01:00
cyqsimon
228160608e chore(deps): Bump rspotify to 0.13.0
* Bump rspotify to 0.13.0

Fixes #1384

* Write changelog

* chore: Migrate away from deprecated constructor

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2024-03-09 22:33:54 +01:00
Henrik Friedrichsen
159bfc4d9c feat(sharing): Switch to arboard crate 2024-03-04 14:12:10 +01:00
Konstantin Sobolev
9a26c58f8e fix: Don't panic when token update fails
* fix a panic when token update fails

sometimes we get an `Err` from `token_rx.recv()`, shouldn't panic in such cases

* chore(docs): Update Changelog

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2024-03-02 17:58:49 +00:00
dependabot[bot]
0007bf6de2 chore(deps): bump the cargo group with 3 updates
* chore(deps): bump the cargo group with 3 updates

Bumps the cargo group with 3 updates: [clap](https://github.com/clap-rs/clap), [zbus](https://github.com/dbus2/zbus) and [clap_complete](https://github.com/clap-rs/clap).


Updates `clap` from 4.5.0 to 4.5.1
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.0...clap_complete-v4.5.1)

Updates `zbus` from 3.15.0 to 4.0.1
- [Release notes](https://github.com/dbus2/zbus/releases)
- [Commits](https://github.com/dbus2/zbus/compare/zbus-3.15.0...zbus-4.0.1)

Updates `clap_complete` from 4.5.0 to 4.5.1
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.5.0...clap_complete-v4.5.1)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: zbus
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: cargo
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>

* chore: `cargo update`

* chore: migrate to zbus v4 macros

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2024-02-23 22:39:00 +00:00
Thomas Frans
5b4a17597d fix(mpris): missing PropertyChanged signal for volume
fix(mpris): missing PropertyChanged signal for volume

Send a `PropertyChanged` signal for the MPRIS volume when the volume
changes inside `ncspot`.
2024-02-19 22:46:00 +01:00
Konstantin Sobolev
5e916fd7ec fix: Don't panic if token is still valid
1. `None` from `update_token` should only mean "no update needed", should not be used for errors. We now panic when worker channel is not set
2. Callers should correctly handle `None` result
2024-02-19 22:07:34 +01:00
Konstantin Sobolev
5c71e2f4bf Fix: update token in blocking task
* attempt to fix https://github.com/hrkfdn/ncspot/issues/1358

mpris runs inside `tokio::runtime.spawn`. At some point it hits `metadata_changed->WebApi::track->api_with_retry`, which gets 401 response and tries to update the token.

This goes into `update_token`, which at a certain point calls *blocking* `token_rx.recv()`. Tokio runtime is not happy about that, as it uses the same thread for the `run_loop` in the worker. That's why `tokio::select!` doesn't work, we're essentially deadlocking, so the worker never pick up `RequestToken` command and `update_token` block forever.

Here I'm changing `update_token` to wrap `recv` in `spawn_blocking`, which makes `update_token` return a `JoinHandle`, on which the caller has to await. This doesn't work nicely in case of mpris though, as it is not an async function, and I don't know how to make it async as it goes through the dbus `metadata_changed` interface. My best effort here is to do `and_then`, which seems to work, but I'm not confident that's the right approach.

* fmt

* move token_rx.recv inside spawn_blocking
2024-02-17 12:59:23 +01:00
Thomas Frans
38010b4c76 fix: gracefully exit when misconfigured or unavailable audio backend
When the user has an error in their audio backend configuration or
doesn't have audio backends available, gracefully exit instead of
panicking.
2024-02-06 20:39:29 +01:00
Thomas Frans
3c8e546445 refactor: general small refactors to simplify code
- Remove `expect` in favor of `unwrap` when the `Result`'s error variant
  contains the info in the `expect` anyway (eg. when locking things).
  The line number/context are given by the backtrace.
- Remove over-specification of types (`&T` instead of
  `&RWReadLockGuard`)
- Put reused values into constants
- `FromStr` instead of manual function
- Change `if let Some(()) = ...` to `if T.is_some()`
2024-02-03 18:52:09 +01:00
Thomas Frans
c5d666f35c docs: small overall documentation improvements (#1381)
* docs: small overall documentation improvements

- Add documentation comments to various items
- Change web API return types from bool/Option to Result
- Create helper functions with descriptive names instead of comments
- Remove redundant/confusing types
- Fix some documentation comments as instructed by `cargo doc`
- Rename variables to clear names

* docs: small fixes to the documentation update
2024-02-01 19:42:53 +01:00
Thomas Frans
8805464b1d docs(worker): comment purpose of UI refresh task
The purpose of the manual UI refresh task isn't immediately clear. It
was explained in the commit message of the commit that introduced it.
2024-02-01 14:47:55 +01:00
Thomas Frans
7940365344 refactor(library): various Rust style optimizations
Lots of small fixes to the APIs and functions in the `library` module,
mostly following best practices outlined in the Rust library guidelines.
Changes outside the `library` module were mostly required changes after
changing function signatures.
2024-01-29 21:58:01 +01:00
Thomas Frans
2a4178e069 style: share linting options across packages
Move the Rust and Clippy linting options into the Cargo manifest and
share them with all the packages in the workspace. This ensures a
consistent style in all packages.
2024-01-09 09:22:06 +01:00
Thomas Frans
cb96f46e51 chore: remove unnecessary asynchronous channel
* chore: remove unnecessary asynchronous channel

The channel does not need to be asynchronous as the receiving end is
used in a blocking manner and the sending end of a regular channel never
blocks.

* Fix broken merge

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2024-01-06 12:00:05 +01:00
Thomas Frans
4eff37a3ed style: deny clippy::multiple_inherent_impls lint 2024-01-06 11:37:50 +01:00
Thomas Frans
0eee40e877 fix: crash on Termux due to missing runtime directory
Instead of crashing on Termux, no IPC socket is created. This is a
temporary solution until a suitable runtime directory for the Termux
platform can be found.
2024-01-06 11:35:38 +01:00
dependabot[bot]
2a44323d59 chore(deps): bump the cargo group with 8 updates (#1359)
* chore(deps): bump the cargo group with 8 updates

Bumps the cargo group with 8 updates:

| Package | From | To |
| --- | --- | --- |
| [clap](https://github.com/clap-rs/clap) | `4.4.11` | `4.4.12` |
| [crossbeam-channel](https://github.com/crossbeam-rs/crossbeam) | `0.5.9` | `0.5.10` |
| [futures](https://github.com/rust-lang/futures-rs) | `0.3.29` | `0.3.30` |
| [reqwest](https://github.com/seanmonstar/reqwest) | `0.11.22` | `0.11.23` |
| [serde_json](https://github.com/serde-rs/json) | `1.0.108` | `1.0.109` |
| [tokio](https://github.com/tokio-rs/tokio) | `1.35.0` | `1.35.1` |
| [clap_mangen](https://github.com/clap-rs/clap) | `0.2.15` | `0.2.16` |
| [clap_complete](https://github.com/clap-rs/clap) | `4.4.4` | `4.4.5` |


Updates `clap` from 4.4.11 to 4.4.12
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/v4.4.11...v4.4.12)

Updates `crossbeam-channel` from 0.5.9 to 0.5.10
- [Release notes](https://github.com/crossbeam-rs/crossbeam/releases)
- [Changelog](https://github.com/crossbeam-rs/crossbeam/blob/master/CHANGELOG.md)
- [Commits](https://github.com/crossbeam-rs/crossbeam/compare/crossbeam-channel-0.5.9...crossbeam-channel-0.5.10)

Updates `futures` from 0.3.29 to 0.3.30
- [Release notes](https://github.com/rust-lang/futures-rs/releases)
- [Changelog](https://github.com/rust-lang/futures-rs/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rust-lang/futures-rs/compare/0.3.29...0.3.30)

Updates `reqwest` from 0.11.22 to 0.11.23
- [Release notes](https://github.com/seanmonstar/reqwest/releases)
- [Changelog](https://github.com/seanmonstar/reqwest/blob/master/CHANGELOG.md)
- [Commits](https://github.com/seanmonstar/reqwest/compare/v0.11.22...v0.11.23)

Updates `serde_json` from 1.0.108 to 1.0.109
- [Release notes](https://github.com/serde-rs/json/releases)
- [Commits](https://github.com/serde-rs/json/compare/v1.0.108...v1.0.109)

Updates `tokio` from 1.35.0 to 1.35.1
- [Release notes](https://github.com/tokio-rs/tokio/releases)
- [Commits](https://github.com/tokio-rs/tokio/compare/tokio-1.35.0...tokio-1.35.1)

Updates `clap_mangen` from 0.2.15 to 0.2.16
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_mangen-v0.2.15...clap_mangen-v0.2.16)

Updates `clap_complete` from 4.4.4 to 4.4.5
- [Release notes](https://github.com/clap-rs/clap/releases)
- [Changelog](https://github.com/clap-rs/clap/blob/master/CHANGELOG.md)
- [Commits](https://github.com/clap-rs/clap/compare/clap_complete-v4.4.4...clap_complete-v4.4.5)

---
updated-dependencies:
- dependency-name: clap
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: crossbeam-channel
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: futures
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: reqwest
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: serde_json
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: tokio
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: clap_mangen
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
- dependency-name: clap_complete
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: cargo
...

Signed-off-by: dependabot[bot] <support@github.com>

* Use `.first()` instead of `.get(0)`

* Update dependencies

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2024-01-01 14:56:39 +00:00
Henrik Friedrichsen
ea36d2d42a Add Git commit hash to version string
Fixes #1348
2023-12-16 18:34:43 +01:00
eulerfan271
a826115907 fix(mpris): can_go_previous should always be true (#1346)
* make can_go_previous always true

* can_go_previous whenever queue is non-empty

* docs: Update CHANGELOG

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2023-12-09 11:51:17 +01:00
Thomas Frans
0a1a9bdd4d refactor: tabs rewrite to clean up API
Tabs relied heavily on `ViewExt`'s `title()` function, while also
requiring a separate `id`. The `id`, if used, should be an internal part
of the struct and not part of its API. This also removes the hashmap as
it will never be faster than sequentially looking up all the names,
since there will most likely never be that many tabs in a `TabbedView`.
2023-12-03 12:02:13 +01:00
Thomas Frans
7a9c8f3a5e fix: allow any value to set MPRIS volume
This fixes a small inconsistency between the MPRIS implementation and
the specification. The specification allows any number when setting the
volume, which have to be clamped to the effectively allowed range in the
application.
https://specifications.freedesktop.org/mpris-spec/2.2/Player_Interface.html#Property:Volume
2023-12-01 16:17:00 +01:00
Thomas Frans
e0373890fe feat: improve configuration file error handling
Cleans up the error messages generated when errors are encountered in
the configuration file. Instead of showing the raw error message, give
clear information about the problem.
2023-11-29 09:44:59 +01:00