Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
354 views
in Technique[技术] by (71.8m points)

electron-builder snap installer confusing home directory

This is a follow up of the previous question Defult home directory for snap installer using electron-builder, asked as requested there.

I'm currently building a electron app an building the installer like .deb and .snap with electron-builder. My app uses showSaveDialog/showOpenDialog to open/save file that opens up a nautilus (in ubuntu) like file explorer. Now if the app is installed using the .snap installer, the Home tab in the explorer pop-up points to the /home/user/snap/<app>/<revision>/ as can be seen in the picture below, not the actual directory we usually call home in linux (/home/username/). As the Home in this pop-up explorer window is not the actual user's home directory, it's getting confusing for users.
Is there a way to fix this?

enter image description here

question from:https://stackoverflow.com/questions/65872077/electron-builder-snap-installer-confusing-home-directory

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...