From fb37b87297aa8a200e87b688bb1ec955051f2eba Mon Sep 17 00:00:00 2001 From: Feross Aboukhadijeh Date: Sun, 20 Mar 2016 00:52:54 -0700 Subject: [PATCH] set windows protocol/file icons --- main/register-protocol-handler.js | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/main/register-protocol-handler.js b/main/register-protocol-handler.js index e84587c7..9b46f6b1 100644 --- a/main/register-protocol-handler.js +++ b/main/register-protocol-handler.js @@ -1,7 +1,9 @@ +var config = require('../config') + module.exports = function () { if (process.platform === 'win32') { - registerProtocolHandler('magnet', 'BitTorrent Magnet URL', process.execPath) - registerFileHandler('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', process.execPath) + registerProtocolHandler('magnet', 'BitTorrent Magnet URL', config.APP_FILE_ICON + '.ico', process.execPath) + registerFileHandler('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', config.APP_FILE_ICON + '.ico', process.execPath) } } @@ -25,7 +27,7 @@ module.exports = function () { * "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users. */ -function registerProtocolHandler (protocol, name, command) { +function registerProtocolHandler (protocol, name, icon, command) { var Registry = require('winreg') var protocolKey = new Registry({ @@ -35,6 +37,12 @@ function registerProtocolHandler (protocol, name, command) { protocolKey.set('', Registry.REG_SZ, 'URL:' + name, callback) protocolKey.set('URL Protocol', Registry.REG_SZ, '', callback) + var iconKey = new Registry({ + hive: Registry.HKCU, + key: '\\Software\\Classes\\' + protocol + '\\DefaultIcon' + }) + iconKey.set('', Registry.REG_SZ, icon, callback) + var commandKey = new Registry({ hive: Registry.HKCU, key: '\\Software\\Classes\\' + protocol + '\\shell\\open\\command' @@ -46,7 +54,7 @@ function registerProtocolHandler (protocol, name, command) { } } -function registerFileHandler (ext, id, name, command) { +function registerFileHandler (ext, id, name, icon, command) { var Registry = require('winreg') var extKey = new Registry({ @@ -61,6 +69,12 @@ function registerFileHandler (ext, id, name, command) { }) idKey.set('', Registry.REG_SZ, name, callback) + var iconKey = new Registry({ + hive: Registry.HKCU, + key: '\\Software\\Classes\\' + id + '\\DefaultIcon' + }) + iconKey.set('', Registry.REG_SZ, icon, callback) + var commandKey = new Registry({ hive: Registry.HKCU, key: '\\Software\\Classes\\' + id + '\\shell\\open\\command'