From 29138fc83c34c2af377d9499420db5a1d0cd71e7 Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sat, 19 Mar 2016 20:29:44 -0700 Subject: [PATCH] add documentation for registerProtocolHandler --- main/register-protocol-handler.js | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/main/register-protocol-handler.js b/main/register-protocol-handler.js index 22a20c5b..6e43a03e 100644 --- a/main/register-protocol-handler.js +++ b/main/register-protocol-handler.js @@ -1,9 +1,29 @@ module.exports = function () { if (process.platform === 'win32') { - registerProtocolHandler('magnet', 'URL:BitTorrent Magnet URL', process.execPath) + registerProtocolHandler('magnet', 'BitTorrent Magnet URL', process.execPath) } } +/** + * To add a protocol handler on Windows, the following keys must be added to the Windows + * registry: + * + * HKEY_CLASSES_ROOT + * $PROTOCOL + * (Default) = "URL:$NAME" + * URL Protocol = "" + * shell + * open + * command + * (Default) = "$COMMAND" "%1" + * + * Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx + * + * However, the "HKEY_CLASSES_ROOT" key can only be written by the Administrator user. + * So, we instead write to "HKEY_CURRENT_USER\Software\Classes", which is inherited by + * "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users. + */ + function registerProtocolHandler (protocol, name, command) { var Registry = require('winreg') @@ -11,7 +31,7 @@ function registerProtocolHandler (protocol, name, command) { hive: Registry.HKCU, // HKEY_CURRENT_USER key: '\\Software\\Classes\\' + protocol }) - protocolKey.set('', Registry.REG_SZ, name, callback) + protocolKey.set('', Registry.REG_SZ, 'URL:' + name, callback) protocolKey.set('URL Protocol', Registry.REG_SZ, '', callback) var commandKey = new Registry({