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

kro*_*ama 8 javascript installation file-association electron squirrel.windows

我已经将以下代码段添加到我的package.json

"build": {
  "fileAssociations": [
    {
      "ext": "asdf",
      "name": "ASDF File",
      "role": "Editor"
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

但是生成的安装程序不会将我的应用程序分配给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
Run Code Online (Sandbox Code Playgroud)

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

小智 6

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

"build": {
  "fileAssociations": [
    {
      "ext": "asdf",
      "name": "ASDF File",
      "role": "Editor",
      "perMachine": true
    }
  ]
}
Run Code Online (Sandbox Code Playgroud)

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