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

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

Merged
merged 4 commits into from
Oct 8, 2024

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.

.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

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
frewsxcv#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 frewsxcv:main Oct 8, 2024
4 checks passed
@Be-ing Be-ing deleted the xdg_cleanup branch October 8, 2024 04:40
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