Search code examples
javascriptinstallationelectronfile-associationsquirrel.windows

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


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.


Solution

  • 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.