only start lbryFirst daemon for approved users

This commit is contained in:
Sean Yesmunt 2020-07-07 16:42:21 -04:00
parent 4291c36c58
commit f9325a816e
5 changed files with 137 additions and 95 deletions

View file

@ -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}`);

View file

@ -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",

View file

@ -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."
}

View file

@ -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 (
<Card
@ -92,86 +103,98 @@ function PublishAdditionalOptions(props: Props) {
<React.Fragment>
{!hideSection && (
<div className={classnames({ 'card--disabled': !name })}>
{!IS_WEB && isLBRYFirstUser && (
<div className="section">
{showLbryFirstCheckbox && (
<>
<FormField
checked={useLBRYUploader}
type="checkbox"
name="use_lbry_uploader_checkbox"
onChange={event => updatePublishForm({ useLBRYUploader: !useLBRYUploader })}
label={
<React.Fragment>
{__('Automagically upload to your youtube channel.')}{' '}
<Button button="link" href="https://lbry.com/faq/lbry-uploader" label={__('Learn More')} />
</React.Fragment>
}
/>
{useLBRYUploader && (
<div className="section__actions">
{needsYTAuth ? (
<Button
button="primary"
onClick={signup}
label={__('Sign In With YouTube')}
disabled={false}
/>
) : (
<Button button="alt" onClick={unlink} label={__('Unlink YouTube Channel')} disabled={false} />
)}
{ytError && <ErrorText>{__('There was an error with LBRY first publishing.')}</ErrorText>}
</div>
)}
</>
)}
</div>
<div className="section">
<FormField
type="checkbox"
name="use_lbry_uploader_checkbox"
onChange={event => updatePublishForm({ useLBRYUploader: !useLBRYUploader })}
label={
<React.Fragment>
{__('Automagically upload to your youtube channel!')}{' '}
<Button button="link" href="https://lbry.com/faq/lbry-uploader" label={__('Learn More')} />
</React.Fragment>
}
/>
)}
{!IS_WEB && useLBRYUploader && !needsYTAuth && isLBRYFirstUser && (
<div className="card__actions">
<Button button="primary" onClick={unlink} label="Unlink YouTube Channel!" disabled={false} />
</div>
)}
{!IS_WEB && useLBRYUploader && needsYTAuth && isLBRYFirstUser && (
<div className="card__actions">
<Button button="primary" onClick={signup} label="Sign in with YouTube!" disabled={false} />
</div>
)}
<FormField
label={__('Language')}
type="select"
name="content_language"
value={language}
onChange={event => updatePublishForm({ language: event.target.value })}
>
<option value="en">{__('English')}</option>
<option value="zh">{__('Chinese')}</option>
<option value="fr">{__('French')}</option>
<option value="de">{__('German')}</option>
<option value="jp">{__('Japanese')}</option>
<option value="ru">{__('Russian')}</option>
<option value="es">{__('Spanish')}</option>
<option value="id">{__('Indonesian')}</option>
<option value="fi">{__('Finnish')}</option>
<option value="kn">{__('Kannada')}</option>
<option value="it">{__('Italian')}</option>
<option value="nl">{__('Dutch')}</option>
<option value="tr">{__('Turkish')}</option>
<option value="pl">{__('Polish')}</option>
<option value="ms">{__('Malay')}</option>
<option value="pt">{__('Portuguese')}</option>
<option value="vi">{__('Vietnamese')}</option>
<option value="th">{__('Thai')}</option>
<option value="ar">{__('Arabic')}</option>
<option value="cs">{__('Czech')}</option>
<option value="hr">{__('Croatian')}</option>
<option value="km">{__('Khmer')}</option>
<option value="ko">{__('Korean')}</option>
<option value="no">{__('Norwegian')}</option>
<option value="ro">{__('Romanian')}</option>
<option value="hi">{__('Hindi')}</option>
<option value="el">{__('Greek')}</option>
</FormField>
label={__('Language')}
type="select"
name="content_language"
value={language}
onChange={event => updatePublishForm({ language: event.target.value })}
>
<option value="en">{__('English')}</option>
<option value="zh">{__('Chinese')}</option>
<option value="fr">{__('French')}</option>
<option value="de">{__('German')}</option>
<option value="jp">{__('Japanese')}</option>
<option value="ru">{__('Russian')}</option>
<option value="es">{__('Spanish')}</option>
<option value="id">{__('Indonesian')}</option>
<option value="fi">{__('Finnish')}</option>
<option value="kn">{__('Kannada')}</option>
<option value="it">{__('Italian')}</option>
<option value="nl">{__('Dutch')}</option>
<option value="tr">{__('Turkish')}</option>
<option value="pl">{__('Polish')}</option>
<option value="ms">{__('Malay')}</option>
<option value="pt">{__('Portuguese')}</option>
<option value="vi">{__('Vietnamese')}</option>
<option value="th">{__('Thai')}</option>
<option value="ar">{__('Arabic')}</option>
<option value="cs">{__('Czech')}</option>
<option value="hr">{__('Croatian')}</option>
<option value="km">{__('Khmer')}</option>
<option value="ko">{__('Korean')}</option>
<option value="no">{__('Norwegian')}</option>
<option value="ro">{__('Romanian')}</option>
<option value="hi">{__('Hindi')}</option>
<option value="el">{__('Greek')}</option>
</FormField>
<LicenseType
licenseType={licenseType}
otherLicenseDescription={otherLicenseDescription}
licenseUrl={licenseUrl}
handleLicenseChange={(newLicenseType, newLicenseUrl) =>
updatePublishForm({
licenseType: newLicenseType,
licenseUrl: newLicenseUrl,
})
}
handleLicenseDescriptionChange={event =>
updatePublishForm({
otherLicenseDescription: event.target.value,
})
}
handleLicenseUrlChange={event => updatePublishForm({ licenseUrl: event.target.value })}
/>
<LicenseType
licenseType={licenseType}
otherLicenseDescription={otherLicenseDescription}
licenseUrl={licenseUrl}
handleLicenseChange={(newLicenseType, newLicenseUrl) =>
updatePublishForm({
licenseType: newLicenseType,
licenseUrl: newLicenseUrl,
})
}
handleLicenseDescriptionChange={event =>
updatePublishForm({
otherLicenseDescription: event.target.value,
})
}
handleLicenseUrlChange={event => updatePublishForm({ licenseUrl: event.target.value })}
/>
</div>
</div>
)}
<div className="card__actions">
<div className="section__actions">
<Button
label={hideSection ? __('Additional Options') : __('Hide')}
button="link"

View file

@ -6391,9 +6391,9 @@ lbry-redux@lbryio/lbry-redux#67d8540ccc0fbedf018ae0bdfe3cae17660a5a6c:
reselect "^3.0.0"
uuid "^3.3.2"
lbryinc@lbryio/lbryinc#0f6fd2c33812fb1c1e393dd35b1a7560d3ba3fe2:
lbryinc@lbryio/lbryinc#cff5dd60934c4c6080e135f47ebbece1548c658c:
version "0.0.1"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/0f6fd2c33812fb1c1e393dd35b1a7560d3ba3fe2"
resolved "https://codeload.github.com/lbryio/lbryinc/tar.gz/cff5dd60934c4c6080e135f47ebbece1548c658c"
dependencies:
reselect "^3.0.0"