Merge pull request #174 from feross/linux-handler
Linux: Register .torrent file/magnet link handlers
This commit is contained in:
14
config.js
14
config.js
@@ -3,8 +3,8 @@ var path = require('path')
|
|||||||
|
|
||||||
module.exports = {
|
module.exports = {
|
||||||
APP_COPYRIGHT: 'Copyright © 2014-2016 The WebTorrent Project',
|
APP_COPYRIGHT: 'Copyright © 2014-2016 The WebTorrent Project',
|
||||||
APP_FILE_ICON: path.join(pathToStatic(), 'WebTorrentFile'),
|
APP_FILE_ICON: path.join(__dirname, 'static', 'WebTorrentFile'),
|
||||||
APP_ICON: path.join(pathToStatic(), 'WebTorrent'),
|
APP_ICON: path.join(__dirname, 'static', 'WebTorrent'),
|
||||||
APP_NAME: 'WebTorrent',
|
APP_NAME: 'WebTorrent',
|
||||||
|
|
||||||
CONFIG_PATH: applicationConfigPath('WebTorrent'),
|
CONFIG_PATH: applicationConfigPath('WebTorrent'),
|
||||||
@@ -15,6 +15,8 @@ module.exports = {
|
|||||||
|
|
||||||
IS_PRODUCTION: isProduction(),
|
IS_PRODUCTION: isProduction(),
|
||||||
|
|
||||||
|
STATIC_PATH: path.join(__dirname, 'static'),
|
||||||
|
|
||||||
SOUND_ADD: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'),
|
SOUND_ADD: 'file://' + path.join(__dirname, 'static', 'sound', 'add.wav'),
|
||||||
SOUND_DELETE: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'),
|
SOUND_DELETE: 'file://' + path.join(__dirname, 'static', 'sound', 'delete.wav'),
|
||||||
SOUND_DISABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'),
|
SOUND_DISABLE: 'file://' + path.join(__dirname, 'static', 'sound', 'disable.wav'),
|
||||||
@@ -36,12 +38,6 @@ function isProduction () {
|
|||||||
return !/\\electron\.exe$/.test(process.execPath)
|
return !/\\electron\.exe$/.test(process.execPath)
|
||||||
}
|
}
|
||||||
if (process.platform === 'linux') {
|
if (process.platform === 'linux') {
|
||||||
// TODO
|
return !/\/electron$/.test(process.execPath)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function pathToStatic () {
|
|
||||||
return isProduction()
|
|
||||||
? path.join(process.resourcesPath, 'app.asar.unpacked', 'static')
|
|
||||||
: path.join(__dirname, 'static')
|
|
||||||
}
|
|
||||||
|
|||||||
@@ -5,7 +5,7 @@ var app = electron.app
|
|||||||
var config = require('../config')
|
var config = require('../config')
|
||||||
var ipc = require('./ipc')
|
var ipc = require('./ipc')
|
||||||
var menu = require('./menu')
|
var menu = require('./menu')
|
||||||
var registerProtocolHandler = require('./register-protocol-handler')
|
var registerProtocolHandler = require('./register-handlers')
|
||||||
var shortcuts = require('./shortcuts')
|
var shortcuts = require('./shortcuts')
|
||||||
var windows = require('./windows')
|
var windows = require('./windows')
|
||||||
|
|
||||||
|
|||||||
@@ -1,10 +1,30 @@
|
|||||||
var config = require('../config')
|
|
||||||
|
|
||||||
module.exports = function () {
|
module.exports = function () {
|
||||||
if (process.platform === 'win32') {
|
if (process.platform === 'win32') {
|
||||||
registerProtocolHandler('magnet', 'BitTorrent Magnet URL', config.APP_FILE_ICON + '.ico', process.execPath)
|
var path = require('path')
|
||||||
registerFileHandler('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', config.APP_FILE_ICON + '.ico', process.execPath)
|
var iconPath = path.join(process.resourcesPath, 'app.asar.unpacked', 'static', 'WebTorrentFile.ico')
|
||||||
|
registerProtocolHandlerWin32('magnet', 'URL:BitTorrent Magnet URL', iconPath, process.execPath)
|
||||||
|
registerFileHandlerWin32('.torrent', 'io.webtorrent.torrent', 'BitTorrent Document', iconPath, process.execPath)
|
||||||
}
|
}
|
||||||
|
if (process.platform === 'linux') {
|
||||||
|
installDesktopFile()
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
function installDesktopFile () {
|
||||||
|
var config = require('../config')
|
||||||
|
var fs = require('fs')
|
||||||
|
var path = require('path')
|
||||||
|
var os = require('os')
|
||||||
|
|
||||||
|
var templatePath = path.join(config.STATIC_PATH, 'webtorrent.desktop')
|
||||||
|
var desktopFile = fs.readFileSync(templatePath, 'utf8')
|
||||||
|
|
||||||
|
desktopFile = desktopFile.replace(/\$APP_NAME/g, config.APP_NAME)
|
||||||
|
desktopFile = desktopFile.replace(/\$APP_PATH/g, path.dirname(process.execPath))
|
||||||
|
desktopFile = desktopFile.replace(/\$EXEC_PATH/g, process.execPath)
|
||||||
|
|
||||||
|
var desktopFilePath = path.join(os.homedir(), '.local', 'share', 'applications', 'webtorrent.desktop')
|
||||||
|
fs.writeFileSync(desktopFilePath, desktopFile)
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@@ -12,13 +32,15 @@ module.exports = function () {
|
|||||||
* registry:
|
* registry:
|
||||||
*
|
*
|
||||||
* HKEY_CLASSES_ROOT
|
* HKEY_CLASSES_ROOT
|
||||||
* $PROTOCOL
|
* $PROTOCOL
|
||||||
* (Default) = "URL:$NAME"
|
* (Default) = "$NAME"
|
||||||
* URL Protocol = ""
|
* URL Protocol = ""
|
||||||
* shell
|
* DefaultIcon
|
||||||
* open
|
* (Default) = "$ICON"
|
||||||
* command
|
* shell
|
||||||
* (Default) = "$COMMAND" "%1"
|
* open
|
||||||
|
* command
|
||||||
|
* (Default) = "$COMMAND" "%1"
|
||||||
*
|
*
|
||||||
* Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx
|
* Source: https://msdn.microsoft.com/en-us/library/aa767914.aspx
|
||||||
*
|
*
|
||||||
@@ -27,14 +49,14 @@ module.exports = function () {
|
|||||||
* "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
|
* "HKEY_CLASSES_ROOT" anyway, and can be written by unprivileged users.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
function registerProtocolHandler (protocol, name, icon, command) {
|
function registerProtocolHandlerWin32 (protocol, name, icon, command) {
|
||||||
var Registry = require('winreg')
|
var Registry = require('winreg')
|
||||||
|
|
||||||
var protocolKey = new Registry({
|
var protocolKey = new Registry({
|
||||||
hive: Registry.HKCU, // HKEY_CURRENT_USER
|
hive: Registry.HKCU, // HKEY_CURRENT_USER
|
||||||
key: '\\Software\\Classes\\' + protocol
|
key: '\\Software\\Classes\\' + protocol
|
||||||
})
|
})
|
||||||
protocolKey.set('', Registry.REG_SZ, 'URL:' + name, callback)
|
protocolKey.set('', Registry.REG_SZ, name, callback)
|
||||||
protocolKey.set('URL Protocol', Registry.REG_SZ, '', callback)
|
protocolKey.set('URL Protocol', Registry.REG_SZ, '', callback)
|
||||||
|
|
||||||
var iconKey = new Registry({
|
var iconKey = new Registry({
|
||||||
@@ -54,7 +76,7 @@ function registerProtocolHandler (protocol, name, icon, command) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function registerFileHandler (ext, id, name, icon, command) {
|
function registerFileHandlerWin32 (ext, id, name, icon, command) {
|
||||||
var Registry = require('winreg')
|
var Registry = require('winreg')
|
||||||
|
|
||||||
var extKey = new Registry({
|
var extKey = new Registry({
|
||||||
16
static/webtorrent.desktop
Normal file
16
static/webtorrent.desktop
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
[Desktop Entry]
|
||||||
|
Name=$APP_NAME
|
||||||
|
Version=1.0
|
||||||
|
GenericName=BitTorrent Client
|
||||||
|
X-GNOME-FullName=$APP_NAME
|
||||||
|
Comment=Download and share files over BitTorrent
|
||||||
|
Encoding=UTF-8
|
||||||
|
Type=Application
|
||||||
|
Icon=webtorrent
|
||||||
|
Terminal=false
|
||||||
|
Path=$APP_PATH
|
||||||
|
Exec=$EXEC_PATH %U
|
||||||
|
TryExec=$EXEC_PATH
|
||||||
|
StartupNotify=false
|
||||||
|
Categories=Network;FileTransfer;P2P;
|
||||||
|
MimeType=application/x-bittorrent;x-scheme-handler/magnet;
|
||||||
Reference in New Issue
Block a user