spotifyd icon indicating copy to clipboard operation
spotifyd copied to clipboard

Refactor Config structs according to features

Open CPerezz opened this issue 4 years ago • 14 comments

As it was stated in #394, structs like SharedConfigValues or SpotifydConfig contain fields like mixer, control and device which only apply if alsa-backend feature is enabled.

Therefore, it would be nice if these fields were only documented when the feature is enabled as well as used.

Closes #394

CPerezz avatar Jan 31 '21 13:01 CPerezz

im not completely sure if changing the config layout like this is a breaking change or not.

I think so. Basically when you're now setting None for these config options, you should directly not specify them or some similar thing. I'd need to check if the configfiles parsing behaves on a friendly way with this. If not, I'll need to refactor this code too.

If it's done by clap or some similar crate, then once compiled that will be handled automatically, otherways I'll need to edit also the configfile parsing.

Also will need to add docs for the different config options considering alsa and non-alsa features.

CPerezz avatar Feb 08 '21 11:02 CPerezz

alright good to know, then we have to bump the version

robinvd avatar Feb 08 '21 11:02 robinvd

We already have another MR that's "waiting" on 0.4 to be merged, we can add this one to the list.

Maybe we should make version branches to keep track?

slondr avatar Feb 08 '21 16:02 slondr

So the macro stuff has been already addressed. And tested.

I'm just concerned about one thing regarding the SpotifyConfig struct.

Should the alsa_backend-only fields be Option<T> or just T? Since as the issue mentions, they need to be expressed if the feature is set.

I made the refactor having the fields like:

#[cfg(feature = "alsa-backend")]
    pub(crate) audio_device: String,
    #[cfg(feature = "alsa-backend")]
    pub(crate) control_device: String,
    #[cfg(feature = "alsa-backend")]
    pub(crate) mixer: String,

But I can change them to be Option<String>.

Once this is clarified, It might need to be specified in the mdbook a bit more clearly IMO. Then the PR will be ready I think.

CPerezz avatar Feb 08 '21 22:02 CPerezz

If it is a plain string, and i specify it in the config but not command line will it then fail?

robinvd avatar Feb 08 '21 22:02 robinvd

If it is a plain string, and i specify it in the config but not command line will it then fail?

Exactly! Good point! Let's make it an Option as it was in the beginning, I thought it was like this due to the backend possibilities but it's also because of being a config param that can be missing too.

CPerezz avatar Feb 08 '21 22:02 CPerezz

I think this looks good! And we should release this in the next breaking change!

robinvd avatar Mar 03 '21 09:03 robinvd

The breaking change concern could be addressed by explicitly telling serde to ignore unknown fields. I do remember there was a way but I can't write it down off the top of my head.

mainrs avatar Mar 27 '21 21:03 mainrs

So the macro stuff has been already addressed. And tested.

I'm just concerned about one thing regarding the SpotifyConfig struct.

Should the alsa_backend-only fields be Option<T> or just T? Since as the issue mentions, they need to be expressed if the feature is set.

I made the refactor having the fields like:

#[cfg(feature = "alsa-backend")]
    pub(crate) audio_device: String,
    #[cfg(feature = "alsa-backend")]
    pub(crate) control_device: String,
    #[cfg(feature = "alsa-backend")]
    pub(crate) mixer: String,

But I can change them to be Option<String>.

Once this is clarified, It might need to be specified in the mdbook a bit more clearly IMO. Then the PR will be ready I think.

I do remember that spotifyd also had a default option that, when no config is supplied, it uses the Default implementation. Setting this to String would break it, as the CLI wouldn't work without the configuration values.

This is something we could (and I think even should!) consider for a large breaking change at some point. I'd rather have mandatory fields than some magic that works in the background (and not even on all machines) .

mainrs avatar Mar 27 '21 21:03 mainrs

Sorry @SirWindfield but this got lost between tons of notifications. The attributes you mention are indeed Option<String> so I'm unsure if this needs any refactoring before it can be approved/landed.

CPerezz avatar Apr 26 '21 10:04 CPerezz

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

stale[bot] avatar Jul 25 '21 12:07 stale[bot]

@mainrs @robinvd is this something that is still not desired?

CPerezz avatar Aug 24 '22 10:08 CPerezz

Hello! I do not have the time to maintain the project actively right now. I think it would still be a good idea to get this PR done, since it just does not make sense to have them in the same struct.

The current code base of spotifyd feels more like patch work then anything else to be honest. The tokio 1.0 rewrite did help though. I definitely am interested in seeing how librespot does these days. Maybe some changes allow us to make the whole client more lightweight in general. Or restructure some features/code modules all together.

I'll definitely investigate this. I cannot tell you when though.

mainrs avatar Aug 26 '22 12:08 mainrs

Thanks for the review comments @eladyn

Will wait to see if @mainrs has more time in the future and address this.

Thank you all! :)

CPerezz avatar Aug 29 '22 08:08 CPerezz