From d44d5806fd3a174392fd90cf3ccddec716290e8e Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 10 May 2017 04:05:55 -0400 Subject: [PATCH 1/8] Add setAsDefaultProtocolClient call for Windows --- app/main.js | 1 + 1 file changed, 1 insertion(+) diff --git a/app/main.js b/app/main.js index cac430513..e2035bcc2 100644 --- a/app/main.js +++ b/app/main.js @@ -315,6 +315,7 @@ function upgrade(event, installerPath) { ipcMain.on('upgrade', upgrade); +app.setAsDefaultProtocolClient('lbry'); if (process.platform == 'darwin') { app.on('open-url', (event, uri) => { if (!win) { From b189b31347c8e8359373cd7aba619e9f0168ca98 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 10 May 2017 04:30:26 -0400 Subject: [PATCH 2/8] Fix handling for URIs requested before window is open on Windows --- app/main.js | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/app/main.js b/app/main.js index e2035bcc2..4fcf6572e 100644 --- a/app/main.js +++ b/app/main.js @@ -327,5 +327,9 @@ if (process.platform == 'darwin') { }); } else if (process.argv.length >= 3) { // No open-url event on Win, but we can still handle URIs provided at launch time - win.webContents.send('open-uri-requested', process.argv[2]); + if (!win) { + openUri = process.argv[2]; + } else { + win.webContents.send('open-uri-requested', process.argv[2]); + } } From 856aa28db2a7fbc3e39121ac1c3cea8d33ab94de Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 10 May 2017 04:44:06 -0400 Subject: [PATCH 3/8] Convert to single-instance app - Prevents multiple windows from being opens at once - Allows for URI launching by capturing argv from second process --- app/main.js | 22 ++++++++++++++++++++++ lbry | 1 + lbryschema | 1 + lbryum | 1 + 4 files changed, 25 insertions(+) create mode 160000 lbry create mode 160000 lbryschema create mode 160000 lbryum diff --git a/app/main.js b/app/main.js index 4fcf6572e..aa0cde89f 100644 --- a/app/main.js +++ b/app/main.js @@ -177,6 +177,27 @@ function quitNow() { app.quit(); } +const isSecondaryInstance = app.makeSingleInstance((argv) => { + if (process.argv.length < 3) { + return; + } + + if (!win) { + openUri = argv[2]; + } else { + if (win.isMinimized()) { + win.restore(); + win.focus(); + } + + win.webContents.send('open-uri-requested', argv[2]); + } +}); + +if (isSecondaryInstance) { // We're not in the original process, so quit + quitNow(); + return; +} app.on('ready', function(){ launchDaemonIfNotRunning(); @@ -316,6 +337,7 @@ function upgrade(event, installerPath) { ipcMain.on('upgrade', upgrade); app.setAsDefaultProtocolClient('lbry'); + if (process.platform == 'darwin') { app.on('open-url', (event, uri) => { if (!win) { diff --git a/lbry b/lbry new file mode 160000 index 000000000..d99fc519b --- /dev/null +++ b/lbry @@ -0,0 +1 @@ +Subproject commit d99fc519b56ee910a44ef4af668b0770e9430d12 diff --git a/lbryschema b/lbryschema new file mode 160000 index 000000000..5c2441fa1 --- /dev/null +++ b/lbryschema @@ -0,0 +1 @@ +Subproject commit 5c2441fa13e39ba7280292519041e14ec696d753 diff --git a/lbryum b/lbryum new file mode 160000 index 000000000..950b95aa7 --- /dev/null +++ b/lbryum @@ -0,0 +1 @@ +Subproject commit 950b95aa7e45a2c15b269d807f6ff8e16bae4304 From 2b6528ca3ed1e193c5ee66809f6789c5c703039b Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 10 May 2017 21:27:57 -0400 Subject: [PATCH 4/8] Fix argv.length check in makeSingleInstance callback Also correct length of argv: with Electron, there's just the executable, not interpreter + filename. --- app/main.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/app/main.js b/app/main.js index aa0cde89f..e2e4c992a 100644 --- a/app/main.js +++ b/app/main.js @@ -178,19 +178,19 @@ function quitNow() { } const isSecondaryInstance = app.makeSingleInstance((argv) => { - if (process.argv.length < 3) { + if (argv.length < 2) { return; } if (!win) { - openUri = argv[2]; + openUri = argv[1]; } else { if (win.isMinimized()) { win.restore(); win.focus(); } - win.webContents.send('open-uri-requested', argv[2]); + win.webContents.send('open-uri-requested', argv[1]); } }); @@ -347,11 +347,11 @@ if (process.platform == 'darwin') { win.webContents.send('open-uri-requested', uri); } }); -} else if (process.argv.length >= 3) { +} else if (process.argv.length >= 2) { // No open-url event on Win, but we can still handle URIs provided at launch time if (!win) { - openUri = process.argv[2]; + openUri = process.argv[1]; } else { - win.webContents.send('open-uri-requested', process.argv[2]); + win.webContents.send('open-uri-requested', process.argv[1]); } } From df46c3f4e5733fd1c262910ceccf023af0f6290d Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Wed, 10 May 2017 23:40:07 -0400 Subject: [PATCH 5/8] Undo normalization that Windows does to URIs passed in from other apps --- app/main.js | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/app/main.js b/app/main.js index e2e4c992a..824ac8885 100644 --- a/app/main.js +++ b/app/main.js @@ -34,6 +34,22 @@ let readyToQuit = false; // send it to, it's cached in this variable. let openUri = null; +function denormalizeUri(uri) { + // Windows normalizes URIs when they're passed in from other apps. 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') { + return uri.replace(/\/$/, '').replace('/#', '#'); + } else { + return uri; + } +} + function checkForNewVersion(callback) { function formatRc(ver) { // Adds dash if needed to make RC suffix semver friendly @@ -183,14 +199,14 @@ const isSecondaryInstance = app.makeSingleInstance((argv) => { } if (!win) { - openUri = argv[1]; + openUri = denormalizeUri(argv[1]); } else { if (win.isMinimized()) { win.restore(); win.focus(); } - win.webContents.send('open-uri-requested', argv[1]); + win.webContents.send('open-uri-requested', denormalizeUri(argv[1])); } }); @@ -348,10 +364,9 @@ if (process.platform == 'darwin') { } }); } else if (process.argv.length >= 2) { - // No open-url event on Win, but we can still handle URIs provided at launch time if (!win) { - openUri = process.argv[1]; + openUri = denormalizeUri(process.argv[1]); } else { - win.webContents.send('open-uri-requested', process.argv[1]); + win.webContents.send('open-uri-requested', denormalizeUri(process.argv[1])); } } From d888707d5605293568e2f3018a63c4bbb372df4e Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 11 May 2017 00:03:39 -0400 Subject: [PATCH 6/8] Tweak logic in makeSingleInstance callback --- app/main.js | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/app/main.js b/app/main.js index 824ac8885..3328b928d 100644 --- a/app/main.js +++ b/app/main.js @@ -194,19 +194,17 @@ function quitNow() { } const isSecondaryInstance = app.makeSingleInstance((argv) => { - if (argv.length < 2) { - return; - } - - if (!win) { - openUri = denormalizeUri(argv[1]); - } else { + if (win) { if (win.isMinimized()) { win.restore(); - win.focus(); } + win.focus(); - win.webContents.send('open-uri-requested', denormalizeUri(argv[1])); + if (argv.length >= 2) { + win.webContents.send('open-uri-requested', denormalizeUri(argv[1])); + } + } else if (argv.length >= 2) { + openUri = denormalizeUri(argv[1]); } }); From 980a50926067b1f3fca32bd33f878bf6e542d8bd Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 11 May 2017 03:30:23 -0400 Subject: [PATCH 7/8] Disable single instance app on Linux for now (Electron bug) On Linux, app.makeSingleInstance is always returning true (i.e. "this is not the original process"). --- app/main.js | 34 +++++++++++++++++++--------------- 1 file changed, 19 insertions(+), 15 deletions(-) diff --git a/app/main.js b/app/main.js index 3328b928d..14e5b7f90 100644 --- a/app/main.js +++ b/app/main.js @@ -193,24 +193,28 @@ function quitNow() { app.quit(); } -const isSecondaryInstance = app.makeSingleInstance((argv) => { - if (win) { - if (win.isMinimized()) { - win.restore(); - } - win.focus(); +if (process.platform != 'linux') { + // On Linux, this is always returning true due to an Electron bug, + // so for now we just don't support single-instance apps on Linux. + const isSecondaryInstance = app.makeSingleInstance((argv) => { + if (win) { + if (win.isMinimized()) { + win.restore(); + } + win.focus(); - if (argv.length >= 2) { - win.webContents.send('open-uri-requested', denormalizeUri(argv[1])); + if (argv.length >= 2) { + win.webContents.send('open-uri-requested', denormalizeUri(argv[1])); + } + } else if (argv.length >= 2) { + openUri = denormalizeUri(argv[1]); } - } else if (argv.length >= 2) { - openUri = denormalizeUri(argv[1]); + }); + + if (isSecondaryInstance) { // We're not in the original process, so quit + quitNow(); + return; } -}); - -if (isSecondaryInstance) { // We're not in the original process, so quit - quitNow(); - return; } app.on('ready', function(){ From 32fd2c2c7a8f1e0397584a1760297bd74487a945 Mon Sep 17 00:00:00 2001 From: Alex Liebowitz Date: Thu, 11 May 2017 03:41:35 -0400 Subject: [PATCH 8/8] Update changelog --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 7b6aa8859..5ff185868 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -44,6 +44,7 @@ Web UI version numbers should always match the corresponding version of LBRY App * Handle more of price calculations at the daemon layer to improve page load time * Add special support for building channel claims in lbryuri module * Enable windows code signing of binary + * Support for opening LBRY URIs from links in other apps ### Changed @@ -55,6 +56,7 @@ Web UI version numbers should always match the corresponding version of LBRY App ### Fixed * Fix Watch page and progress bars for new API changes + * On Windows, prevent opening multiple LBRY instances (launching LBRY again just focuses the current instance)