second attempt at localized player

This commit is contained in:
seanyesmunt 2020-03-17 14:58:34 -04:00 committed by Sean Yesmunt
parent f0d2298142
commit 1984ee585f
8 changed files with 88 additions and 1998 deletions

View file

@ -2,7 +2,6 @@
/* eslint space-before-function-paren:0 */
// Module imports
import '@babel/polyfill';
import keytar from 'keytar';
import SemVer from 'semver';
import https from 'https';
import { app, dialog, ipcMain, session, shell } from 'electron';
@ -319,32 +318,6 @@ ipcMain.on('version-info-requested', () => {
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 => {
keytar.getPassword('LBRY', 'auth_token').then(token => {
event.sender.send('auth-token-response', token ? token.toString().trim() : null);
});
});
ipcMain.on('delete-auth-token', (event, password) => {
keytar.deletePassword('LBRY', 'auth_token', password).then(res => {
event.sender.send('delete-auth-token-response', res);
});
});
ipcMain.on('get-password', event => {
keytar.getPassword('LBRY', 'wallet_password').then(password => {
event.sender.send('get-password-response', password ? password.toString() : null);
});
});
ipcMain.on('delete-password', event => {
keytar.deletePassword('LBRY', 'wallet_password').then(res => {
event.sender.send('delete-password-response', res);
});
});
process.on('uncaughtException', error => {
console.log(error);
dialog.showErrorBox('Error Encountered', `Caught error: ${error}`);

View file

@ -1,32 +0,0 @@
// flow-typed signature: 33d904b96c8747ed8b41b631dd56dbab
// flow-typed version: <<STUB>>/keytar_v4.4.1/flow_v0.94.0
/**
* This is an autogenerated libdef stub for:
*
* 'keytar'
*
* Fill this stub out by replacing all the `any` types.
*
* Once filled out, we encourage you to share your work with the
* community by sending a pull request to:
* https://github.com/flowtype/flow-typed
*/
declare module 'keytar' {
declare module.exports: any;
}
/**
* We include stubs for each file inside this npm package in case you need to
* require those files directly. Feel free to delete any files that aren't
* needed.
*/
declare module 'keytar/lib/keytar' {
declare module.exports: any;
}
// Filename aliases
declare module 'keytar/lib/keytar.js' {
declare module.exports: $Exports<'keytar/lib/keytar'>;
}

View file

@ -51,8 +51,7 @@
"electron-notarize": "^0.1.1",
"electron-updater": "^4.2.4",
"express": "^4.17.1",
"if-env": "^1.0.4",
"keytar": "^4.4.1"
"if-env": "^1.0.4"
},
"devDependencies": {
"@babel/core": "^7.0.0",
@ -132,7 +131,7 @@
"json-loader": "^0.5.4",
"lbry-format": "https://github.com/lbryio/lbry-format.git",
"lbry-redux": "lbryio/lbry-redux#6ed0dde5cbd7c25aa02631d5fa31fb6a4de76876",
"lbryinc": "lbryio/lbryinc#275f35b31ec614e2b89689f860fe19e645deee68",
"lbryinc": "lbryio/lbryinc#1980f38cd4e799df9e259194ccf13abbdfc4cc40",
"lint-staged": "^7.0.2",
"localforage": "^1.7.1",
"lodash-es": "^4.17.14",
@ -210,7 +209,7 @@
"yarn": "^1.3"
},
"lbrySettings": {
"lbrynetDaemonVersion": "0.63.0",
"lbrynetDaemonVersion": "0.64.0",
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-OSNAME.zip",
"lbrynetDaemonDir": "static/daemon",
"lbrynetDaemonFileName": "lbrynet"

View file

@ -16,7 +16,7 @@ import FileSelector from 'component/common/file-selector';
import SyncToggle from 'component/syncToggle';
import { SETTINGS } from 'lbry-redux';
import Card from 'component/common/card';
import { getKeychainPassword } from 'util/saved-passwords';
import { getPasswordFromCookie } from 'util/saved-passwords';
// @if TARGET='app'
export const IS_MAC = process.platform === 'darwin';
@ -74,7 +74,7 @@ type Props = {
hideBalance: boolean,
confirmForgetPassword: ({}) => void,
floatingPlayer: boolean,
showReposts: boolean,
// showReposts: boolean,
clearPlayingUri: () => void,
darkModeTimes: DarkModeTimes,
setDarkTime: (string, {}) => void,
@ -108,7 +108,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
const { isAuthenticated } = this.props;
if (isAuthenticated || !IS_WEB) {
this.props.updateWalletStatus();
getKeychainPassword().then(p => {
getPasswordFromCookie().then(p => {
if (typeof p === 'string') {
this.setState({ storedPassword: true });
}
@ -209,7 +209,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
hideBalance,
userBlockedChannelsCount,
floatingPlayer,
showReposts,
// showReposts,
clearPlayingUri,
darkModeTimes,
clearCache,

View file

@ -1,10 +1,35 @@
const { Lbryio } = require('lbryinc');
const { URL, LBRY_TV_STREAMING_API } = require('../../config');
const { getCookie, setCookie } = require('../../ui/util/saved-passwords');
const CONTINENT_COOKIE = 'continent';
function generateStreamUrl(claimName, claimId, apiUrl) {
const prefix = LBRY_TV_STREAMING_API || apiUrl;
let prefix = LBRY_TV_STREAMING_API || apiUrl;
const continent = getCookie(CONTINENT_COOKIE);
if (continent && prefix.split('//').length > 1) {
prefix = prefix.replace('//', '//' + continent + '.');
} else {
Lbryio.call('locale', 'get', {}, 'post').then(result => {
const userContinent = getSupportedCDN(result.continent);
setCookie(CONTINENT_COOKIE, userContinent, 1);
});
}
return `${prefix}/content/claims/${claimName}/${claimId}/stream`;
}
function getSupportedCDN(continent) {
switch (continent) {
case 'NA':
case 'EU':
return continent;
default:
return 'NA';
}
}
function generateEmbedUrl(claimName, claimId) {
return `${URL}/$/embed/${claimName}/${claimId}`;
}

View file

@ -1,16 +1,13 @@
// @flow
import { ipcRenderer } from 'electron';
const { DOMAIN } = require('../../config.js');
const AUTH_TOKEN = 'auth_token';
const SAVED_PASSWORD = 'saved_password';
const DEPRECATED_SAVED_PASSWORD = 'saved-password';
const domain = window.location.hostname;
const domain = typeof window === 'object' ? window.location.hostname : DOMAIN;
const isProduction = process.env.NODE_ENV === 'production';
const maxExpiration = 2147483647;
let sessionPassword;
function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
function setCookie(name, value, expirationDaysOnWeb) {
let expires = '';
if (expirationDaysOnWeb) {
let date = new Date();
@ -27,7 +24,7 @@ function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
document.cookie = cookie;
}
function getCookie(name: string) {
function getCookie(name) {
const nameEQ = name + '=';
const cookies = document.cookie.split(';');
@ -44,7 +41,7 @@ function getCookie(name: string) {
return null;
}
function deleteCookie(name: string) {
function deleteCookie(name) {
document.cookie = name + `=; Max-Age=-99999999; domain=${domain}; path=/;`;
// Legacy
@ -54,8 +51,8 @@ function deleteCookie(name: string) {
document.cookie = name + `=; Max-Age=-99999999; domain=.${domain}; path=/;`;
}
export const setSavedPassword = (value?: string, saveToDisk: boolean) => {
return new Promise<*>(resolve => {
function setSavedPassword(value, saveToDisk) {
return new Promise(resolve => {
const password = value === undefined || value === null ? '' : value;
sessionPassword = password;
@ -67,97 +64,84 @@ export const setSavedPassword = (value?: string, saveToDisk: boolean) => {
}
}
});
};
}
export const getSavedPassword = () => {
return new Promise<*>(resolve => {
function getSavedPassword() {
return new Promise(resolve => {
if (sessionPassword) {
resolve(sessionPassword);
}
return getKeychainPassword().then(p => resolve(p));
return getPasswordFromCookie().then(p => resolve(p));
});
};
}
export const getKeychainPassword = () => {
return new Promise<*>(resolve => {
function getPasswordFromCookie() {
return new Promise(resolve => {
let password;
// @if TARGET='web'
// In the future, this will be the only code in this function
// Handling keytar stuff separately so we can easily rip it out later
password = getCookie(SAVED_PASSWORD);
resolve(password);
// @endif
// @if TARGET='app'
password = getCookie(SAVED_PASSWORD);
if (password) {
resolve(password);
} else {
// No password saved in a cookie, get it from the keychain, then delete the value in the keychain
ipcRenderer.once('get-password-response', (event, keychainPassword) => {
resolve(keychainPassword);
if (keychainPassword) {
setSavedPassword(keychainPassword, true);
ipcRenderer.send('delete-password');
}
});
ipcRenderer.send('get-password');
}
// @endif
});
};
}
export const deleteSavedPassword = () => {
return new Promise<*>(resolve => {
function deleteSavedPassword() {
return new Promise(resolve => {
deleteCookie(SAVED_PASSWORD);
resolve();
});
};
}
export const getAuthToken = () => {
function getAuthToken() {
return getCookie(AUTH_TOKEN);
};
}
export const setAuthToken = (value: string) => {
function setAuthToken(value) {
return setCookie(AUTH_TOKEN, value, 365);
};
}
export const deleteAuthToken = () => {
return new Promise<*>(resolve => {
function deleteAuthToken() {
return new Promise(resolve => {
deleteCookie(AUTH_TOKEN);
resolve();
});
};
}
export const doSignOutCleanup = () => {
return new Promise<*>(resolve => {
function doSignOutCleanup() {
return new Promise(resolve => {
deleteAuthToken();
deleteSavedPassword();
resolve();
// @if TARGET='app'
ipcRenderer.send('delete-auth-token');
ipcRenderer.send('delete-password');
// @endif;
});
};
}
export const doAuthTokenRefresh = () => {
function doAuthTokenRefresh() {
const authToken = getAuthToken();
if (authToken) {
deleteAuthToken();
setAuthToken(authToken);
}
};
}
export const doDeprecatedPasswordMigrationMarch2020 = () => {
function doDeprecatedPasswordMigrationMarch2020() {
const savedPassword = getCookie(DEPRECATED_SAVED_PASSWORD);
if (savedPassword) {
deleteCookie(DEPRECATED_SAVED_PASSWORD);
setSavedPassword(savedPassword, true);
}
}
module.exports = {
setCookie,
getCookie,
deleteCookie,
setSavedPassword,
getSavedPassword,
getPasswordFromCookie,
deleteSavedPassword,
getAuthToken,
setAuthToken,
deleteAuthToken,
doSignOutCleanup,
doAuthTokenRefresh,
doDeprecatedPasswordMigrationMarch2020,
};

View file

@ -64,7 +64,6 @@ if (process.env.NODE_ENV === 'production') {
// Apply prod overrides
mainConfig = merge(mainConfig, {
externals: {
keytar: 'require("keytar")',
electron: 'require("electron")',
express: 'require("express")',
'electron-updater': 'require("electron-updater")',
@ -75,7 +74,6 @@ if (process.env.NODE_ENV === 'production') {
// Apply dev overrides
mainConfig = merge(mainConfig, {
externals: {
keytar: 'require("keytar")',
electron: 'require("electron")',
express: 'require("express")',
'electron-updater': 'require("electron-updater")',

1873
yarn.lock

File diff suppressed because it is too large Load diff