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

Added possibility to turn on/off shuffle using MPRIS #318

Merged
merged 23 commits into from
Nov 14, 2020
Merged

Added possibility to turn on/off shuffle using MPRIS #318

merged 23 commits into from
Nov 14, 2020

Conversation

Bettehem
Copy link
Contributor

Hello, I added shuffle support for MPRIS.
Solves #317.

For example using playerctl:
playerctl -p ncspot shuffle on -> Turns shuffle on
playerctl -p ncspot shuffle off -> Turns shuffle off

However I'm facing one problem that I can't figure out.
After adding these changes, running playerctl -p ncspot shuffle always returns "Off" regardless of the actual shuffle state.
Without these changes it functions as expected, and returns "On" or "Off" depending on the shuffle state.
I'd imagine it's probably a simple fix but I'm still a Rust newbie so I can't quite figure it out on my own :/

Bettehem and others added 20 commits April 27, 2020 09:50
Removed "user:" from URIType check because Spotify doesn't always provide it.
…the Spotify URI so that it matches the functionality of the official Spotify client.
Added possibility to search for Podcast Episodes.
MPRIS OpenUri function now supports Spotify url links.
@r4v3n6101
Copy link
Contributor

You could do it better using unwrap_or

Changed the default value to be retrieved from spotify.
@Bettehem
Copy link
Contributor Author

Thanks for the suggestion @r4v3n6101! I have changed it to use unwrap_or now.

@hrkfdn
Copy link
Owner

hrkfdn commented Nov 13, 2020

Thanks for the suggestion @r4v3n6101! I have changed it to use unwrap_or now.

Previously an on_set without parameters would toggle the shuffle. Now it just sets the current shuffle setting. Is this intended, or should the default value in unwrap_or be flipped?

@r4v3n6101
Copy link
Contributor

Also if get_spotify is very time consuming operation, you could do it with unwrap_or_else. Previously you have used variable so I didn't pay attention for lazy version of this method.

@Bettehem
Copy link
Contributor Author

Bettehem commented Nov 13, 2020

I was reading the MPRIS specification about the Shuffle property and there was no mention about toggling.
Playerctl has it's own implementation for toggling the shuffle state, which gets the shuffle state of the player and then inverts it.
I'm not quite sure what on_set without parameters should return. Does it ever even get called without parameters because if I understood correctly, on_set only gets called if you use either "On" or "Off"? Perhaps it could be enough to just use unwrap instead of unwrap_or

@r4v3n6101
Copy link
Contributor

Using unwrap may cause application's crash, so it should be backed by default value in this case. You could use either true or false to provide default behaviour. As for me, unwrap isn't such bad way because it crashes with an error if something went wrong.

@Bettehem
Copy link
Contributor Author

Which do you think would be a better default, true or false? Or just the current state but inverted

@r4v3n6101
Copy link
Contributor

I think the best one is not using shuffle cause I'm assuming there's no shuffle by default. Also you can ask @hrkfdn as he defines code design.

@Bettehem
Copy link
Contributor Author

Yeah. Defaulting to no shuffle is probably the best. @hrkfdn what do you think?

@hrkfdn
Copy link
Owner

hrkfdn commented Nov 14, 2020 via email

@Bettehem
Copy link
Contributor Author

So in the case that no setting is supplied, do you mean it would be good to best unwrap_or_default? If just using unwrap would result in a crash.
Oh and a quick question, in this case, does unwrap_or_default work the same way as unwrap_or_else(false)?

@hrkfdn
Copy link
Owner

hrkfdn commented Nov 14, 2020

I think unwrap_or with the current shuffle setting as the default is a solid approach. unwrap_or_default will fall back to the default value of a datatype, e.g. 0 for integers or false for booleans, so in this case it'd turn shuffle off by default. unwrap_or_else executes a closure to set the default value instead.

@hrkfdn
Copy link
Owner

hrkfdn commented Nov 14, 2020

I have pushed a minor change to implement this behavior. Could you confirm that it works for your use-case?

@Bettehem
Copy link
Contributor Author

Yes! It works as it should. Thank you.

@Bettehem
Copy link
Contributor Author

Now there is the next problem though.
For some reason getting the shuffle state always returns "Off" or false but without the addition of .on_set it works normally

And not just once during DBus/MPRIS setup. Also, redraw UI when shuffle
state has changed.
@hrkfdn
Copy link
Owner

hrkfdn commented Nov 14, 2020

Ah, right. Sorry, I didn't have access to a machine running DBus to test it. Now it should work as expected.

@hrkfdn hrkfdn merged commit 9baed7a into hrkfdn:master Nov 14, 2020
@hrkfdn
Copy link
Owner

hrkfdn commented Nov 14, 2020

Merged, thanks!

@hrkfdn hrkfdn mentioned this pull request Nov 14, 2020
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.

None yet

3 participants