second attempt at localized player
This commit is contained in:
parent
f0d2298142
commit
1984ee585f
8 changed files with 88 additions and 1998 deletions
|
@ -2,7 +2,6 @@
|
||||||
/* eslint space-before-function-paren:0 */
|
/* eslint space-before-function-paren:0 */
|
||||||
// Module imports
|
// Module imports
|
||||||
import '@babel/polyfill';
|
import '@babel/polyfill';
|
||||||
import keytar from 'keytar';
|
|
||||||
import SemVer from 'semver';
|
import SemVer from 'semver';
|
||||||
import https from 'https';
|
import https from 'https';
|
||||||
import { app, dialog, ipcMain, session, shell } from 'electron';
|
import { app, dialog, ipcMain, session, shell } from 'electron';
|
||||||
|
@ -319,32 +318,6 @@ 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 => {
|
|
||||||
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 => {
|
process.on('uncaughtException', error => {
|
||||||
console.log(error);
|
console.log(error);
|
||||||
dialog.showErrorBox('Error Encountered', `Caught error: ${error}`);
|
dialog.showErrorBox('Error Encountered', `Caught error: ${error}`);
|
||||||
|
|
32
flow-typed/npm/keytar_vx.x.x.js
vendored
32
flow-typed/npm/keytar_vx.x.x.js
vendored
|
@ -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'>;
|
|
||||||
}
|
|
|
@ -51,8 +51,7 @@
|
||||||
"electron-notarize": "^0.1.1",
|
"electron-notarize": "^0.1.1",
|
||||||
"electron-updater": "^4.2.4",
|
"electron-updater": "^4.2.4",
|
||||||
"express": "^4.17.1",
|
"express": "^4.17.1",
|
||||||
"if-env": "^1.0.4",
|
"if-env": "^1.0.4"
|
||||||
"keytar": "^4.4.1"
|
|
||||||
},
|
},
|
||||||
"devDependencies": {
|
"devDependencies": {
|
||||||
"@babel/core": "^7.0.0",
|
"@babel/core": "^7.0.0",
|
||||||
|
@ -132,7 +131,7 @@
|
||||||
"json-loader": "^0.5.4",
|
"json-loader": "^0.5.4",
|
||||||
"lbry-format": "https://github.com/lbryio/lbry-format.git",
|
"lbry-format": "https://github.com/lbryio/lbry-format.git",
|
||||||
"lbry-redux": "lbryio/lbry-redux#6ed0dde5cbd7c25aa02631d5fa31fb6a4de76876",
|
"lbry-redux": "lbryio/lbry-redux#6ed0dde5cbd7c25aa02631d5fa31fb6a4de76876",
|
||||||
"lbryinc": "lbryio/lbryinc#275f35b31ec614e2b89689f860fe19e645deee68",
|
"lbryinc": "lbryio/lbryinc#1980f38cd4e799df9e259194ccf13abbdfc4cc40",
|
||||||
"lint-staged": "^7.0.2",
|
"lint-staged": "^7.0.2",
|
||||||
"localforage": "^1.7.1",
|
"localforage": "^1.7.1",
|
||||||
"lodash-es": "^4.17.14",
|
"lodash-es": "^4.17.14",
|
||||||
|
@ -210,7 +209,7 @@
|
||||||
"yarn": "^1.3"
|
"yarn": "^1.3"
|
||||||
},
|
},
|
||||||
"lbrySettings": {
|
"lbrySettings": {
|
||||||
"lbrynetDaemonVersion": "0.63.0",
|
"lbrynetDaemonVersion": "0.64.0",
|
||||||
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-OSNAME.zip",
|
"lbrynetDaemonUrlTemplate": "https://github.com/lbryio/lbry/releases/download/vDAEMONVER/lbrynet-OSNAME.zip",
|
||||||
"lbrynetDaemonDir": "static/daemon",
|
"lbrynetDaemonDir": "static/daemon",
|
||||||
"lbrynetDaemonFileName": "lbrynet"
|
"lbrynetDaemonFileName": "lbrynet"
|
||||||
|
|
|
@ -16,7 +16,7 @@ import FileSelector from 'component/common/file-selector';
|
||||||
import SyncToggle from 'component/syncToggle';
|
import SyncToggle from 'component/syncToggle';
|
||||||
import { SETTINGS } from 'lbry-redux';
|
import { SETTINGS } from 'lbry-redux';
|
||||||
import Card from 'component/common/card';
|
import Card from 'component/common/card';
|
||||||
import { getKeychainPassword } from 'util/saved-passwords';
|
import { getPasswordFromCookie } from 'util/saved-passwords';
|
||||||
|
|
||||||
// @if TARGET='app'
|
// @if TARGET='app'
|
||||||
export const IS_MAC = process.platform === 'darwin';
|
export const IS_MAC = process.platform === 'darwin';
|
||||||
|
@ -74,7 +74,7 @@ type Props = {
|
||||||
hideBalance: boolean,
|
hideBalance: boolean,
|
||||||
confirmForgetPassword: ({}) => void,
|
confirmForgetPassword: ({}) => void,
|
||||||
floatingPlayer: boolean,
|
floatingPlayer: boolean,
|
||||||
showReposts: boolean,
|
// showReposts: boolean,
|
||||||
clearPlayingUri: () => void,
|
clearPlayingUri: () => void,
|
||||||
darkModeTimes: DarkModeTimes,
|
darkModeTimes: DarkModeTimes,
|
||||||
setDarkTime: (string, {}) => void,
|
setDarkTime: (string, {}) => void,
|
||||||
|
@ -108,7 +108,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
||||||
const { isAuthenticated } = this.props;
|
const { isAuthenticated } = this.props;
|
||||||
if (isAuthenticated || !IS_WEB) {
|
if (isAuthenticated || !IS_WEB) {
|
||||||
this.props.updateWalletStatus();
|
this.props.updateWalletStatus();
|
||||||
getKeychainPassword().then(p => {
|
getPasswordFromCookie().then(p => {
|
||||||
if (typeof p === 'string') {
|
if (typeof p === 'string') {
|
||||||
this.setState({ storedPassword: true });
|
this.setState({ storedPassword: true });
|
||||||
}
|
}
|
||||||
|
@ -209,7 +209,7 @@ class SettingsPage extends React.PureComponent<Props, State> {
|
||||||
hideBalance,
|
hideBalance,
|
||||||
userBlockedChannelsCount,
|
userBlockedChannelsCount,
|
||||||
floatingPlayer,
|
floatingPlayer,
|
||||||
showReposts,
|
// showReposts,
|
||||||
clearPlayingUri,
|
clearPlayingUri,
|
||||||
darkModeTimes,
|
darkModeTimes,
|
||||||
clearCache,
|
clearCache,
|
||||||
|
|
|
@ -1,10 +1,35 @@
|
||||||
|
const { Lbryio } = require('lbryinc');
|
||||||
const { URL, LBRY_TV_STREAMING_API } = require('../../config');
|
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) {
|
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`;
|
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) {
|
function generateEmbedUrl(claimName, claimId) {
|
||||||
return `${URL}/$/embed/${claimName}/${claimId}`;
|
return `${URL}/$/embed/${claimName}/${claimId}`;
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,16 +1,13 @@
|
||||||
// @flow
|
const { DOMAIN } = require('../../config.js');
|
||||||
import { ipcRenderer } from 'electron';
|
|
||||||
|
|
||||||
const AUTH_TOKEN = 'auth_token';
|
const AUTH_TOKEN = 'auth_token';
|
||||||
const SAVED_PASSWORD = 'saved_password';
|
const SAVED_PASSWORD = 'saved_password';
|
||||||
const DEPRECATED_SAVED_PASSWORD = 'saved-password';
|
const DEPRECATED_SAVED_PASSWORD = 'saved-password';
|
||||||
|
const domain = typeof window === 'object' ? window.location.hostname : DOMAIN;
|
||||||
const domain = window.location.hostname;
|
|
||||||
const isProduction = process.env.NODE_ENV === 'production';
|
const isProduction = process.env.NODE_ENV === 'production';
|
||||||
const maxExpiration = 2147483647;
|
const maxExpiration = 2147483647;
|
||||||
let sessionPassword;
|
let sessionPassword;
|
||||||
|
|
||||||
function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
|
function setCookie(name, value, expirationDaysOnWeb) {
|
||||||
let expires = '';
|
let expires = '';
|
||||||
if (expirationDaysOnWeb) {
|
if (expirationDaysOnWeb) {
|
||||||
let date = new Date();
|
let date = new Date();
|
||||||
|
@ -27,7 +24,7 @@ function setCookie(name: string, value: string, expirationDaysOnWeb: number) {
|
||||||
document.cookie = cookie;
|
document.cookie = cookie;
|
||||||
}
|
}
|
||||||
|
|
||||||
function getCookie(name: string) {
|
function getCookie(name) {
|
||||||
const nameEQ = name + '=';
|
const nameEQ = name + '=';
|
||||||
const cookies = document.cookie.split(';');
|
const cookies = document.cookie.split(';');
|
||||||
|
|
||||||
|
@ -44,7 +41,7 @@ function getCookie(name: string) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
function deleteCookie(name: string) {
|
function deleteCookie(name) {
|
||||||
document.cookie = name + `=; Max-Age=-99999999; domain=${domain}; path=/;`;
|
document.cookie = name + `=; Max-Age=-99999999; domain=${domain}; path=/;`;
|
||||||
|
|
||||||
// Legacy
|
// Legacy
|
||||||
|
@ -54,8 +51,8 @@ function deleteCookie(name: string) {
|
||||||
document.cookie = name + `=; Max-Age=-99999999; domain=.${domain}; path=/;`;
|
document.cookie = name + `=; Max-Age=-99999999; domain=.${domain}; path=/;`;
|
||||||
}
|
}
|
||||||
|
|
||||||
export const setSavedPassword = (value?: string, saveToDisk: boolean) => {
|
function setSavedPassword(value, saveToDisk) {
|
||||||
return new Promise<*>(resolve => {
|
return new Promise(resolve => {
|
||||||
const password = value === undefined || value === null ? '' : value;
|
const password = value === undefined || value === null ? '' : value;
|
||||||
sessionPassword = password;
|
sessionPassword = password;
|
||||||
|
|
||||||
|
@ -67,97 +64,84 @@ export const setSavedPassword = (value?: string, saveToDisk: boolean) => {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getSavedPassword = () => {
|
function getSavedPassword() {
|
||||||
return new Promise<*>(resolve => {
|
return new Promise(resolve => {
|
||||||
if (sessionPassword) {
|
if (sessionPassword) {
|
||||||
resolve(sessionPassword);
|
resolve(sessionPassword);
|
||||||
}
|
}
|
||||||
|
|
||||||
return getKeychainPassword().then(p => resolve(p));
|
return getPasswordFromCookie().then(p => resolve(p));
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getKeychainPassword = () => {
|
function getPasswordFromCookie() {
|
||||||
return new Promise<*>(resolve => {
|
return new Promise(resolve => {
|
||||||
let password;
|
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);
|
password = getCookie(SAVED_PASSWORD);
|
||||||
resolve(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');
|
function deleteSavedPassword() {
|
||||||
}
|
return new Promise(resolve => {
|
||||||
// @endif
|
|
||||||
});
|
|
||||||
};
|
|
||||||
|
|
||||||
export const deleteSavedPassword = () => {
|
|
||||||
return new Promise<*>(resolve => {
|
|
||||||
deleteCookie(SAVED_PASSWORD);
|
deleteCookie(SAVED_PASSWORD);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
export const getAuthToken = () => {
|
function getAuthToken() {
|
||||||
return getCookie(AUTH_TOKEN);
|
return getCookie(AUTH_TOKEN);
|
||||||
};
|
}
|
||||||
|
|
||||||
export const setAuthToken = (value: string) => {
|
function setAuthToken(value) {
|
||||||
return setCookie(AUTH_TOKEN, value, 365);
|
return setCookie(AUTH_TOKEN, value, 365);
|
||||||
};
|
}
|
||||||
|
|
||||||
export const deleteAuthToken = () => {
|
function deleteAuthToken() {
|
||||||
return new Promise<*>(resolve => {
|
return new Promise(resolve => {
|
||||||
deleteCookie(AUTH_TOKEN);
|
deleteCookie(AUTH_TOKEN);
|
||||||
resolve();
|
resolve();
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
export const doSignOutCleanup = () => {
|
function doSignOutCleanup() {
|
||||||
return new Promise<*>(resolve => {
|
return new Promise(resolve => {
|
||||||
deleteAuthToken();
|
deleteAuthToken();
|
||||||
deleteSavedPassword();
|
deleteSavedPassword();
|
||||||
resolve();
|
resolve();
|
||||||
|
|
||||||
// @if TARGET='app'
|
|
||||||
ipcRenderer.send('delete-auth-token');
|
|
||||||
ipcRenderer.send('delete-password');
|
|
||||||
// @endif;
|
|
||||||
});
|
});
|
||||||
};
|
}
|
||||||
|
|
||||||
export const doAuthTokenRefresh = () => {
|
function doAuthTokenRefresh() {
|
||||||
const authToken = getAuthToken();
|
const authToken = getAuthToken();
|
||||||
if (authToken) {
|
if (authToken) {
|
||||||
deleteAuthToken();
|
deleteAuthToken();
|
||||||
setAuthToken(authToken);
|
setAuthToken(authToken);
|
||||||
}
|
}
|
||||||
};
|
}
|
||||||
|
|
||||||
export const doDeprecatedPasswordMigrationMarch2020 = () => {
|
function doDeprecatedPasswordMigrationMarch2020() {
|
||||||
const savedPassword = getCookie(DEPRECATED_SAVED_PASSWORD);
|
const savedPassword = getCookie(DEPRECATED_SAVED_PASSWORD);
|
||||||
if (savedPassword) {
|
if (savedPassword) {
|
||||||
deleteCookie(DEPRECATED_SAVED_PASSWORD);
|
deleteCookie(DEPRECATED_SAVED_PASSWORD);
|
||||||
setSavedPassword(savedPassword, true);
|
setSavedPassword(savedPassword, true);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = {
|
||||||
|
setCookie,
|
||||||
|
getCookie,
|
||||||
|
deleteCookie,
|
||||||
|
setSavedPassword,
|
||||||
|
getSavedPassword,
|
||||||
|
getPasswordFromCookie,
|
||||||
|
deleteSavedPassword,
|
||||||
|
getAuthToken,
|
||||||
|
setAuthToken,
|
||||||
|
deleteAuthToken,
|
||||||
|
doSignOutCleanup,
|
||||||
|
doAuthTokenRefresh,
|
||||||
|
doDeprecatedPasswordMigrationMarch2020,
|
||||||
};
|
};
|
||||||
|
|
|
@ -64,7 +64,6 @@ if (process.env.NODE_ENV === 'production') {
|
||||||
// Apply prod overrides
|
// Apply prod overrides
|
||||||
mainConfig = merge(mainConfig, {
|
mainConfig = merge(mainConfig, {
|
||||||
externals: {
|
externals: {
|
||||||
keytar: 'require("keytar")',
|
|
||||||
electron: 'require("electron")',
|
electron: 'require("electron")',
|
||||||
express: 'require("express")',
|
express: 'require("express")',
|
||||||
'electron-updater': 'require("electron-updater")',
|
'electron-updater': 'require("electron-updater")',
|
||||||
|
@ -75,7 +74,6 @@ if (process.env.NODE_ENV === 'production') {
|
||||||
// Apply dev overrides
|
// Apply dev overrides
|
||||||
mainConfig = merge(mainConfig, {
|
mainConfig = merge(mainConfig, {
|
||||||
externals: {
|
externals: {
|
||||||
keytar: 'require("keytar")',
|
|
||||||
electron: 'require("electron")',
|
electron: 'require("electron")',
|
||||||
express: 'require("express")',
|
express: 'require("express")',
|
||||||
'electron-updater': 'require("electron-updater")',
|
'electron-updater': 'require("electron-updater")',
|
||||||
|
|
Loading…
Reference in a new issue