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

Refactor file_picker_linux to use the XDG FileChooser portal #1275

Draft
wants to merge 5 commits into
base: master
Choose a base branch
from

Conversation

MateusRodCosta
Copy link

This PR moves from using zenit, qarma and kdialog to use the FileChooser portal instead.

This issue is related to #1270.

Also, currently setting as a draft due to not implementing unit tests yet and due to having to check how to deal with the uris.

@miguelpruivo
Copy link
Owner

@philenius could you review this?

@MateusRodCosta MateusRodCosta marked this pull request as ready for review May 7, 2023 18:16
@MateusRodCosta
Copy link
Author

I am moving this as ready for review.

A few notes:

Only the method for saving files on the FileChooser portal support setting an initial directory right now, they plan on enabling it for the opening files method in the future, see flatpak/xdg-desktop-portal#796.
Also, while it could be enabled, I hit an issue where the file chooser actually refuses to access the directory specified so I decided to disable it. The code I was trying to use is commented out, and the issue related to that seems to be https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/issues/29.

It seems the FileChooser API supports choosing whether dialogs modal, however since on my testing I couldn't see it working, I didn't implement support for that.

I added a small converter from the file:// uri to a normal file path, since I believe that's how file_picker would like it, but I don't know whether it would work well on a sandbox such as the ones from flatpak or snap.

Also, tests are broken. Since I rewrote completely how the linux side works, I would have to re-do them from scratch, that is assuming I can figure out how.

@philenius
Copy link
Collaborator

Thank you very much for your contribution, @MateusRodCosta. I'll look into your PR within the next few days.

lib/src/file_picker_linux.dart Outdated Show resolved Hide resolved
lib/src/file_picker_linux.dart Outdated Show resolved Hide resolved
lib/src/file_picker_linux.dart Outdated Show resolved Hide resolved
@philenius
Copy link
Collaborator

@MateusRodCosta thanks for your implementation.

I added a small converter from the file:// uri to a normal file path, since I believe that's how file_picker would like it, but I don't know whether it would work well on a sandbox such as the ones from flatpak or snap.

The conversion works fine 👍

Also, tests are broken. Since I rewrote completely how the linux side works, I would have to re-do them from scratch, that is assuming I can figure out how.

No problem, we can fix the test later. Let's rather focus on two issues here:

Only the method for saving files on the FileChooser portal support setting an initial directory right now, they plan on enabling it for the opening files method in the future, see flatpak/xdg-desktop-portal#796.
Also, while it could be enabled, I hit an issue where the file chooser actually refuses to access the directory specified so I decided to disable it. The code I was trying to use is commented out, and the issue related to that seems to be https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/issues/29.

This would be a downgrade because our current solution does support setting the initial directory.

It seems the FileChooser API supports choosing whether dialogs modal, however since on my testing I couldn't see it working, I didn't implement support for that.

I would consider this a blocker as long as we cannot figure our how to make it behave like a modal. Our current implementation provides already a limited usability since the file picker dialog sometimes opens in the background. However, I tested the FileChooser Portal implementation on Ubuntu 23 and the file picker dialog is always spawned behind the actual Flutter app.

2023-05-09-22-18-26_uyjUnumj_cropped.mp4

In contrast, our current implementation:

2023-05-09.22-34-07_trimmed_cropped.mp4

I'm sorry, I definitely see advantages in your implementation but I don't want to merge this PR until we can solve the modal issue.

@philenius philenius changed the title Refactor file_picker_linux to use the XDG FileChooser portal Draft: Refactor file_picker_linux to use the XDG FileChooser portal May 9, 2023
@philenius philenius marked this pull request as draft May 9, 2023 20:51
@philenius philenius changed the title Draft: Refactor file_picker_linux to use the XDG FileChooser portal Refactor file_picker_linux to use the XDG FileChooser portal May 9, 2023
@philenius philenius added help wanted Extra attention is needed feature-candidate This issue might result in a feature to be implemented desktop The issue applies to Windows, Linux or MacOS implementations. labels May 9, 2023
@philenius
Copy link
Collaborator

I posted a question in canonical/xdg_desktop_portal.dart#87. Maybe we'll figure it out this way.

@MateusRodCosta
Copy link
Author

Only the method for saving files on the FileChooser portal support setting an initial directory right now, they plan on enabling it for the opening files method in the future, see flatpak/xdg-desktop-portal#796.
Also, while it could be enabled, I hit an issue where the file chooser actually refuses to access the directory specified so I decided to disable it. The code I was trying to use is commented out, and the issue related to that seems to be https://gitlab.gnome.org/GNOME/xdg-desktop-portal-gnome/-/issues/29.

This would be a downgrade because our current solution does support setting the initial directory.

Yeah, makes sense, can't do much besides waiting for the upstream to actually do it =/.

From reading the related issue, it seems to be related to how the following three values are filled : current_directory, current_name and current_file.

I am using right now a combination of both current_name and current_directory. Maybe the bug could be fixed if when using both at the same time we used current_file instead? I will experiment with that.

It seems the FileChooser API supports choosing whether dialogs modal, however since on my testing I couldn't see it working, I didn't implement support for that.

I would consider this a blocker as long as we cannot figure our how to make it behave like a modal. Our current implementation provides already a limited usability since the file picker dialog sometimes opens in the background. However, I tested the FileChooser Portal implementation on Ubuntu 23 and the file picker dialog is always spawned behind the actual Flutter app.
2023-05-09-22-18-26_uyjUnumj_cropped.mp4

In contrast, our current implementation:
2023-05-09.22-34-07_trimmed_cropped.mp4

I'm sorry, I definitely see advantages in your implementation but I don't want to merge this PR until we can solve the modal issue.

Ok, so this I think I know why.
If you noticed, the portal version pops up a notification, that's because it's triggering GNOME's focus stealing prevention. Which means that basically GNOME thought it was some other application which didn't deserve to steal focus from whatever important thing you were doing.

First, the default for modals seem to be true:

modal b

Whether the dialog should be modal. Default is yes.

But it also can take the info of the parent window:

IN s parent_window:

Identifier for the application window, see Common Conventions

On my system (Fedora + GNOME Wayland) it pops up in front, it might behave a bit diferently in X11.
Anyway, I am don't know how to get the window identifier, but using it would probably fix it.

@MateusRodCosta
Copy link
Author

I retried implementing the initialDirectory support to saveFile, this time by also including the "current_file" value.

It still didn't work =/.

I starting to think the issue might either be upstream on the xdg portal Flutter plugin or on the GNOME/GTK portal.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
desktop The issue applies to Windows, Linux or MacOS implementations. feature-candidate This issue might result in a feature to be implemented help wanted Extra attention is needed
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants