Refactor duplicated XDG portal code, and remove a buggy fallback path#108665
Closed
wjt wants to merge 4 commits intogodotengine:masterfrom
Closed
Refactor duplicated XDG portal code, and remove a buggy fallback path#108665wjt wants to merge 4 commits intogodotengine:masterfrom
wjt wants to merge 4 commits intogodotengine:masterfrom
Conversation
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
e5cfd64 to
03350b2
Compare
Contributor
Author
|
I have rebased this branch atop |
Contributor
Author
|
Closing this in favour of #108704, which is stacked upon it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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.