Merge pull request #121 from lbryio/windows-linux-uris

Windows URI handling
This commit is contained in:
Jeremy Kauffman 2017-05-12 16:46:48 -04:00 committed by GitHub
commit 57bd67d925
5 changed files with 52 additions and 3 deletions

View file

@ -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)

View file

@ -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,6 +199,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();
@ -321,6 +360,8 @@ function upgrade(event, installerPath) {
ipcMain.on('upgrade', upgrade);
app.setAsDefaultProtocolClient('lbry');
if (process.platform == 'darwin') {
app.on('open-url', (event, uri) => {
if (!win) {
@ -330,7 +371,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]));
}
}

1
lbry Submodule

@ -0,0 +1 @@
Subproject commit d99fc519b56ee910a44ef4af668b0770e9430d12

1
lbryschema Submodule

@ -0,0 +1 @@
Subproject commit 5c2441fa13e39ba7280292519041e14ec696d753

1
lbryum Submodule

@ -0,0 +1 @@
Subproject commit 950b95aa7e45a2c15b269d807f6ff8e16bae4304