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

File Picker not spawning on Linux (Ubuntu 20.04.3 LTS) #903

Closed
1 of 4 tasks
jlnrrg opened this issue Dec 1, 2021 · 14 comments
Closed
1 of 4 tasks

File Picker not spawning on Linux (Ubuntu 20.04.3 LTS) #903

jlnrrg opened this issue Dec 1, 2021 · 14 comments
Assignees
Labels
desktop The issue applies to Windows, Linux or MacOS implementations. fixed Issue has been addressed and already been deployed or waiting to deploy on master. new issue An issue that hasn't yet been seen from the maintainer

Comments

@jlnrrg
Copy link

jlnrrg commented Dec 1, 2021

Describe the bug
At first I thought it was just my problem, so I cloned your repo and tried the example folder with linux support enabled:
The picker is not showing up. Attached video for demonstration

Platform

  • Android
  • iOS
  • Web
  • Desktop (Go)

Platform OS version

Distributor ID: Ubuntu
Description:    Ubuntu 20.04.3 LTS
Release:        20.04
Codename:       focal

How are you picking?
I did not modify your example folder, so however it is handled there.

Details to reproduce the issue

  1. clone the repo
  2. navigate to the example folder
  3. flutter config --enable-linux-desktop
  4. flutter create . --org com.mr.flutter.plugin
  5. debug using the linux desktop

Error Log
No errors were found in the debug console

Screenshots and/or video

Peek.2021-12-01.14-31.mp4

Flutter Version details

Flutter 2.5.3 • channel stable • https://github.com/flutter/flutter.git
Framework • revision 18116933e7 (7 weeks ago) • 2021-10-15 10:46:35 -0700
Engine • revision d3ea636dc5
Tools • Dart 2.14.4
@jlnrrg jlnrrg added the new issue An issue that hasn't yet been seen from the maintainer label Dec 1, 2021
@philenius philenius added the desktop The issue applies to Windows, Linux or MacOS implementations. label Dec 2, 2021
@philenius
Copy link
Collaborator

Thank you for providing a screen recording, @jlnrrg . I followed your steps, created a fresh copy of the GitHub repository, and ran the example app. On my laptop, everything works as expected 🤔 Frankly, I'm a little stumped here...

My environment is exactly the same as yours (even the same Ubuntu distribution):

[✓] Flutter (Channel stable, 2.5.3, on Ubuntu 20.04.3 LTS)
    • Flutter version 2.5.3 at /home/phil/snap/flutter/common/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 18116933e7 (7 weeks ago), 2021-10-15 10:46:35 -0700
    • Engine revision d3ea636dc5
    • Dart version 2.14.4

Which version of this file_picker do you use? It should be the latest version because you cloned it from GitHub, right?

Internally, the Linux implementation of file_picker executes a simple shell command. Ideally, we would call the Linux C++ APIs directly but we lack the expertise to implement this. Therefore, we use one of the CLIs qarma or zenity (whichever is available) instead. The following command should open a file picker dialog. Can you please check this?

# zenity should be available on Ubuntu
zenity --file-selection --title "Select a file:"
# alternatively:
qarma --file-selection --title "Select a file:"

@jlnrrg
Copy link
Author

jlnrrg commented Dec 2, 2021

The screenrecording is a given 😄

The example project uses:

file_picker:
    path: ../

and the upper folder is version 4.2.6

zenity --file-selection --title "Select a file:"
worked like a charm

qarma --file-selection --title "Select a file:"
didn't work, as the command was not found

This is indeed a peculiar problem.
If I can be of further assist, I am willing to do a screen sharing if that is of interest to you.
You can find my contact info in my profile.
(Otherwise this is also fine)

@jlnrrg
Copy link
Author

jlnrrg commented Dec 3, 2021

