How to associate a file extension to an electron app (multiplatform)

6.4k views Asked by At

I already added the following snippet to my package.json:

"build": {
  "fileAssociations": [
    {
      "ext": "asdf",
      "name": "ASDF File",
      "role": "Editor"
    }
  ]
}

But the generated installer does not assign my application to the asdf extension. (tested on Windows 10)

I also looked up, how to edit the setupEvents.js file. It contains the following part:

case '--squirrel-updated':
 // Optionally do things such as:
 // - Add your .exe to the PATH
 // - Write to the registry for things like file associations and
 // explorer context menus

But I could not find a single example, how to archieve the registry writing part.

2

There are 2 answers

2
Steeve On BEST ANSWER

Add the "perMachine": true, option, e.g.:

"build": {
  "fileAssociations": [
    {
      "ext": "asdf",
      "name": "ASDF File",
      "role": "Editor",
      "perMachine": true
    }
  ]
}

The reason it is needed, is because on Windows, per-user installed program cannot register file associations, and that is the default setting.

0
2BC.Wasabi On

It seems that with the newer version you need to set it like this

"build": {
   "fileAssociations": [{
     "ext": "ext1",
     "name": "ext1 File",
     "role": "Editor"
   },
   {
     "ext": "ext2",
     "name": "ext2File",
     "role": "Editor"
   }
   ],
   "nsis": {
     //othersettings,
     "perMachine": true
   }
}

there is more information about other file association settings here