Windows: register protocol handler for magnet links

This commit is contained in:
Feross Aboukhadijeh
2016-03-19 18:32:58 -07:00
parent 381087208c
commit 2cc8ebc9f8
3 changed files with 33 additions and 3 deletions

View File

@@ -0,0 +1,26 @@
module.exports = function () {
if (process.platform === 'win32') {
registerProtocolHandler('magnet', 'URL:BitTorrent Magnet URL', 'WebTorrent.exe')
}
}
function registerProtocolHandler (protocol, name, command) {
var Registry = require('winreg')
var protocolKey = new Registry({
hive: Registry.HKCR, // HKEY_CLASSES_ROOT
key: '\\' + protocol
})
protocolKey.set('', Registry.REG_SZ, name, callback)
protocolKey.set('URL Protocol', Registry.REG_SZ, '', callback)
var commandKey = new Registry({
hive: Registry.HKCR,
key: '\\' + protocol + '\\shell\\open\\command'
})
commandKey.set('', Registry.REG_SZ, '"' + command + '" "%1"', callback)
function callback (err) {
if (err) console.error(err.message || err)
}
}