feat: app image + cookie

fix: password stuff
This commit is contained in:
Thomas Zarebczan 2020-01-14 23:34:28 -05:00 committed by Sean Yesmunt
parent d256d9eac1
commit 939a7d7689
9 changed files with 39 additions and 68 deletions

View file

@ -50,7 +50,7 @@ addons:
artifacts: artifacts:
working_dir: dist working_dir: dist
paths: paths:
- $(git ls-files -o dist/{*.dmg,*.exe,*.deb} | tr "\n" ":") - $(git ls-files -o dist/{*.dmg,*.exe,*.deb,*.AppImage} | tr "\n" ":")
target_paths: target_paths:
- '/app/build-${TRAVIS_BUILD_NUMBER}_commit-${TRAVIS_COMMIT:0:7}$([ ! -z ${TRAVIS_TAG} - '/app/build-${TRAVIS_BUILD_NUMBER}_commit-${TRAVIS_COMMIT:0:7}$([ ! -z ${TRAVIS_TAG}
] && echo _tag-${TRAVIS_TAG})' ] && echo _tag-${TRAVIS_TAG})'

View file

@ -73,7 +73,7 @@
} }
], ],
"linux": { "linux": {
"target": "deb", "target": ["AppImage", "deb"],
"executableName": "lbry", "executableName": "lbry",
"category": "AudioVideo;Video", "category": "AudioVideo;Video",
"desktop": { "desktop": {

View file

@ -318,17 +318,14 @@ ipcMain.on('version-info-requested', () => {
requestLatestRelease(); requestLatestRelease();
}); });
// In a few months, we can remove the keytar dependency and below calls once
// enough users have moved over to cookies
ipcMain.on('get-auth-token', event => { ipcMain.on('get-auth-token', event => {
keytar.getPassword('LBRY', 'auth_token').then(token => { keytar.getPassword('LBRY', 'auth_token').then(token => {
event.sender.send('auth-token-response', token ? token.toString().trim() : null); event.sender.send('auth-token-response', token ? token.toString().trim() : null);
}); });
}); });
ipcMain.on('set-auth-token', (event, token) => {
keytar.setPassword('LBRY', 'auth_token', token ? token.toString().trim() : null);
});
ipcMain.on('delete-auth-token', (event, password) => { ipcMain.on('delete-auth-token', (event, password) => {
keytar.deletePassword('LBRY', 'auth_token', password).then(res => { keytar.deletePassword('LBRY', 'auth_token', password).then(res => {
event.sender.send('delete-auth-token-response', res); event.sender.send('delete-auth-token-response', res);

View file

@ -109,10 +109,6 @@ Lbryio.setOverride(
authToken = response.auth_token; authToken = response.auth_token;
setAuthToken(authToken); setAuthToken(authToken);
// @if TARGET='app'
ipcRenderer.send('set-auth-token', authToken);
// @endif
resolve(authToken); resolve(authToken);
}); });
}) })
@ -123,6 +119,10 @@ Lbryio.setOverride(
() => () =>
new Promise(resolve => { new Promise(resolve => {
// @if TARGET='app' // @if TARGET='app'
// NEED TO DO SOMETHING HERE TO CHECK FOR A COOKIE AUTH TOKEN.
// IF IT EXISTS, SKIP AND CONTINUE BELOW THE @ENDIF
// IF NOT, COPY THE KEYTAR AUTH TOKEN AND PASSWORD TO THE COOKIE (SetAuthToken/SetPassword?)
// AND THEN DELETE KEYTAR ONE (Or leave for now?)
if (authToken) { if (authToken) {
resolve(authToken); resolve(authToken);
} }
@ -135,7 +135,6 @@ Lbryio.setOverride(
ipcRenderer.send('get-auth-token'); ipcRenderer.send('get-auth-token');
// @endif // @endif
// @if TARGET='web'
const authTokenToReturn = authToken || getAuthToken(); const authTokenToReturn = authToken || getAuthToken();
if (authTokenToReturn !== null) { if (authTokenToReturn !== null) {
@ -143,7 +142,6 @@ Lbryio.setOverride(
} }
resolve(authTokenToReturn); resolve(authTokenToReturn);
// @endif
}) })
); );
@ -245,7 +243,7 @@ function AppWrapper() {
console.error(error.message); // eslint-disable-line no-console console.error(error.message); // eslint-disable-line no-console
}); });
if (['win32', 'darwin'].includes(process.platform)) { if (['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE) {
autoUpdater.on('update-available', () => { autoUpdater.on('update-available', () => {
console.log('Update available'); // eslint-disable-line no-console console.log('Update available'); // eslint-disable-line no-console
}); });

View file

@ -33,6 +33,12 @@ class ModalDownloading extends React.PureComponent<Props> {
</p> </p>
<blockquote>sudo dpkg -i {downloadItem}</blockquote> <blockquote>sudo dpkg -i {downloadItem}</blockquote>
<p>{__('After the install is complete, please reopen the app.')}</p> <p>{__('After the install is complete, please reopen the app.')}</p>
<p>
{__('Note: You can also install the AppImage version for streamlined updates.')}{' '}
<span style={{ whiteSpace: 'nowrap' }}>
<Button button="link" label={__('Download here.')} href="https://lbry.com/get/lbry.AppImage" />
</span>
</p>
</React.Fragment> </React.Fragment>
) : null} ) : null}

View file

@ -111,6 +111,9 @@ class HelpPage extends React.PureComponent<Props, State> {
platform = `${osName} ${ver.os_release}`; platform = `${osName} ${ver.os_release}`;
newVerLink = 'https://lbry.com/get/lbry.dmg'; newVerLink = 'https://lbry.com/get/lbry.dmg';
} else if (process.env.APPIMAGE !== undefined) {
platform = `Linux (AppImage)`;
newVerLink = 'https://lbry.com/get/lbry.AppImage';
} else if (ver.os_system === 'Linux') { } else if (ver.os_system === 'Linux') {
platform = `Linux (${ver.platform})`; platform = `Linux (${ver.platform})`;
newVerLink = 'https://lbry.com/get/lbry.deb'; newVerLink = 'https://lbry.com/get/lbry.deb';

View file

@ -103,7 +103,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
componentDidMount() { componentDidMount() {
const { isAuthenticated } = this.props; const { isAuthenticated } = this.props;
if (isAuthenticated) { if (isAuthenticated || !IS_WEB) {
this.props.updateWalletStatus(); this.props.updateWalletStatus();
getKeychainPassword().then(p => { getKeychainPassword().then(p => {
if (typeof p === 'string') { if (typeof p === 'string') {
@ -416,7 +416,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
} }
/> />
{isAuthenticated && ( {(isAuthenticated || !IS_WEB) && (
<Card <Card
title={__('Blocked Channels')} title={__('Blocked Channels')}
actions={ actions={

View file

@ -130,7 +130,7 @@ export function doDownloadUpgradeRequested() {
// the old logic. // the old logic.
return dispatch => { return dispatch => {
if (['win32', 'darwin'].includes(process.platform)) { if (['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE) {
// electron-updater behavior // electron-updater behavior
dispatch(doOpenModal(MODALS.AUTO_UPDATE_DOWNLOADED)); dispatch(doOpenModal(MODALS.AUTO_UPDATE_DOWNLOADED));
} else { } else {
@ -204,8 +204,8 @@ export function doCheckUpgradeAvailable() {
type: ACTIONS.CHECK_UPGRADE_START, type: ACTIONS.CHECK_UPGRADE_START,
}); });
if (['win32', 'darwin'].includes(process.platform)) { if (['win32', 'darwin'].includes(process.platform) || !!process.env.APPIMAGE) {
// On Windows and Mac, updates happen silently through // On Windows, Mac, and AppImage, updates happen silently through
// electron-updater. // electron-updater.
const autoUpdateDeclined = selectAutoUpdateDeclined(state); const autoUpdateDeclined = selectAutoUpdateDeclined(state);

View file

@ -3,6 +3,7 @@ import { ipcRenderer } from 'electron';
import { DOMAIN } from 'config'; import { DOMAIN } from 'config';
const isProduction = process.env.NODE_ENV === 'production'; const isProduction = process.env.NODE_ENV === 'production';
const maxExpiration = 2147483647;
let sessionPassword; let sessionPassword;
function setCookie(name: string, value: string, days: number) { function setCookie(name: string, value: string, days: number) {
@ -10,7 +11,8 @@ function setCookie(name: string, value: string, days: number) {
if (days) { if (days) {
let date = new Date(); let date = new Date();
date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000); date.setTime(date.getTime() + days * 24 * 60 * 60 * 1000);
expires = `expires=${date.toUTCString()};`; // If on PC, set to not expire (max)
expires = `expires=${IS_WEB ? date.toUTCString() : maxExpiration};`;
} }
let cookie = `${name}=${value || ''}; ${expires} path=/; SameSite=Lax;`; let cookie = `${name}=${value || ''}; ${expires} path=/; SameSite=Lax;`;
@ -49,23 +51,12 @@ function deleteCookie(name: string) {
export const setSavedPassword = (value?: string, saveToDisk: boolean) => { export const setSavedPassword = (value?: string, saveToDisk: boolean) => {
return new Promise<*>(resolve => { return new Promise<*>(resolve => {
// @if TARGET='app'
ipcRenderer.once('set-password-response', (event, success) => {
resolve(success);
});
// @endif
const password = value === undefined || value === null ? '' : value; const password = value === undefined || value === null ? '' : value;
sessionPassword = password; sessionPassword = password;
if (saveToDisk) { if (saveToDisk) {
if (password) { if (password) {
// @if TARGET='app'
ipcRenderer.send('set-password', password);
// @endif
// @if TARGET='web'
setCookie('saved-password', password, 14); setCookie('saved-password', password, 14);
// @endif
} else { } else {
deleteSavedPassword(); deleteSavedPassword();
} }
@ -85,32 +76,28 @@ export const getSavedPassword = () => {
export const getKeychainPassword = () => { export const getKeychainPassword = () => {
return new Promise<*>(resolve => { return new Promise<*>(resolve => {
// @if TARGET='app' const password = getCookie('saved-password');
if (password) {
resolve(password);
}
// We can remove this when we remove keytar
else {
ipcRenderer.once('get-password-response', (event, password) => { ipcRenderer.once('get-password-response', (event, password) => {
resolve(password); resolve(password);
}); });
ipcRenderer.send('get-password'); ipcRenderer.send('get-password');
// @endif }
// @if TARGET='app'
// @if TARGET='web'
const password = getCookie('saved-password');
resolve(password);
// @endif // @endif
}); });
}; };
export const deleteSavedPassword = () => { export const deleteSavedPassword = () => {
return new Promise<*>(resolve => { return new Promise<*>(resolve => {
// @if TARGET='app'
ipcRenderer.once('delete-password-response', (event, success) => {
resolve();
});
ipcRenderer.send('delete-password');
// @endif;
// @if TARGET='web'
deleteCookie('saved-password'); deleteCookie('saved-password');
resolve(); resolve();
// @endif
}); });
}; };
@ -125,36 +112,16 @@ export const setAuthToken = (value: string) => {
export const deleteAuthToken = () => { export const deleteAuthToken = () => {
return new Promise<*>(resolve => { return new Promise<*>(resolve => {
deleteCookie('auth_token'); deleteCookie('auth_token');
// @if TARGET='app'
ipcRenderer.once('delete-auth-token-response', (event, success) => {
resolve(); resolve();
}); });
ipcRenderer.send('delete-auth-token');
// @endif;
// @if TARGET='web'
resolve();
// @endif
});
}; };
export const doSignOutCleanup = () => { export const doSignOutCleanup = () => {
return new Promise<*>(resolve => { return new Promise<*>(resolve => {
deleteCookie('auth_token'); deleteCookie('auth_token');
deleteCookie('saved-password'); deleteCookie('saved-password');
// @if TARGET='app'
ipcRenderer.once('delete-auth-token-response', (event, success) => {
resolve(); resolve();
}); });
ipcRenderer.send('delete-auth-token');
// @endif;
// @if TARGET='web'
resolve();
// @endif
});
}; };
export const testKeychain = () => { export const testKeychain = () => {