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

2

11

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.

Unbroken answered 29/11, 2018 at 8:56 Comment(0)
G
9

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.

Genteelism answered 29/11, 2018 at 11:38 Comment(2)
Works fine. Also, I had to use the .msi installer.Unbroken
for anyone else, this config might also be in an external json file if using the --config flagAvigation
W
2

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

Waldron answered 16/5, 2022 at 15:34 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.