Alex Hawking
Alex Hawking

Reputation: 1245

How do I make my Electron app the default for opening files?

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.

Other info:

Packaging: packaging with electron builder

Node: v12.14.1

npm: 6.14.1

Electron: 9.0.4

Upvotes: 0

Views: 1786

Answers (1)

Dave Newton
Dave Newton

Reputation: 160170

You'll want to look at the electron-builder config, specifically fileAssociations.

Nutshell:

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:

  1. Googled for "electron app make default for opening a type of files"
  2. Found an Electron issue that looked promising.
  3. Scrolled to a reference to electron-builder, which fit your question nicely.
  4. Made clicky on the links, made sure it was reasonable.
  5. Didn't test because on wrong laptop, but seems legit.

Upvotes: 1

Related Questions