From f9325a816eb6e47ca060fa37b182df0916f1a262 Mon Sep 17 00:00:00 2001 From: Sean Yesmunt Date: Tue, 7 Jul 2020 16:42:21 -0400 Subject: [PATCH] only start lbryFirst daemon for approved users --- electron/index.js | 19 +- package.json | 2 +- static/app-strings.json | 6 +- .../publishAdditionalOptions/view.jsx | 201 ++++++++++-------- yarn.lock | 4 +- 5 files changed, 137 insertions(+), 95 deletions(-) diff --git a/electron/index.js b/electron/index.js index 5601c9c84..a7e30ba8b 100644 --- a/electron/index.js +++ b/electron/index.js @@ -4,7 +4,7 @@ import '@babel/polyfill'; import SemVer from 'semver'; import https from 'https'; -import { app, dialog, ipcMain, session, shell } from 'electron'; +import { app, dialog, ipcMain, session, shell, ipcRenderer } from 'electron'; import { autoUpdater } from 'electron-updater'; import { Lbry, LbryFirst } from 'lbry-redux'; import LbryFirstInstance from './LbryFirstInstance'; @@ -95,6 +95,8 @@ const startLbryFirst = async () => { try { await LbryFirst.status(); isLbryFirstRunning = true; + console.log('LbryFirst: Already running'); + handleLbryFirstLaunched(); } catch (e) { console.log('status fails', e); console.log('Starting LbryFirst'); @@ -118,12 +120,17 @@ const startLbryFirst = async () => { try { await lbryFirst.launch(); + handleLbryFirstLaunched(); } catch (e) { console.log('e', e); } } }; +const handleLbryFirstLaunched = () => { + rendererWindow.webContents.send('lbry-first-launched'); +}; + // When we are starting the app, ensure there are no other apps already running const gotSingleInstanceLock = app.requestSingleInstanceLock(); @@ -160,7 +167,6 @@ if (!gotSingleInstanceLock) { app.on('ready', async () => { await startDaemon(); - await startLbryFirst(); startSandbox(); if (isDev) { @@ -370,6 +376,15 @@ ipcMain.on('version-info-requested', () => { requestLatestRelease(); }); +ipcMain.on('launch-lbry-first', async () => { + try { + await startLbryFirst(); + } catch (e) { + console.log('Failed to start LbryFirst'); + console.log(e); + } +}); + process.on('uncaughtException', error => { console.log(error); dialog.showErrorBox('Error Encountered', `Caught error: ${error}`); diff --git a/package.json b/package.json index 9b7525a57..33fc33ada 100644 --- a/package.json +++ b/package.json @@ -137,7 +137,7 @@ "json-loader": "^0.5.4", "lbry-format": "https://github.com/lbryio/lbry-format.git", "lbry-redux": "lbryio/lbry-redux#67d8540ccc0fbedf018ae0bdfe3cae17660a5a6c", - "lbryinc": "lbryio/lbryinc#0f6fd2c33812fb1c1e393dd35b1a7560d3ba3fe2", + "lbryinc": "lbryio/lbryinc#cff5dd60934c4c6080e135f47ebbece1548c658c", "lint-staged": "^7.0.2", "localforage": "^1.7.1", "lodash-es": "^4.17.14", diff --git a/static/app-strings.json b/static/app-strings.json index 36c5fd97b..99eb2f49c 100644 --- a/static/app-strings.json +++ b/static/app-strings.json @@ -1261,5 +1261,9 @@ "Delete Your Channel": "Delete Your Channel", "Remove from Blocked List": "Remove from Blocked List", "Are you sure you want to remove this from the list?": "Are you sure you want to remove this from the list?", - "Automagically upload to your youtube channel!": "Automagically upload to your youtube channel!" + "CableTube Escape Artists": "CableTube Escape Artists", + "Unlink YouTube Channel": "Unlink YouTube Channel", + "Sign In With YouTube": "Sign In With YouTube", + "There was an error with LBRY first publishing.": "There was an error with LBRY first publishing.", + "Automagically upload to your youtube channel.": "Automagically upload to your youtube channel." } diff --git a/ui/component/publishAdditionalOptions/view.jsx b/ui/component/publishAdditionalOptions/view.jsx index e1a981632..bb80fccb9 100644 --- a/ui/component/publishAdditionalOptions/view.jsx +++ b/ui/component/publishAdditionalOptions/view.jsx @@ -5,9 +5,13 @@ import usePersistedState from 'effects/use-persisted-state'; import { FormField } from 'component/common/form'; import Button from 'component/button'; import { LbryFirst } from 'lbry-redux'; - import LicenseType from './license-type'; import Card from 'component/common/card'; +import { getAuthToken } from 'util/saved-passwords'; +import ErrorText from 'component/common/error-text'; +// @if TARGET='app' +import { ipcRenderer } from 'electron'; +// @endif type Props = { user: ?User, @@ -35,56 +39,63 @@ function PublishAdditionalOptions(props: Props) { updatePublishForm, useLBRYUploader, needsYTAuth, - fetchAccessToken, - accessToken, } = props; const [hideSection, setHideSection] = usePersistedState('publish-advanced-options', true); + const [hasLaunchedLbryFirst, setHasLaunchedLbryFirst] = React.useState(false); + const [ytError, setYtError] = React.useState(true); const isLBRYFirstUser = user && user.lbry_first_approved; + const showLbryFirstCheckbox = !IS_WEB && isLBRYFirstUser && hasLaunchedLbryFirst; + const authToken = getAuthToken(); function toggleHideSection() { setHideSection(!hideSection); } + function signup() { updatePublishForm({ ytSignupPending: true }); LbryFirst.ytSignup() .then(response => { - console.log(response); updatePublishForm({ needsYTAuth: false, ytSignupPending: false }); }) .catch(error => { updatePublishForm({ ytSignupPending: false }); - console.log(error); + setYtError(true); + console.error(error); // eslint-disable-line }); } + function unlink() { LbryFirst.remove() .then(response => { - console.log(response); updatePublishForm({ needsYTAuth: true }); }) .catch(error => { - console.log(error); + setYtError(true); + console.error(error); // eslint-disable-line }); } React.useEffect(() => { - if (!accessToken) { - fetchAccessToken(); + if (isLBRYFirstUser) { + ipcRenderer.send('launch-lbry-first'); + ipcRenderer.on('lbry-first-launched', () => { + setHasLaunchedLbryFirst(true); + }); } - }, [accessToken, fetchAccessToken]); + }, [isLBRYFirstUser, setHasLaunchedLbryFirst]); React.useEffect(() => { if (useLBRYUploader) { - LbryFirst.hasYTAuth(accessToken) + LbryFirst.hasYTAuth(authToken) .then(response => { - console.log(response); updatePublishForm({ needsYTAuth: !response.HasAuth }); }) .catch(error => { - console.log(error); + setYtError(true); + console.error(error); // eslint-disable-line }); } - }, [accessToken, updatePublishForm, useLBRYUploader]); + }, [authToken, updatePublishForm, useLBRYUploader]); return ( {!hideSection && (
- {!IS_WEB && isLBRYFirstUser && ( +
+ {showLbryFirstCheckbox && ( + <> + updatePublishForm({ useLBRYUploader: !useLBRYUploader })} + label={ + + {__('Automagically upload to your youtube channel.')}{' '} +
+ )} + + )} +
+
updatePublishForm({ useLBRYUploader: !useLBRYUploader })} - label={ - - {__('Automagically upload to your youtube channel!')}{' '} -
- )} - {!IS_WEB && useLBRYUploader && needsYTAuth && isLBRYFirstUser && ( -
-
- )} - updatePublishForm({ language: event.target.value })} - > - - - - - - - - - - - - - - - - - - - - - - - - - - - - + label={__('Language')} + type="select" + name="content_language" + value={language} + onChange={event => updatePublishForm({ language: event.target.value })} + > + + + + + + + + + + + + + + + + + + + + + + + + + + + + - - updatePublishForm({ - licenseType: newLicenseType, - licenseUrl: newLicenseUrl, - }) - } - handleLicenseDescriptionChange={event => - updatePublishForm({ - otherLicenseDescription: event.target.value, - }) - } - handleLicenseUrlChange={event => updatePublishForm({ licenseUrl: event.target.value })} - /> + + updatePublishForm({ + licenseType: newLicenseType, + licenseUrl: newLicenseUrl, + }) + } + handleLicenseDescriptionChange={event => + updatePublishForm({ + otherLicenseDescription: event.target.value, + }) + } + handleLicenseUrlChange={event => updatePublishForm({ licenseUrl: event.target.value })} + /> + )} -
+