如何将我的Electron应用程序设为打开文件的默认设置? [英] How do I make my Electron app the default for opening files?
问题描述
我正在制作一个电子应用程序,用户可以用它来编辑.txt文件。我想知道是否有可能将应用程序设置为默认应用程序,以使用...打开.txt文件?我可以在packge.json中添加一些内容吗?我该如何处理文件?我知道这个问题有点笼统,但我在文档中找不到任何内容,因此,如果可以向正确的方向指出那将是个好消息。
I am making an electron app with which the user can edit .txt files. I was wondering if it was possible to make the app the default app to open .txt files with... do I add something to the packge.json? How do I handle the file? I know this question is sort of broad but I can not find anything in the docs so if I could be pointed in the right direction that would be great.
其他信息:
包装:使用电子制造器进行包装
Packaging: packaging with electron builder
节点:v12.14.1
Node: v12.14.1
npm:6.14.1
npm: 6.14.1
电子:9.0.4
推荐答案
您需要查看 electron-builder 配置,特别是 fileAssociations 。
You'll want to look at the electron-builder config, specifically fileAssociations.
果壳:
fileAssociations
允许设置 ext
设置为 txt
IIRC。您还可以提供一个描述性的名称
,为其提供图标,以及几个特定于平台的选项。
fileAssociations
allows setting ext
, which you'd set to txt
IIRC. You can also provide a descriptive name
, give it icons, and several platform-specific options.
不相关,但这花了大约一分钟的时间。供参考:
Unrelated, but this took about a minute of searching. For reference:
- Googled搜索电子应用将默认打开文件类型
- 找到了一个看似有希望的电子问题。
- 滚动到对电子制造器的引用,很符合您的问题。
- 在链接上单击了单击,确保它是合理的。
- 未测试,因为使用了错误的笔记本电脑,但似乎合法。
- Googled for "electron app make default for opening a type of files"
- Found an Electron issue that looked promising.
- Scrolled to a reference to electron-builder, which fit your question nicely.
- Made clicky on the links, made sure it was reasonable.
- Didn't test because on wrong laptop, but seems legit.
这篇关于如何将我的Electron应用程序设为打开文件的默认设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!