From 034398859e2316d58648fc6a0073c22cd0144d25 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Mon, 19 Mar 2018 15:57:42 -0400 Subject: [PATCH 1/8] fix: daemon doesn't quit when quitting the app for an auto-update (https://github.com/lbryio/lbry-app/issues/1142) Fix https://github.com/lbryio/lbry-app/issues/1142 --- src/main/index.js | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index a1947739d..d2c30e2b0 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -14,15 +14,6 @@ import createWindow from './createWindow'; autoUpdater.autoDownload = true; -// This is set to true if an auto update has been downloaded through the Electron -// auto-update system and is ready to install. If the user declined an update earlier, -// it will still install on shutdown. -let autoUpdateDownloaded = false; - -// This is used to keep track of whether we are showing the special dialog -// that we show on Windows after you decline an upgrade and close the app later. -let showingAutoUpdateCloseAlert = false; - // Keep a global reference, if you don't, they will be closed automatically when the JavaScript // object is garbage collected. let rendererWindow; @@ -84,16 +75,16 @@ app.on('activate', () => { app.on('will-quit', event => { if ( process.platform === 'win32' && - autoUpdateDownloaded && + appState.autoUpdateDownloaded && !appState.autoUpdateAccepted && - !showingAutoUpdateCloseAlert + !appState.showingAutoUpdateCloseAlert ) { - // We're on Win and have an update downloaded, but the user declined it (or closed + // We're on Win and have an update downloaded, but the user postponed it (or closed // the app without accepting it). Now the user is closing the app, so the new update // will install. On Mac this is silent, but on Windows they get a confusing permission // escalation dialog, so we show Windows users a warning dialog first. - showingAutoUpdateCloseAlert = true; + appState.showingAutoUpdateCloseAlert = true; dialog.showMessageBox( { type: 'info', @@ -126,6 +117,9 @@ app.on('will-finish-launching', () => { app.on('before-quit', () => { appState.isQuitting = true; + if (appState.autoUpdateAccepted) { + if (daemon) daemon.quit(); + } }); ipcMain.on('upgrade', (event, installerPath) => { @@ -145,7 +139,7 @@ ipcMain.on('upgrade', (event, installerPath) => { }); autoUpdater.on('update-downloaded', () => { - autoUpdateDownloaded = true; + appState.autoUpdateDownloaded = true; }); ipcMain.on('autoUpdateAccepted', () => { From e6e82180954cd55371e50edac03c090cd0160d2a Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Mon, 19 Mar 2018 16:51:57 -0400 Subject: [PATCH 2/8] fix: error when clicking LBRY URL when app is closed (https://github.com/lbryio/lbry-app/issues/1119) Fix https://github.com/lbryio/lbry-app/issues/1119 --- src/main/createWindow.js | 2 ++ src/main/index.js | 9 +++++++-- 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/src/main/createWindow.js b/src/main/createWindow.js index 06d222e96..57d459452 100644 --- a/src/main/createWindow.js +++ b/src/main/createWindow.js @@ -43,6 +43,8 @@ export default appState => { // - 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') { + deepLinkingURI = appState.macDeepLinkingURI; } setupBarMenu(); diff --git a/src/main/index.js b/src/main/index.js index d2c30e2b0..13381fc1c 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -110,8 +110,13 @@ app.on('will-finish-launching', () => { // Protocol handler for macOS app.on('open-url', (event, URL) => { event.preventDefault(); - rendererWindow.webContents.send('open-uri-requested', URL); - rendererWindow.show(); + + if (rendererWindow) { + rendererWindow.webContents.send('open-uri-requested', URL); + rendererWindow.show(); + } else { + appState.macDeepLinkingURI = URL; + } }); }); From 5579a12cf3de461850c50eac16fe99ed07be4dc5 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Mon, 19 Mar 2018 19:03:14 -0400 Subject: [PATCH 3/8] 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 --- electron-builder.json | 3 ++- src/main/createWindow.js | 13 +++++++++---- src/main/index.js | 22 ++++++++++++++++------ 3 files changed, 27 insertions(+), 11 deletions(-) diff --git a/electron-builder.json b/electron-builder.json index baecbb56e..0addff49a 100644 --- a/electron-builder.json +++ b/electron-builder.json @@ -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": { diff --git a/src/main/createWindow.js b/src/main/createWindow.js index 57d459452..27af06c38 100644 --- a/src/main/createWindow.js +++ b/src/main/createWindow.js @@ -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; } diff --git a/src/main/index.js b/src/main/index.js index 13381fc1c..8b125042c 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -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(); }); From 0271311bca4f25204f1e1eee5737c9a1c6af811e Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Mon, 19 Mar 2018 21:09:36 -0400 Subject: [PATCH 4/8] feat: add error console logging for auto-update --- src/renderer/index.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/renderer/index.js b/src/renderer/index.js index d75505200..983f611ef 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -4,7 +4,6 @@ import SnackBar from 'component/snackBar'; import SplashScreen from 'component/splash'; import * as ACTIONS from 'constants/action_types'; import { ipcRenderer, remote, shell } from 'electron'; -import lbry from 'lbry'; import React from 'react'; import ReactDOM from 'react-dom'; import { Provider } from 'react-redux'; @@ -100,6 +99,10 @@ const init = () => { app.store.dispatch(doAutoUpdate()); }); + autoUpdater.on('error', (error) => { + console.error(error.message) + }); + if (['win32', 'darwin'].includes(process.platform)) { autoUpdater.on('update-available', () => { console.log('Update available'); From 40a6ad0e1ca613b0273e588e83448fbd4a55244b Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Mon, 19 Mar 2018 21:09:48 -0400 Subject: [PATCH 5/8] Revert "fix: daemon doesn't quit when quitting the app for an auto-update (https://github.com/lbryio/lbry-app/issues/1142)" This reverts commit 034398859e2316d58648fc6a0073c22cd0144d25. --- src/main/index.js | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 8b125042c..4f7e9dcdf 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -14,6 +14,15 @@ import createWindow from './createWindow'; autoUpdater.autoDownload = true; +// This is set to true if an auto update has been downloaded through the Electron +// auto-update system and is ready to install. If the user declined an update earlier, +// it will still install on shutdown. +let autoUpdateDownloaded = false; + +// This is used to keep track of whether we are showing the special dialog +// that we show on Windows after you decline an upgrade and close the app later. +let showingAutoUpdateCloseAlert = false; + // Keep a global reference, if you don't, they will be closed automatically when the JavaScript // object is garbage collected. let rendererWindow; @@ -75,16 +84,16 @@ app.on('activate', () => { app.on('will-quit', event => { if ( process.platform === 'win32' && - appState.autoUpdateDownloaded && + autoUpdateDownloaded && !appState.autoUpdateAccepted && - !appState.showingAutoUpdateCloseAlert + !showingAutoUpdateCloseAlert ) { - // We're on Win and have an update downloaded, but the user postponed it (or closed + // We're on Win and have an update downloaded, but the user declined it (or closed // the app without accepting it). Now the user is closing the app, so the new update // will install. On Mac this is silent, but on Windows they get a confusing permission // escalation dialog, so we show Windows users a warning dialog first. - appState.showingAutoUpdateCloseAlert = true; + showingAutoUpdateCloseAlert = true; dialog.showMessageBox( { type: 'info', @@ -122,9 +131,6 @@ app.on('will-finish-launching', () => { app.on('before-quit', () => { appState.isQuitting = true; - if (appState.autoUpdateAccepted) { - if (daemon) daemon.quit(); - } }); ipcMain.on('upgrade', (event, installerPath) => { @@ -144,7 +150,7 @@ ipcMain.on('upgrade', (event, installerPath) => { }); autoUpdater.on('update-downloaded', () => { - appState.autoUpdateDownloaded = true; + autoUpdateDownloaded = true; }); ipcMain.on('autoUpdateAccepted', () => { From 07ee6b95b1ce8f29fcdf7d3901971d3d07a4d119 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Tue, 20 Mar 2018 15:01:18 -0400 Subject: [PATCH 6/8] fix: daemon doesn't quit when quitting the app for an auto-update (https://github.com/lbryio/lbry-app/issues/1142) This fixes https://github.com/lbryio/lbry-app/issues/1142 --- src/main/index.js | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/main/index.js b/src/main/index.js index 4f7e9dcdf..a456fcd5a 100644 --- a/src/main/index.js +++ b/src/main/index.js @@ -65,8 +65,8 @@ app.on('ready', async () => { 'For more information please visit: \n' + 'https://lbry.io/faq/startup-troubleshooting' ); - app.quit(); } + app.quit(); }); daemon.launch(); } @@ -111,7 +111,10 @@ app.on('will-quit', event => { } appState.isQuitting = true; - if (daemon) daemon.quit(); + if (daemon) { + daemon.quit(); + event.preventDefault(); + } }); // https://electronjs.org/docs/api/app#event-will-finish-launching From a15192db030a0ed209ae795392f9594dabfc9ced Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Tue, 20 Mar 2018 15:47:43 -0400 Subject: [PATCH 7/8] chore: add changelog entries --- CHANGELOG.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98703d571..e53c5892c 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -33,6 +33,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/). * Fix right click bug ([#928](https://github.com/lbryio/lbry-app/pull/928)) * Fix Election linting errors ([#929](https://github.com/lbryio/lbry-app/pull/929)) * App will no longer reset when minimizing to tray ([#1042](https://github.com/lbryio/lbry-app/pull/1042)) + * Error when clicking LBRY URLs when app is closed on macOS ([#1119](https://github.com/lbryio/lbry-app/issues/1119)) + * LBRY URLs not working on Linux ([#1120](https://github.com/lbryio/lbry-app/issues/1120)) ### Deprecated * From 8267a5caea027e4de08409a3ed457e9cbf302e21 Mon Sep 17 00:00:00 2001 From: Igor Gassmann Date: Tue, 20 Mar 2018 15:49:08 -0400 Subject: [PATCH 8/8] chore: suppress no-console ESLint rule Suppresses this rule until logging framework integrated. --- src/renderer/index.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/renderer/index.js b/src/renderer/index.js index 983f611ef..1b395f3ad 100644 --- a/src/renderer/index.js +++ b/src/renderer/index.js @@ -100,6 +100,7 @@ const init = () => { }); autoUpdater.on('error', (error) => { + // eslint-disable-next-line no-console console.error(error.message) });