X Tutup
Skip to content

Refactor duplicated XDG portal code, and remove a buggy fallback path#108665

Closed
wjt wants to merge 4 commits intogodotengine:masterfrom
wjt:xdg-portal-refactor
Closed

Refactor duplicated XDG portal code, and remove a buggy fallback path#108665
wjt wants to merge 4 commits intogodotengine:masterfrom
wjt:xdg-portal-refactor

Conversation

@wjt
Copy link
Contributor

@wjt wjt commented Jul 16, 2025

While looking at what changes would be necessary to support the XDG Inhibit portal (#108634) I found that there was a fair amount of duplicated code to use the FileChooser and Screenshot (i.e. color-picker) portals that would need to be duplicated again.

This PR refactors that code, fixing a latent bug in a fallback path in the process. It then adds portal version checking so that the fallback path in question can be removed entirely.

@wjt wjt requested a review from a team as a code owner July 16, 2025 12:12
@wjt wjt force-pushed the xdg-portal-refactor branch from dac4ad5 to e5cfd64 Compare July 16, 2025 12:17
@Calinou Calinou added this to the 4.6 milestone Jul 16, 2025
wjt added 4 commits September 16, 2025 10:59
Previously, a large amount of code was duplicated in the methods which
make a request to the FileChooser and ColorPicker portal interfaces:

1. Generating a unique token for the request
2. Deriving the expected path for the request object and adding a match rule for it
3. Making the request method call
4. Inspecting the method call reply to see if the request object has the expected path
5. If not, updating the match rules accordingly

Factor this out into two internal methods. In the process, fix a bug in
step 5: if the paths did not match, the old code would incorrectly try
to use the returned object path as a match rule (named filter in this
code) rather than building a new match rule for the new path.

I found this bug by inspection. This bug can only be encountered when
using xdg-desktop-portal versions older than 0.10, the first stable
release to support handle_token. This version was released in February
2018, so in practice this code path will never be reached. (In fact, the
entire ColorPicker API was added after the invention of handle_token;
and the FileChooser portal code uses features from a much newer
version.)

A future commit will check the portal versions and remove this
unnecessary fallback path.
Previously, the code would query for the existance of a "version"
property on each portal interface, but disregard its value when deciding whether it can be used.

Instead, check this version. Having checked the code and the
documentation at https://flatpak.github.io/xdg-desktop-portal/docs/:

- FileChooser portal version 3 is required due to the use of the
  "directory" parameter.

- On the Settings portal, the only addition in version 2 is the ReadOne() method which is not used here, so version 1 suffices.

- On the Screenshot portal, the only addition in version 2 is the
  "interactive" parameter to the Screenshot() method; this code only uses
  the PickColor() method, so version 1 suffices.
As documented in
https://flatpak.github.io/xdg-desktop-portal/docs/doc-org.freedesktop.portal.Request.html#org-freedesktop-portal-request,
since version 0.9 of xdg-desktop-portal, Request objects returned by
portal requests have a path that can be determined before the call is
made.

Version 0.10 (the first stable release after 0.9) was released in
February 2018. This code was already relying on portal features from
newer versions; portal interface versions are now checked; and the
fallback logic for pre-0.9 portals was incorrect in 4.4 and earlier so
could never have worked.

Remove the fallback logic. Fail if the request object path is not what
we expected.
Previously, failure to read a setting would print a generic error like this:

    ERROR: Error on D-Bus communication: Requested setting not found

Improve the message to note the name of the setting that could not be read:

    ERROR: Failed to read setting org.freedesktop.appearance accent-color: Requested setting not found
@wjt wjt force-pushed the xdg-portal-refactor branch from e5cfd64 to 03350b2 Compare September 16, 2025 10:19
@wjt
Copy link
Contributor Author

wjt commented Sep 16, 2025

I have rebased this branch atop master. There were no conflicts in this branch, but there were conflicts in #108704 which is stacked upon it.

@wjt
Copy link
Contributor Author

wjt commented Sep 22, 2025

Closing this in favour of #108704, which is stacked upon it.

@wjt wjt closed this Sep 22, 2025
@AThousandShips AThousandShips removed this from the 4.6 milestone Sep 22, 2025
@wjt wjt deleted the xdg-portal-refactor branch November 21, 2025 07:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants

X Tutup