I enabled to debug all Exceptions and uncaught Exceptions and the filePicker throws the error:
_Exception (Exception: Couldn't find the executable qarma in the path.)
Which is bc qarma is not installed on my system.
As noted before this should be the alternative solution, so there might be an error of trying to instantiating it even when it is not used.

@philenius
Copy link
Collaborator

Thank you for providing all the details, @jlnrrg.

I enabled to debug all Exceptions and uncaught Exceptions and the filePicker throws the error:
_Exception (Exception: Couldn't find the executable qarma in the path.)
Which is bc qarma is not installed on my system.
As noted before this should be the alternative solution, so there might be an error of trying to instantiating it even when it is not used.

Also, thanks for checking with All Exceptions enabled in VS Code. As you said, this exception is expected behavior because we check for qarma first and then use zenity as a backup:

Future<String> _getPathToExecutable() async {
try {
return await isExecutableOnPath('qarma');
} on Exception {
return await isExecutableOnPath('zenity');
}
}

Thanks for offering a screen sharing. I might contact you for a screen sharing but honestly I'm too busy writing my master thesis.

@jlnrrg
Copy link
Author

jlnrrg commented Dec 7, 2021

A totally reasonable excuse 😄.

Is qarma chosen as the default over zenity by design?
If not I could offer a PR to first check for existence, to reduce your workload a little 👍 .

@philenius
Copy link
Collaborator

@jlnrrg , thank you for your understanding.

There is no particular reason why we check qarma first followed by zenity other than that the original implementation in Go (https://github.com/gen2brain/dlgs/blob/master/dlgs_linux.go) does it the same way. I'd be fine with you creating a PR to switch the order so that zenity is tried first. It could be that zenity is much more common because it's comes preinstalled with GNOME/Ubuntu...

@jlnrrg
Copy link
Author

jlnrrg commented Dec 16, 2021

I debugged a little further and it does not seem to be an issue with the executable selection, but more with the runExecutableWithArguments function.

if I manually type /usr/bin/zenity --file-selection --title "File Picker" in my terminal, the file picker spawns no problem.
If I let the code run, which is like the following, nothing spawns, the return value is null and the processResult exitCode is -11

runExecutableWithArguments(
      "/usr/bin/zenity",
      [
          "--file-selection"
          "--title",
          "File Picker",
      ]
    );

I'll investigate further

Edit:
The error code seems to be a segmentation fault error. Which I am not familiar with.
First I though it is an access problem but with the following rights this seems unlikely:

-rwxr-xr-x 1 root root 135960 Feb 27  2020 /usr/bin/zenity

Edit 2:
For a change of pace, I installed qarma, but while it did spawn the file picker window.
It had no access rights for any folder (probably bc of snap install).

@philenius
Copy link
Collaborator

philenius commented Dec 18, 2021

Thank you for investigating, @jlnrrg.

First I though it is an access problem but with the following rights this seems unlikely:
-rwxr-xr-x 1 root root 135960 Feb 27 2020 /usr/bin/zenity

I agree with you, this shouldn't be a problem as long as zenity has the executable-flag. On my computer, the zenity binary has the same permissions.

I would have one more idea: I always wondered how Process.run() handles arguments with blanks/whitespace. Are arguments with blanks automatically quoted? Maybe the segmentation fault is caused by the blank in the title. Could you retry with a single-word title so that runExecutableWithArguments() is invoked like this?

runExecutableWithArguments(
      "/usr/bin/zenity",
      [
          "--file-selection"
          "--title",
          "Dialog",
      ]
);

If a single-word title doesn't work either, could you please play around with Process.run()? Process.run() offers many more parameters which we currently do not use respectively never tried out:

final processResult = await Process.run(executable, arguments);

Btw, Google provides its own Dart package for picking files on Linux, macOS, and Windows. Maybe you will have more luck with their professional C++ implementation (our script-based approach has many weaknesses):
https://github.com/google/flutter-desktop-embedding/tree/master/plugins/file_selector

@github-actions
Copy link

This issue is stale because it has been open for 14 days with no activity.

@github-actions github-actions bot added the stale label Dec 26, 2021
@jlnrrg
Copy link
Author

jlnrrg commented Dec 28, 2021

I decided to deinstall the qarma as it had the above mentioned permission issues and rather focus on the zenity issue as this comes preinstalled with ubuntu.
So after the deinstall I driggered this command: await Process.run("/usr/bin/zenity", [file-selection","--title","Test"]);, which again resulted in the exitCode: -11 😞

I will now play around with Process.run() and list my progress here:

  • Process.runSync('zenit', ['--file-selection']); -11
  • Process.run('zenit', ['--file-selection']); -11
  • Process.run('yad', ['--file-selection']); -11

Edit:
I think this is caused by an deeper issue of rights on linux. I researched a little bit and I think it might be this, as also qarma had no permissions:

Segment Violation Access Error (SEGV_ACCERR): Accessing memory where the application has no permission or trying to write on read-only memory space

So now I will rather research how dart Process.run can get the needed rights 🙏

Edit 2:
When using Process.run('zenity', ['--file-selection'], runInShell: true);
the exitCode: 139 is in the result with stderr: Segmentation fault (core dumped) which solidifies my assumption

@github-actions github-actions bot removed the stale label Dec 29, 2021
@jlnrrg
Copy link
Author

jlnrrg commented Dec 29, 2021

Good news first:
As it seems to be a permission issue, I tought about actually building the app and starting it (not using the debugger) and boom. Everything works as intended.

So the issue seems to lay in the flutter debugger not getting the same rights as to the real app.
I'll investigate this.

Edit 1:
It also works with the terminal command flutter run.
But not with the following vscode launch.json:

launch.json
{
    "version": "0.2.0",
    "configurations": [
        {
            "name": "start",
            "request": "launch",
            "type": "dart"
        },
    ]
}

@jlnrrg
Copy link
Author

jlnrrg commented Dec 29, 2021

The issue was most likely the usage of the snap vscode, bc when I installed the non-snap vscode everything worked as intended.
Thank you for your ongoing support 😄.
With this my issue is resolved and I hope this will also help someone in the futute.

@jlnrrg jlnrrg closed this as completed Dec 29, 2021
@philenius philenius added the fixed Issue has been addressed and already been deployed or waiting to deploy on master. label Dec 29, 2021
@philenius
Copy link
Collaborator

@jlnrrg thank you keeping us up to date on your investigations and for posting the solution 👍

@samuelpismel
Copy link

I was having the same problem here.
I lost some time to find this answer.
Would be nice to have this info in the wiki or readme.

Great lib btw 😄

Thanks guys

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. fixed Issue has been addressed and already been deployed or waiting to deploy on master. new issue An issue that hasn't yet been seen from the maintainer
Projects
None yet
Development

No branches or pull requests

3 participants