Commit Graph

643 Commits

Author SHA1 Message Date
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
Thomas Frans
0cee99ba4c feat: add info command line subcommand (#1330)
* feat: add `info` command line subcommand

Adding an info command allows the documentation to refer to it when
mentioning platform specific information. This gives users a nicer
experience since they don't need to think about how `ncspot` will behave
on their system, but can run `ncspot info` to get that information.

* fix: info command don't create runtime directory

* fix: don't print runtime path on Windows

Windows doesn't use the runtime path so it shouldn't be printed there.

* fix: make `info` command easier to parse

* docs: add back the default configuration directory
2023-11-27 08:43:55 +01:00
Thomas Frans
fcf68995cb fix!: create IPC socket in user runtime directory (#1313)
Each user has their own runtime directory at `/run/user/<uid>`. Creating
the IPC socket in there makes sure it is cleaned up regardless of
whether `ncspot` exits normally.

BREAKING CHANGE: move IPC socket location
2023-10-28 18:43:33 +02:00
Henrik Friedrichsen
6ee00e39d3 Change color of unavailable song
If song is not available/playable, use secondary text color.

Fixes #1300
2023-10-14 22:36:22 +02:00
Henrik Friedrichsen
a1a986344f Revert "feat: move to async POSIX signal handler"
This reverts commit a067ab2ae2.
2023-10-14 12:44:47 +02:00
Thomas Frans
8d00ca74fc fix: MPRIS loop tokio::select!() panic on exit
This fixes a bug that would cause a panic when quiting the process
normally. `tokio::select!()` was used to await a single branch, which is
useless as it can be replaced by a normal await.
2023-10-14 12:42:24 +02:00
Thomas Frans
51d1b34ccc fix: prevent IPC socket cleanup panic
Prevent a panic when the IPC socket isn't available when the user quits
`ncspot`.
2023-10-14 12:15:38 +02:00
Thomas Frans
a69e2d763b fix: disable cursive_buffered_backend tracing
Disable the useless trace logs from the `cursive_buffered_backend`
crate.
2023-10-12 11:14:51 +02:00
Thomas Frans
a067ab2ae2 feat: move to async POSIX signal handler
Instead of trying to handle signals for every step of the `cursive`
event loop, move the signal handling into its own asynchronous task and
send callbacks to `cursive` when a signal arrives.
2023-10-08 10:47:43 +02:00
Thomas Frans
209d8e260b refactor: remove lazy_static crate
The `lazy_static` crate was superseded by the `once_cell` crate which
has been included in Rust's standard library since version `1.70`.
Remove the `lazy_static` dependency and refactor all use cases to use
`std::sync::OnceLock` instead.

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2023-10-07 17:33:48 +02:00
Thomas Frans
2f365c1551 chore: remove placeholder code
Remove the placeholder entries from the command aliases.
2023-10-07 17:27:00 +02:00
Thomas Frans
b27b067a47 fix: prevent MPRIS D-Bus duplicate name
Append `instance<pid>` to the MPRIS bus name to prevent two instances
from fighting over the same bus name.
2023-10-03 17:29:37 +02:00
Thomas Frans
fe8f8e78ee style(clippy): enforce clippy use_self lint
Clippy's `use_self` line ensures that `Self` is used instead of the real
name whenever possible. This makes searching easier and cleans up the
code a bit.
2023-09-27 22:06:54 +02:00
Henrik Friedrichsen
fcf8223e00 Update dependencies
Adapt to rspotify 0.12 breaking changes
2023-09-10 20:32:07 +02:00
Henrik Friedrichsen
c0c7ea8828 Make worker command delivery more resilient
This may discard commands during reauthentication, but at least it doesn't crash
the application.

May help with #993 and #1257
2023-08-29 21:47:07 +02:00
Henrik Friedrichsen
b4a397c84d Use Rc for UserData as it's !Sync 2023-08-26 15:06:23 +02:00
cyqsimon
4942647e1c Improve how we indicate that a command arg is optional 2023-08-21 21:26:17 +02:00
Henrik Friedrichsen
0c13afb46f Fix: fetch album only once
Should speed up display of the context menu

Fixes #1225
2023-07-23 14:49:21 +02:00
Henrik Friedrichsen
bef4742cec Remove duplicate album query 2023-07-23 14:49:21 +02:00
Flynn Duniho
924296ac52 Add add command for adding song to playlist (#1232)
* Add command for adding song to playlist

* edits for code style

* Return playlist dialog via `CommandResult::Modal`

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2023-07-22 16:03:21 +02:00
Henrik Friedrichsen
92cd4f1c8b Handle local tracks in playlist
- Show error on deletion, as we currently do not have a Uri we can pass to the
  Spotify API to delete local files in playlists
- Mark local files in `ListView`

fixes #1213
2023-07-22 15:42:14 +02:00
Henrik Friedrichsen
90b4560a2d Gracefully handle tracks without IDs
As reported in #1231:

Local files in playlists have no IDs. When trying to delete them ncspot crashes
as it tries to extract a track ID.
2023-07-22 15:42:14 +02:00
bentheklutz
2786c6ba34 Sort Artists Ignoring "The" (#1238)
* Sorting QoL

Ignore leading "The" when sorting albums and artists by artist name
in the library.

* Simplify stripping of `The ` prefix in artist

---------

Co-authored-by: Henrik Friedrichsen <henrik@affekt.org>
2023-07-22 13:05:03 +02:00
Henrik Friedrichsen
66bb0746b6 Update to strum 0.25.0 2023-07-22 12:44:50 +02:00
Henrik Friedrichsen
83f9e8d224 Update dependencies 2023-07-22 12:31:26 +02:00
hrdl
f74661a15d feat: add save current command 2023-07-07 11:23:47 +02:00