fix: opening LBRY hyperlinks broken on Linux (https://github.com/lbryio/lbry-app/issues/1120)

This fixes https://github.com/lbryio/lbry-app/issues/1120
This commit is contained in:
Igor Gassmann 2018-03-19 19:03:14 -04:00
parent e6e8218095
commit 5579a12cf3
3 changed files with 27 additions and 11 deletions

View file

@ -46,7 +46,8 @@
"target": "deb",
"category": "AudioVideo;Video",
"desktop": {
"MimeType": "x-scheme-handler/lbry;"
"MimeType": "x-scheme-handler/lbry",
"Exec": "/opt/LBRY/lbry %U"
}
},
"deb": {

View file

@ -33,8 +33,11 @@ export default appState => {
window.loadURL(rendererURL);
let deepLinkingURI;
// Protocol handler for win32
if (process.platform === 'win32' && String(process.argv[1]).startsWith('lbry')) {
if (
(process.platform === 'win32' || process.platform === 'linux') &&
String(process.argv[1]).startsWith('lbry')
) {
[, deepLinkingURI] = process.argv;
// Keep only command line / deep linked arguments
// Windows normalizes URIs when they're passed in from other apps. On Windows, this tries to
// restore the original URI that was typed.
@ -42,8 +45,10 @@ export default appState => {
// path, so we just strip it off.
// - In a URI with a claim ID, like lbry://channel#claimid, Windows interprets the hash mark as
// an anchor and converts it to lbry://channel/#claimid. We remove the slash here as well.
deepLinkingURI = process.argv[1].replace(/\/$/, '').replace('/#', '#');
} else if (process.platform === 'darwin') {
if (process.platform === 'win32') {
deepLinkingURI = deepLinkingURI.replace(/\/$/, '').replace('/#', '#');
}
} else {
deepLinkingURI = appState.macDeepLinkingURI;
}

View file

@ -218,16 +218,26 @@ process.on('uncaughtException', error => {
// Force single instance application
const isSecondInstance = app.makeSingleInstance(argv => {
// Protocol handler for win32
// argv: An array of the second instances (command line / deep linked) arguments
if (
(process.platform === 'win32' || process.platform === 'linux') &&
String(argv[1]).startsWith('lbry')
) {
let URI = argv[1];
let URI;
if (process.platform === 'win32' && String(argv[1]).startsWith('lbry')) {
// Keep only command line / deep linked arguments
URI = argv[1].replace(/\/$/, '').replace('/#', '#');
// Windows normalizes URIs when they're passed in from other apps. On Windows, this tries to
// restore the original URI that was typed.
// - If the URI has no path, Windows adds a trailing slash. LBRY URIs can't have a slash with no
// path, so we just strip it off.
// - In a URI with a claim ID, like lbry://channel#claimid, Windows interprets the hash mark as
// an anchor and converts it to lbry://channel/#claimid. We remove the slash here as well.
if (process.platform === 'win32') {
URI = URI.replace(/\/$/, '').replace('/#', '#');
}
rendererWindow.webContents.send('open-uri-requested', URI);
}
rendererWindow.webContents.send('open-uri-requested', URI);
rendererWindow.show();
});