diff --git a/CHANGELOG.md b/CHANGELOG.md index fd4f4efb6..49434d180 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -55,6 +55,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 @@ -66,6 +67,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) diff --git a/app/main.js b/app/main.js index 90668b138..6fb0ba981 100644 --- a/app/main.js +++ b/app/main.js @@ -37,6 +37,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 @@ -186,6 +202,29 @@ function quitNow() { app.quit(); } +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])); + } + } else if (argv.length >= 2) { + openUri = denormalizeUri(argv[1]); + } + }); + + if (isSecondaryInstance) { // We're not in the original process, so quit + quitNow(); + return; + } +} app.on('ready', function(){ launchDaemonIfNotRunning(); @@ -324,6 +363,8 @@ function upgrade(event, installerPath) { ipcMain.on('upgrade', upgrade); +app.setAsDefaultProtocolClient('lbry'); + if (process.platform == 'darwin') { app.on('open-url', (event, uri) => { if (!win) { @@ -333,7 +374,10 @@ if (process.platform == 'darwin') { win.webContents.send('open-uri-requested', uri); } }); -} 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]); +} else if (process.argv.length >= 2) { + if (!win) { + openUri = denormalizeUri(process.argv[1]); + } else { + win.webContents.send('open-uri-requested', denormalizeUri(process.argv[1])); + } } 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