Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

new protocol handler: stream-magnet #640

Merged
merged 2 commits into from
Jun 24, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 6 additions & 0 deletions bin/package.js
Original file line number Diff line number Diff line change
Expand Up @@ -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' ]
}
]

Expand Down
9 changes: 8 additions & 1 deletion main/handlers.js
Original file line number Diff line number Diff line change
Expand Up @@ -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')
Copy link
Member

@feross feross Jun 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This shouldn't remove magnet, since we support both in Windows/Linux.


// File handlers are defined in `Info.plist`.
}
Expand All @@ -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',
Expand Down Expand Up @@ -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) {
Expand Down
2 changes: 1 addition & 1 deletion renderer/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -549,7 +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' && /^magnet:/.test(file) || /^stream-magnet:/.test(file)
Copy link
Member

@feross feross Jun 24, 2016

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would put parens around the magnet regexes for clarity -- I can never remember the order of ops of || and &&.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This also could be like var isMagnet = typeof file === 'string' && /^(stream-)?magnet:/.test(file)

return isTorrentFile || isMagnet
}

Expand Down
2 changes: 1 addition & 1 deletion static/linux/webtorrent-desktop.desktop
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down