Skip to content

Commit

Permalink
fix: opening LBRY hyperlinks broken on Linux (#1120)
Browse files Browse the repository at this point in the history
This fixes #1120
  • Loading branch information
Igor Gassmann committed Mar 20, 2018
1 parent e6e8218 commit 5579a12
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 11 deletions.
3 changes: 2 additions & 1 deletion electron-builder.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": {
Expand Down
13 changes: 9 additions & 4 deletions src/main/createWindow.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,17 +33,22 @@ 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.
// - 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.
deepLinkingURI = process.argv[1].replace(/\/$/, '').replace('/#', '#');
} else if (process.platform === 'darwin') {
if (process.platform === 'win32') {
deepLinkingURI = deepLinkingURI.replace(/\/$/, '').replace('/#', '#');
}
} else {
deepLinkingURI = appState.macDeepLinkingURI;
}

Expand Down
22 changes: 16 additions & 6 deletions src/main/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 instance’s (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();
});

Expand Down

0 comments on commit 5579a12

Please sign in to comment.