电子生成器快照安装程序使主目录混乱 [英] electron-builder snap installer confusing home directory

查看:61
本文介绍了电子生成器快照安装程序使主目录混乱的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是上一个问题的后续操作

解决方案

这似乎是一个常见的问题,当在快照限制中运行时,基于GTK的打开/保存对话框就会出现.

网络上散布了以下错误报告:

上面最后一个链接中的评论者建议设置$ G_HOME环境变量.

您可以覆盖此变量以影响文件选择器,但是您需要尽早进行操作.在我的测试中,它需要在应用就绪事件之前完成:

  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);//应该打印您的实际主目录dialog.showOpenDialogSync();}); 

请您自担风险;此更改可能还会有其他潜在的不良影响.我没有在快速限制下运行此程序,但是能够更改文件选择器用于主目录"的目录.项.

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?

解决方案

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.

这篇关于电子生成器快照安装程序使主目录混乱的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