This seems to be a common problem that the GTK-based open/save dialogs have when run in the snap confinement.
There are the following bug reports sprinkled around the web:
A commenter in the last link above suggested to set the $G_HOME environment variable.
You can override this variable to affect the file chooser, but you'll need to do it early. In my test, it needs to be done before the app-ready event:
const os = require("os");
process.env.G_HOME = os.userInfo().homedir;
const {app, dialog} = require("electron");
app.on("ready", function() {
console.log(process.env.G_HOME); // should print your actual home directory
dialog.showOpenDialogSync();
});
Do this at your own risk; it is possible that there are other, potentially undesired effects of this change.
I did not run this under snap confinement, but was able to change the directory the file chooser uses for the "Home" entry.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…