Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(mpris): missing PropertyChanged signal for volume #1368

Merged
merged 1 commit into from
Feb 19, 2024

Conversation

ThomasFrans
Copy link
Contributor

When the volume is changed from inside ncspot, also send a PropertyChanged signal.

Describe your changes

  • Send a DBus PropertyChanged signal every time the volume is changed inside Spotify
  • Make the update() command on the MprisManager more general with different signals

Issue ticket number and link

closes #1328

Checklist before requesting a review

  • Documentation was updated (i.e. due to changes in keybindings, commands, etc.)
  • Changelog was updated with relevant user-facing changes (eg. not dependency updates,
    not performance improvements, etc.)

@ThomasFrans
Copy link
Contributor Author

ThomasFrans commented Jan 6, 2024

Two little gotchas with this PR:

  1. The signal is sent twice when changing volume over MPRIS. I didn't think it was worth it to duplicate the logic in Spotify::set_volume() to solve this as that will probably cause more trouble than it will solve in the long run. I don't see a problem with sending it twice, and there isn't a way to disable it from what I can tell. It this needs to be solved, let me know :)
  2. The implementation is a bit 'un-rustlike' because Spotify depends on MprisManager now and MprisManager on Spotify, so the mpris value in Spotify is optional for this reason, to set it afterwards. I don't know of a better way to do this for now.

I also didn't use PlayerEvent in the end as it's used in two ways (for the playback state and for sending events) which is quite confusing. I feel like it might need to be split into two different enums at some point (one for state and one for events)? If using PlayerEvent is preferred for this issue, also let me know :)

@ThomasFrans ThomasFrans marked this pull request as draft January 13, 2024 15:59
@ThomasFrans ThomasFrans force-pushed the fix-mpris-volume-signal branch from 159b5b3 to c6265be Compare February 5, 2024 14:20
@ThomasFrans
Copy link
Contributor Author

ThomasFrans commented Feb 5, 2024

I changed the names of the commands and prevented the duplicate message when updating the volume through the MPRIS interface. I will work on the events vs state in another PR to not make this one too big. Before touching the configuration stuff I would really like to add tests to that module because I'm scared to break people's configs if I start changing related types.

`dbus-monitor` output with this PR applied
thomas@thomas-desktop-arch:~% dbus-monitor "sender='org.mpris.MediaPlayer2.ncspot.instance22879'"
signal time=1707142778.269864 sender=org.freedesktop.DBus -> destination=:1.162 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameAcquired
   string ":1.162"
signal time=1707142778.269889 sender=org.freedesktop.DBus -> destination=:1.162 serial=4294967295 path=/org/freedesktop/DBus; interface=org.freedesktop.DBus; member=NameLost
   string ":1.162"
signal time=1707142781.119037 sender=:1.155 -> destination=(null destination) serial=22 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Volume"
         variant             double 0.990005
      )
   ]
   array [
   ]
signal time=1707142781.370324 sender=:1.155 -> destination=(null destination) serial=23 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Volume"
         variant             double 0.980011
      )
   ]
   array [
   ]
signal time=1707142781.529028 sender=:1.155 -> destination=(null destination) serial=24 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Volume"
         variant             double 0.990005
      )
   ]
   array [
   ]
signal time=1707142781.631169 sender=:1.155 -> destination=(null destination) serial=25 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Volume"
         variant             double 1
      )
   ]
   array [
   ]
signal time=1707142781.808720 sender=:1.155 -> destination=(null destination) serial=26 path=/org/mpris/MediaPlayer2; interface=org.freedesktop.DBus.Properties; member=PropertiesChanged
   string "org.mpris.MediaPlayer2.Player"
   array [
      dict entry(
         string "Volume"
         variant             double 1
      )
   ]
   array [
   ]

Let me know if this PR is ok or you want to solve it in a different way 🙂

@ThomasFrans ThomasFrans marked this pull request as ready for review February 5, 2024 14:24
Send a `PropertyChanged` signal for the MPRIS volume when the volume
changes inside `ncspot`.
@ThomasFrans ThomasFrans force-pushed the fix-mpris-volume-signal branch from c6265be to 4114a23 Compare February 9, 2024 21:44
@ThomasFrans ThomasFrans requested a review from hrkfdn February 9, 2024 21:46
Copy link
Owner

@hrkfdn hrkfdn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you, LGTM. I was wondering if there's a way to reduce some of the #[cfg] conditionals, but I don't see how. Let's get it in! :)

@hrkfdn hrkfdn merged commit 5b4a175 into hrkfdn:main Feb 19, 2024
5 checks passed
@ThomasFrans
Copy link
Contributor Author

ThomasFrans commented Feb 19, 2024

I was wondering if there's a way to reduce some of the #[cfg] conditionals, but I don't see how. Let's get it in! :)

You don't want to know how much I've thought about this as well. It's hard to get right because there are too many combinations and also because any code that isn't used causes clippy warnings which in turn cause CI to fail. The only solution I can see is to use cross-platform libraries which makes the conditional stuff "someone else's problem" 😄

@ThomasFrans ThomasFrans deleted the fix-mpris-volume-signal branch April 4, 2024 18:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Changing volume internally does not change MPRIS volume
2 participants