From db20bd8eaf0afbe97b5564841fd6dc6a859629d1 Mon Sep 17 00:00:00 2001 From: anonymlol Date: Tue, 14 Jun 2016 13:30:38 +0200 Subject: [PATCH 1/2] New Handler: stream-magnet only tested on windows --- bin/package.js | 6 ++++++ main/handlers.js | 9 ++++++++- renderer/main.js | 1 + static/linux/webtorrent-desktop.desktop | 2 +- 4 files changed, 16 insertions(+), 2 deletions(-) diff --git a/bin/package.js b/bin/package.js index 09a2dcea..b0597694 100755 --- a/bin/package.js +++ b/bin/package.js @@ -206,6 +206,12 @@ function buildDarwin (cb) { CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns', CFBundleURLName: 'BitTorrent Magnet URL', CFBundleURLSchemes: [ 'magnet' ] + }, + { + CFBundleTypeRole: 'Editor', + CFBundleURLIconFile: path.basename(config.APP_FILE_ICON) + '.icns', + CFBundleURLName: 'BitTorrent Stream-Magnet URL', + CFBundleURLSchemes: [ 'stream-magnet' ] } ] diff --git a/main/handlers.js b/main/handlers.js index 33da88fe..5ea9431a 100644 --- a/main/handlers.js +++ b/main/handlers.js @@ -36,7 +36,7 @@ function installDarwin () { // On OS X, only protocols that are listed in `Info.plist` can be set as the // default handler at runtime. - app.setAsDefaultProtocolClient('magnet') + app.setAsDefaultProtocolClient('stream-magnet') // File handlers are defined in `Info.plist`. } @@ -63,6 +63,12 @@ function installWin32 () { iconPath, EXEC_COMMAND ) + registerProtocolHandlerWin32( + 'stream-magnet', + 'URL:BitTorrent Stream-Magnet URL', + iconPath, + EXEC_COMMAND + ) registerFileHandlerWin32( '.torrent', 'io.webtorrent.torrent', @@ -201,6 +207,7 @@ function uninstallWin32 () { var Registry = require('winreg') unregisterProtocolHandlerWin32('magnet', EXEC_COMMAND) + unregisterProtocolHandlerWin32('stream-magnet', EXEC_COMMAND) unregisterFileHandlerWin32('.torrent', 'io.webtorrent.torrent', EXEC_COMMAND) function unregisterProtocolHandlerWin32 (protocol, command) { diff --git a/renderer/main.js b/renderer/main.js index 39bcc30a..470cfdc5 100644 --- a/renderer/main.js +++ b/renderer/main.js @@ -550,6 +550,7 @@ function isTorrent (file) { var name = typeof file === 'string' ? file : file.name var isTorrentFile = path.extname(name).toLowerCase() === '.torrent' var isMagnet = typeof file === 'string' && /^magnet:/.test(file) + var isMagnet = typeof file === 'string' && /^stream-magnet:/.test(file) return isTorrentFile || isMagnet } diff --git a/static/linux/webtorrent-desktop.desktop b/static/linux/webtorrent-desktop.desktop index ac37a056..d47e98a6 100644 --- a/static/linux/webtorrent-desktop.desktop +++ b/static/linux/webtorrent-desktop.desktop @@ -13,7 +13,7 @@ Exec=$EXEC_PATH %U TryExec=$TRY_EXEC_PATH StartupNotify=false Categories=Network;FileTransfer;P2P; -MimeType=application/x-bittorrent;x-scheme-handler/magnet; +MimeType=application/x-bittorrent;x-scheme-handler/magnet;x-scheme-handler/stream-magnet; Actions=CreateNewTorrent;OpenTorrentFile;OpenTorrentAddress; From 8f03ecedaa2872c3ff604fbc53d407c94c700868 Mon Sep 17 00:00:00 2001 From: anonymlol Date: Tue, 14 Jun 2016 13:53:01 +0200 Subject: [PATCH 2/2] fix 'isMagnet' is already defined error --- renderer/main.js | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/renderer/main.js b/renderer/main.js index 470cfdc5..2fe0ff5c 100644 --- a/renderer/main.js +++ b/renderer/main.js @@ -549,8 +549,7 @@ function onOpen (files) { function isTorrent (file) { var name = typeof file === 'string' ? file : file.name var isTorrentFile = path.extname(name).toLowerCase() === '.torrent' - var isMagnet = typeof file === 'string' && /^magnet:/.test(file) - var isMagnet = typeof file === 'string' && /^stream-magnet:/.test(file) + var isMagnet = typeof file === 'string' && /^magnet:/.test(file) || /^stream-magnet:/.test(file) return isTorrentFile || isMagnet }