You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
[Bug]: File dialog overwrites the file manager's "Show hidden files" setting in Linux/GNOME #34706
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.
Reacted by Mike Jerred, zakutin, codestothestars, Ronnie Dutta and Jonathan Hefner
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.
@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.
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.
@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.
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.
// 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_);
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.
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.
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.
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!
Activity
akilangh commentedon Jun 22, 2022
There is an Atom bug report too (closed since due to lack of activity): atom/atom#20712
mlaurencin commentedon Jun 29, 2022
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-reprolabel 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.
akilangh commentedon Aug 2, 2022
@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:
akilangh commentedon Aug 2, 2022
I take it that Fiddle itself is written using Electron?
akilangh commentedon Aug 11, 2022
Hi, do you need anything else from me?
BlackHole1 commentedon Aug 16, 2022
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_hiddento get the current value). Or we should check ifGTKhas an API that only affects the current dialog, not the global state.See:
electron/shell/browser/ui/file_dialog_gtk.cc
Lines 227 to 228 in c4ea33d
electron/shell/browser/ui/file_dialog_gtk.cc
Lines 236 to 237 in c4ea33d
@mlaurencin Please set assignees to me.akilangh commentedon Aug 16, 2022
@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.
akilangh commentedon Aug 16, 2022
@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.
BlackHole1 commentedon Aug 16, 2022
This should be the expected behavior, since we have
showHiddenFiles, see: https://www.electronjs.org/zh/docs/latest/api/dialog#dialogshowopendialogsyncbrowserwindow-optionsIt might be better to inherit the value of the current system hiddenFiles if showHiddenFiles is not passed in. e.g.
Pseudocode:
This may not be realistic, and based on my investigation today, I've learned that it was intentional. See:
electron/shell/browser/ui/file_dialog_gtk.cc
Lines 193 to 196 in c4ea33d
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)
Inspired by:
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
akilangh commentedon Aug 16, 2022
I will take a look and submit a PR in few days. Thank you!
ckerr commentedon Aug 29, 2022
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-hiddensystem 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?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()inlib/browser/api/dialog.ts) holds bitwise or'ed flags of Dialog.showOpenDialog'soptions.properties, so in Electron right now the default is all the features inoptions.propertiesare off by default and get enabled by explicitly opting in.To change this:
setupOpenPropertiesDialog().14 remaining items
misaki-web commentedon Mar 10, 2023
I agree. It's a quick workaround until an official fix is released, but in the meanwhile, it can be quite useful.
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):
github-actions commentedon Jun 9, 2023
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!
rubensa commentedon Jun 9, 2023
bump
codebytere commentedon Jul 15, 2024
Does this still happen? #42045 might have addressed this!
rubensa commentedon Jul 16, 2024
Just checked and looks like
env GTK_USE_PORTAL=1is not needed anymore.Thanks @codebytere
codebytere commentedon Jul 16, 2024
@rubensa delightful - i'll close this out but ping if something new arises and i'll take a fresh look :)
Openstreetmapler commentedon Nov 19, 2024
Several months after the issue has been closed, I’m somehow still affected …
rubensa commentedon Nov 19, 2024
Same here.
The problem appeared again.
I'm on:
rubensa commentedon Nov 19, 2024
Sadly this time the
env GDK_DEBUG=portals GTK_USE_PORTAL=1workaround doesn't work anymore.zonescape commentedon Feb 28, 2025
@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:
So the bug is that VSCode's file chooser doesn't read "show hidden files" property and always sets it to false on close.