如何将文件扩展名关联到电子应用程序(多平台)

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

我已经将以下片段添加到我的 package.json:

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

但是生成的安装程序没有将我的应用程序分配给 asdf 扩展。 (在 Windows 10 上测试)

我也查了一下,如何编辑setupEvents.js文件。它包含以下部分:

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

但是我找不到一个例子,如何实现注册表写入部分。

添加"perMachine": true,选项,例如:

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

之所以需要它,是因为在 Windows 上,每个用户安装的程序无法注册文件关联,这是默认设置。

看来新版本需要这样设置

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

有更多关于其他文件关联设置的信息here