Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 305
kroegerama Avatar asked Nov 29 '18 08:11

kroegerama


People also ask

How do I associate a file extension with an application?

In the Control Panel, click the Default Programs option. Click the Associate a file type or protocol with a program option. In the Default apps window, scroll to the bottom and select Choose defaults by file type. Find the file type that interests you.

How do you package an Electron app into a single executable?

It's impossible to create a single executable file of an electron application. The application's source code is available to anyone. No ways to protect the application's assets (scripts, images, etc.) No ways to set the executable file icon.

How is Electron cross-platform?

Electron is a framework that allows you to develop native cross-platform desktop applications based on HTML, JavaScript and CSS. It uses Chromium to render the content and Node. js to access the local file system and the operating system. That allows you to create a Windows or Mac application with local file access.

How do I distribute the Electron app in Windows?

To distribute your app manually, you need to download Electron's prebuilt binaries. Next, the folder containing your app should be named app and placed in Electron's resources directory as shown in the following examples. The location of Electron's prebuilt binaries is indicated with electron/ in the examples below.


2 Answers

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.

like image 58
Steeve Avatar answered Oct 20 '22 06:10

Steeve


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

like image 1
2BC.Wasabi Avatar answered Oct 20 '22 06:10

2BC.Wasabi