Skip to content

Freedesktop: use ashpd for both sync & async implementations#42

Merged
Be-ing merged 4 commits intorust-dark-light:mainfrom
Be-ing:xdg_cleanup
Oct 8, 2024
Merged

Freedesktop: use ashpd for both sync & async implementations#42
Be-ing merged 4 commits intorust-dark-light:mainfrom
Be-ing:xdg_cleanup

Conversation

@Be-ing
Copy link
Collaborator

@Be-ing Be-ing commented Oct 7, 2024

Before, the sync and async APIs had completely separate implementations. When Linux support was first added in
#6 the XDG Desktop Portal color-scheme API was new and not yet widely supported, so fallbacks were needed. Now, the portal API is more widely supported so the fallbacks are not needed. In my testing, the portal works on:

KDE Plasma
GNOME
Cinnamon
Xfce

MATE does not currently support the portal API. Selecting MATE's GTK themes from Xfce's settings also does not
change what xdg-desktop-portal-gtk reports. I am not sure, but I think that may be due to missing metadata in MATE's
GTK themes. The old implementation never worked on MATE anyway because MATE's dark themes don't have "dark" in
their name, so there's no regression removing it.

@Be-ing Be-ing force-pushed the xdg_cleanup branch 10 times, most recently from 01d0852 to 1d18ab0 Compare October 7, 2024 03:48
@Be-ing Be-ing requested a review from edfloreshz October 7, 2024 03:50
@Be-ing Be-ing mentioned this pull request Oct 7, 2024
.receive_color_scheme_changed()
.await?
.map(Mode::from)
.boxed())
Copy link
Collaborator Author

@Be-ing Be-ing Oct 7, 2024

Choose a reason for hiding this comment

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

I want to prepend the initial value to this stream so the downstream application can get the current state on startup. I used future::stream::once(initial_value()) but that caused the notify example to continually print the initial value instead of printing it once then waiting... suggestions?

This doesn't need to be done in this PR considering the main branch doesn't do that either.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can use the stream![] macro to construct a Stream, perhaps that could be a way.

Copy link
Contributor

Choose a reason for hiding this comment

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

but that caused the notify example to continually print the initial value instead of printing it once then waiting... suggestions?

This is because of a bug in the notify example fixed by #43.

Something like this should work

Ok(stream::once(inital_value()).chain(Settings::new()
        .await?
        .receive_color_scheme_changed()
        .await?
        .map(Mode::from)
        .boxed()))

Copy link
Collaborator

@edfloreshz edfloreshz left a comment

Choose a reason for hiding this comment

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

Some tiny details but overall it looks good 👍🏼

.receive_color_scheme_changed()
.await?
.map(Mode::from)
.boxed())
Copy link
Collaborator

Choose a reason for hiding this comment

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

I think you can use the stream![] macro to construct a Stream, perhaps that could be a way.

.unwrap()
.color_scheme()
.await
.unwrap()
Copy link
Collaborator

Choose a reason for hiding this comment

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

Calling unwrap() here might fail on some platforms, we might want to return Result<Mode>, use ? and handle it in detect().

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

That would require changing the public API of detect. I don't want to change public APIs in this PR, just the implementations.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I didn't mean change detect signature, just initial_value's and then match it in detect.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

I'm not sure bubbling up the error would be helpful unless it's given to the user. But I'm also wondering... do we need to keep the sync API? #45

Copy link
Collaborator

Choose a reason for hiding this comment

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

Let's continue the conversation in #45

Be-ing added 4 commits October 7, 2024 23:20
setting up the XDG Desktop Portal on CI is not easy
Before, the sync and async APIs had completely separate
implementations. When Linux support was first added in
rust-dark-light#6
the XDG Desktop Portal color-scheme API was new and not
yet widely supported, so fallbacks were needed. Now,
the portal API is more widely supported so the fallbacks
are not needed. In my testing, the portal works on:

KDE Plasma
GNOME
Cinnamon
Xfce

MATE does not currently support the portal API. Selecting
MATE's GTK themes from Xfce's settings also does not
change what xdg-desktop-portal-gtk reports. I am not sure,
but I think that may be due to missing metadata in MATE's
GTK themes. The old implementation never worked on MATE
anyway because MATE's dark themes don't have "dark" in
their name, so there's no regression removing it.
This allows downstream applications to respond to the system
light/dark mode preference on application startup while continuing
to react to changes of the preference.
@Be-ing Be-ing merged commit 925fe9d into rust-dark-light:main Oct 8, 2024
@Be-ing Be-ing deleted the xdg_cleanup branch October 8, 2024 04:40
@edfloreshz edfloreshz mentioned this pull request Dec 31, 2024
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.

3 participants