Cross platform 'Open with myApp' context menu entry in electron apps?


#1

I’ve spent days looking for anything on how to register my electron app in operating system’s context menu registry. So that when user right clicks on a folder, they get to choose ‘Open with myApp’ option.

Like in this image

How can I accomplish this?

Thanks


Right-click menu is that possible?
Right-click menu is that possible?
#2

It looks like Atom handles that through Squirrel.


#3

Thanks, but any actual documentation on how to actually get it to work?


#4

Not as far as I can tell. @leedohm, do you know where or to whom to look for this information?


#5

Looks like it was done in this PR:


#6

Would @paulcbetts, @damieng, or someone else savvy be willing to write a brief primer to distill the process of setting up an update script like squirrel-update.coffee? The process is tough for an outsider to disentangle and I’ve looked at the documentation in both the Squirrel.Mac and Squirrel.Windows repos and can’t find anything about using the capabilities of Squirrel outside of purely downloading the latest version in the background (or even a complete list of what those capabilities are).


#7

Hi there.

Squirrel only really provides a hook - it basically passes a flag to you app telling you if you are being installed, upgraded or uninstalled so you can do what you need to do.

What you actually do is entirely up to you and just performed as regular node code in your app.

In the case of adding “Open with X” - there are two options:

  1. Add a file handler so people can associate your app with the files they like. This doesn’t quite appear as in your screenshot but rather appears as “Open with…” and then includes your app in the next dialog. People seem to like this.

  2. Add an item to the Windows context menu that is always visible. This is what your screenshot shows and we used to do this by default but now it is optional because of complaints.

Either way you need to add items to the registry on install (and upgrade if your path changes) and remove them properly on uninstall.

The exact registry entries and details of how Atom does all of this can be found in our win-shell.js file at https://github.com/atom/atom/blob/master/src/main-process/win-shell.js and requires the ‘winreg’ npm package to actually perform the registry operations.

exports.fileHandler is the open with … one (option 1)
exports.fileContextMenu is option 2 for all files on your system
exports.folderContextMenu is option 2 for all folders on your system
exports.folderBackgroundContextMenu is option 2 when you right-click inside a folder not on any specific file

The ShellOption class wraps up the testing/installing/uninstalling logic for you so you can just modify the appName, appPath and fileIcon bits you need.

Check out https://github.com/atom/settings-view/blob/master/lib/system-windows-panel.coffee to see how you can find out if the registry is set, remove the setting or add the setting from a ui etc.

Hope that helps!


#8

Many thanks to all for the help.

Special thanks to @DamnedScholar for dedication to the topic, never seen before. :slight_smile:


#9

I need Add share button here how I can able to Add?


#10

It’s been answered already… Look here Cross platform ‘Open with myApp’ context menu entry in electron apps?