Skip to content

[Bug]: File dialog overwrites the file manager's "Show hidden files" setting in Linux/GNOME #34706

Closed

Description

@akilangh

Preflight Checklist

Electron Version

17.4.7

What operating system are you using?

Ubuntu

Operating System Version

Ubuntu 20.04 ( Linux x64 5.13.0-41-generic )

What arch are you using?

x64

Last Known Working Electron version

No response

Expected Behavior

When an Electron based app presents a file open dialog, it should respect the desktop system-wide settings related to visibility of hidden files.

Actual Behavior

Try this on VS Code on GNOME:

  • Enable "Show hidden files" in Nautilus.
  • Open VS Code's file dialog (for example via Ctrl+O). The hidden files in nautilus will be hidden again

Testcase Gist URL

No response

Additional Information

There is an open bug report for VS Code on this: microsoft/vscode#107246

This issue is present in both KDE and GNOME but it affects GNOME users in a worse way because of a design decision made by GNOME. See microsoft/vscode#151153 for more info on that.

Thanks for looking into this.

Activity

  1. akilangh commented on Jun 22, 2022

    @akilangh
    Author

    There is an Atom bug report too (closed since due to lack of activity): atom/atom#20712

  2. mlaurencin commented on Jun 29, 2022

    @mlaurencin
    Member

    Thanks for reporting this and helping to make Electron better!

    Because of time constraints, triaging code with third-party dependencies is usually not feasible for a small team like Electron's.

    Would it be possible for you to make a standalone testcase with only the code necessary to reproduce the issue? For example, Electron Fiddle is a great tool for making small test cases and makes it easy to publish your test case to a gist that Electron maintainers can use.

    Stand-alone test cases make fixing issues go more smoothly: it ensure everyone's looking at the same issue, it removes all unnecessary variables from the equation, and it can also provide the basis for automated regression tests.

    I'm adding the blocked/need-repro label for this reason. After you make a test case, please link to it in a follow-up comment.

    Thanks in advance! Your help is appreciated.

  3. added
    blocked/need-repro
    on Jun 29, 2022
  4. akilangh commented on Aug 2, 2022

    @akilangh
    Author

    @mlaurencin I downloaded Electron Fiddle to see if I can write something small to demo this and noticed something interesting. Fiddle itself suffers from this bug. Since it is Electron's tool I suppose you will be able to reproduce the bug and examine fiddle's code to see where the issue is? I'm copying the steps to reproduce for easy access:

    Steps to Reproduce:

    • Go to Files (Nautilus) and make sure you can see hidden files (dotfiles) by checking the checkbox under Hamburger Menu -> Show Hidden Files.
    • Go to Fiddle
    • From menu choose File -> Open...
    • Open a file or click cancel.
    • Go to Files (Nautilus). You can no longer see hidden files. The checkbox under Hamburger Menu -> Show Hidden Files is now unchecked.
  5. akilangh commented on Aug 2, 2022

    @akilangh
    Author

    I take it that Fiddle itself is written using Electron?

  6. akilangh commented on Aug 11, 2022

    @akilangh
    Author

    Hi, do you need anything else from me?

  7. BlackHole1 commented on Aug 16, 2022

    @BlackHole1
    Member

    I think this is a relatively simple fix, we need to restore the initial values after the dialog is closed (use gtk_file_chooser_get_show_hidden to get the current value). Or we should check if GTK has an API that only affects the current dialog, not the global state.

    See:

    gtk_file_chooser_set_show_hidden(file_chooser,
    hasProp(OPEN_DIALOG_SHOW_HIDDEN_FILES));

    gtk_file_chooser_set_show_hidden(file_chooser,
    hasProp(SAVE_DIALOG_SHOW_HIDDEN_FILES));

    @mlaurencin Please set assignees to me.

  8. akilangh commented on Aug 16, 2022

    @akilangh
    Author

    @BlackHole1 Thank you so much. Electron resets the hidden file visibility under KDE too but KDE takes an intelligent approach and changes it only for Electron's file dialog and not anywhere else. I will submit a PR to make Electron obey default desktop settings in KDE too.

  9. akilangh commented on Aug 16, 2022

    @akilangh
    Author

    we need to restore the initial values after the dialog is closed ... Or we should check if GTK has an API that only affects the current dialog

    @BlackHole1 Ideally Electron should not set that value even for its own dialog. User has set a default value in their desktop and Electron should obey that default value. If user needs a different value then user would take appropriate action. That has been my general experience with the apps that I use.

  10. BlackHole1 commented on Aug 16, 2022

    @BlackHole1
    Member

    Electron resets the hidden file visibility under KDE too

    This should be the expected behavior, since we have showHiddenFiles, see: https://www.electronjs.org/zh/docs/latest/api/dialog#dialogshowopendialogsyncbrowserwindow-options
    It might be better to inherit the value of the current system hiddenFiles if showHiddenFiles is not passed in. e.g.

    Pseudocode:

    gtk_file_chooser_set_show_hidden(file_chooser,
      hasProp(SAVE_DIALOG_SHOW_HIDDEN_FILES) ||  gtk_file_chooser_get_show_hidden(file_chooser))

    KDE takes an intelligent approach and changes it only for Electron's file dialog and not anywhere else.

    This may not be realistic, and based on my investigation today, I've learned that it was intentional. See:

    // GtkFileChooserNative does not support preview widgets through the
    // org.freedesktop.portal.FileChooser portal. In the case of running through
    // the org.freedesktop.portal.FileChooser portal, anything having to do with
    // the update-preview signal or the preview widget will just be ignored.

    Sounds like you want to submit a PR for this bug, if so, you're more than welcome to do so! (I'll briefly describe my local fix below, which may help you)

    #include <gio/gio.h>
    #include <gio/gsettings.h>
    
    // In private:
    gboolean show_hidden_files_;
    
    // In void FileChooserDialog::OnFileDialogResponse
    // TODO: use `g_settings_schema_source_lookup` check `org.gtk.Settings.FileChooser` exist.
    GSettings *settings = g_object_new("org.gtk.Settings.FileChooser");
    show_hidden_files_ = g_settings_get_boolean(settings, "show_hidden");
    
    // In ~FileChooserDialog()
    // TODO: use `g_settings_schema_source_lookup` check `org.gtk.Settings.FileChooser` exist.
    GSettings *settings = g_object_new("org.gtk.Settings.FileChooser");
    g_settings_set_boolean(settings, "show_hidden", show_hidden_files_);

    Inspired by:

    1. https://github.com/GNOME/nautilus/blob/5d7d285d98e717a1bebb965d9c7ef809f69d3db1/src/nautilus-files-view.c#L2613-L2639

    image

    1. https://github.com/GNOME/nautilus/blob/6af38c29d23deb6be571f560cc33740f6ac6348c/src/nautilus-global-preferences.c#L61-L63

    image

    1. https://github.com/GNOME/nautilus/blob/0c1f2fe55300b0f81b323191ecc56c3250a5c1e4/src/nautilus-global-preferences.h#L31-L32

    image


    The fix code above is only the initial version, and if you are willing to submit a PR for this, I will forgo continuing to optimize this fix and cancel my intention to submit a PR.

    If you want to submit a PR, my suggestion is to use: https://github.com/electron/build-tools . This tool will allow you to quickly build electron locally

  11. akilangh commented on Aug 16, 2022

    @akilangh
    Author

    I will take a look and submit a PR in few days. Thank you!

  12. added
    status/confirmed
    and removed
    blocked/need-repro
    on Aug 29, 2022
  13. ckerr commented on Aug 29, 2022

    @ckerr
    Member

    Confirmed. Looks like every time a GtkFileChooserDefault is unmapped, its settings get saved for next time, e.g. so the system can remember the window position and size of the dialog.

    The patch by @BlackHole1 in #34706 (comment) looks like it would solve the immediate problem of not clobbering the show-hidden system setting and would be a good candidate for backporting into the currently-supported versions of Electron. @akilan27 could you give some more information on how the KDE desktop does it differently? Is there something we'd want to do differently from this patch?

    Ideally Electron should not set that value even for its own dialog. User has set a default value in their desktop and Electron should obey that default value.

    This would be a little better for native integration on Linux, but it will take some work and probably be a semver major change because we'll need to change the Dialog API. The current implementation (in setupOpenPropertiesDialog() in lib/browser/api/dialog.ts) holds bitwise or'ed flags of Dialog.showOpenDialog's options.properties, so in Electron right now the default is all the features in options.properties are off by default and get enabled by explicitly opting in.

    To change this:

    • We'd need some new C++ code to init the default value from the system preferences, and use that code in setupOpenPropertiesDialog().
    • We'd need to change the public API from 'opt in' to 'override system setting', e.g. under the current API there would be no way in the API to hide hidden files if the system preference is to show them.
  14. 14 remaining items

  15. misaki-web commented on Mar 10, 2023

    @misaki-web

    Despite it might work (if you have the xdg-desktop-portal package installed -you might have it installed if using Flatpak or Snap-), I doubt it is a good solution.

    I agree. It's a quick workaround until an official fix is released, but in the meanwhile, it can be quite useful.

    More on this, looks like GTK_USE_PORTAL env var has been replaced with GDK_DEBUG (see: https://gitlab.gnome.org/GNOME/gtk/-/merge_requests/4829)

    Yes. The change occurred in GTK 4.7.1, but not in GTK 3.

    The workaround could use both variables as follows (example with VSCode; note that it must be run after each software update):

    file='/usr/share/applications/code.desktop'
    workaround='env GDK_DEBUG=portals GTK_USE_PORTAL=1 '
    grep -q "^Exec=$workaround" "$file" || sudo sed -i "s/^Exec=/Exec=$workaround/g" "$file"
  16. github-actions commented on Jun 9, 2023

    @github-actions
    Contributor

    This issue has been automatically marked as stale. If this issue is still affecting you, please leave any comment (for example, "bump"), and we'll keep it open. If you have any new additional information—in particular, if this is still reproducible in the latest version of Electron or in the beta—please include it with your comment!

  17. rubensa commented on Jun 9, 2023

    @rubensa

    bump

  18. codebytere commented on Jul 15, 2024

    @codebytere
    Member

    Does this still happen? #42045 might have addressed this!

  19. added
    blocked/need-info ❌
    on Jul 15, 2024
  20. rubensa commented on Jul 16, 2024

    @rubensa

    Just checked and looks like env GTK_USE_PORTAL=1 is not needed anymore.

    Thanks @codebytere

  21. codebytere commented on Jul 16, 2024

    @codebytere
    Member

    @rubensa delightful - i'll close this out but ping if something new arises and i'll take a fresh look :)

  22. Openstreetmapler commented on Nov 19, 2024

    @Openstreetmapler

    Several months after the issue has been closed, I’m somehow still affected …

    • VSCodium 1.95.3 Release 24321
    • Electron 32.2.5
    • Ubuntu 22.04
  23. removed
    blocked/need-info ❌
    on Nov 19, 2024
  24. rubensa commented on Nov 19, 2024

    @rubensa

    Same here.

    The problem appeared again.

    I'm on:

    • VSCode 1.95.3
    • Electron 32.2.1
    • Ubuntu 22.04.5 LTS
  25. rubensa commented on Nov 19, 2024

    @rubensa

    Sadly this time the env GDK_DEBUG=portals GTK_USE_PORTAL=1 workaround doesn't work anymore.

  26. zonescape commented on Feb 28, 2025

    @zonescape
    Contributor

    @codebytere please reopen the bug. It still exists in VSCode.

    Version: 1.97.2
    Commit: e54c774e0add60467559eb0d1e229c6452cf8447
    Date: 2025-02-12T23:20:35.343Z
    Electron: 32.2.7
    ElectronBuildId: 10982180
    Chromium: 128.0.6613.186
    Node.js: 20.18.1
    V8: 12.8.374.38-electron.0
    OS: Linux x64 6.8.0-52-generic

    I think the steps to reproduce in the bug description are not very clear. I think this description is easier to understand:

    • Make hidden files displayed in the GTK file chooser:
    $ dconf write /org/gtk/settings/file-chooser/show-hidden true
    $ dconf read /org/gtk/settings/file-chooser/show-hidden
    true
    
    • Open VSCode. Hidden files are still set to be displayed:
    $ code
    $ dconf read /org/gtk/settings/file-chooser/show-hidden
    true
    
    • In VSCode, go to File > Open File. Hidden files in the file chooser are not displayed, but settings have not been updated yet:
    $ dconf read /org/gtk/settings/file-chooser/show-hidden
    true
    
    • Close the "Open File" popup. Even if we don't choose a file and click on "Cancel", settings were updated by VSCode:
    $ dconf read /org/gtk/settings/file-chooser/show-hidden
    false
    

    So the bug is that VSCode's file chooser doesn't read "show hidden files" property and always sets it to false on close.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

bug 🪲component/dialogplatform/linuxstatus/confirmed

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions