finally killed client settings in lbry.js
This commit is contained in:
parent
145e4c8b97
commit
767630a985
6 changed files with 29 additions and 104 deletions
|
@ -3,6 +3,7 @@ import * as settings from "constants/settings";
|
||||||
import lbry from "lbry";
|
import lbry from "lbry";
|
||||||
import lbryio from "lbryio";
|
import lbryio from "lbryio";
|
||||||
import lbryuri from "lbryuri";
|
import lbryuri from "lbryuri";
|
||||||
|
import { makeSelectClientSetting } from "selectors/settings";
|
||||||
import { selectBalance } from "selectors/wallet";
|
import { selectBalance } from "selectors/wallet";
|
||||||
import {
|
import {
|
||||||
makeSelectFileInfoForUri,
|
makeSelectFileInfoForUri,
|
||||||
|
@ -360,13 +361,13 @@ export function doPurchaseUri(uri) {
|
||||||
|
|
||||||
if (
|
if (
|
||||||
cost == 0 ||
|
cost == 0 ||
|
||||||
!lbry.getClientSetting(settings.INSTANT_PURCHASE_ENABLED)
|
!makeSelectClientSetting(settings.INSTANT_PURCHASE_ENABLED)(state)
|
||||||
) {
|
) {
|
||||||
attemptPlay(cost);
|
attemptPlay(cost);
|
||||||
} else {
|
} else {
|
||||||
const instantPurchaseMax = lbry.getClientSetting(
|
const instantPurchaseMax = makeSelectClientSetting(
|
||||||
settings.INSTANT_PURCHASE_MAX
|
settings.INSTANT_PURCHASE_MAX
|
||||||
);
|
)(state);
|
||||||
if (instantPurchaseMax.currency == "LBC") {
|
if (instantPurchaseMax.currency == "LBC") {
|
||||||
attemptPlay(cost, instantPurchaseMax.amount);
|
attemptPlay(cost, instantPurchaseMax.amount);
|
||||||
} else {
|
} else {
|
||||||
|
|
|
@ -41,8 +41,6 @@ export function doSetDaemonSetting(key, value) {
|
||||||
}
|
}
|
||||||
|
|
||||||
export function doSetClientSetting(key, value) {
|
export function doSetClientSetting(key, value) {
|
||||||
lbry.setClientSetting(key, value);
|
|
||||||
|
|
||||||
return {
|
return {
|
||||||
type: types.CLIENT_SETTING_CHANGED,
|
type: types.CLIENT_SETTING_CHANGED,
|
||||||
data: {
|
data: {
|
||||||
|
|
|
@ -1,11 +1,6 @@
|
||||||
import lighthouse from "./lighthouse.js";
|
|
||||||
import jsonrpc from "./jsonrpc.js";
|
import jsonrpc from "./jsonrpc.js";
|
||||||
import lbryuri from "./lbryuri.js";
|
import lbryuri from "./lbryuri.js";
|
||||||
|
|
||||||
/**
|
|
||||||
* The 4 get/set functions below used to be in a utils.js library when used more widely.
|
|
||||||
* They've been reduced to just this file and probably ought to be eliminated entirely.
|
|
||||||
*/
|
|
||||||
function getLocal(key, fallback = undefined) {
|
function getLocal(key, fallback = undefined) {
|
||||||
const itemRaw = localStorage.getItem(key);
|
const itemRaw = localStorage.getItem(key);
|
||||||
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
||||||
|
@ -15,15 +10,6 @@ function setLocal(key, value) {
|
||||||
localStorage.setItem(key, JSON.stringify(value));
|
localStorage.setItem(key, JSON.stringify(value));
|
||||||
}
|
}
|
||||||
|
|
||||||
function getSession(key, fallback = undefined) {
|
|
||||||
const itemRaw = sessionStorage.getItem(key);
|
|
||||||
return itemRaw === null ? fallback : JSON.parse(itemRaw);
|
|
||||||
}
|
|
||||||
|
|
||||||
function setSession(key, value) {
|
|
||||||
sessionStorage.setItem(key, JSON.stringify(value));
|
|
||||||
}
|
|
||||||
|
|
||||||
const { remote, ipcRenderer } = require("electron");
|
const { remote, ipcRenderer } = require("electron");
|
||||||
const menu = remote.require("./menu/main-menu");
|
const menu = remote.require("./menu/main-menu");
|
||||||
|
|
||||||
|
@ -31,19 +17,6 @@ let lbry = {
|
||||||
isConnected: false,
|
isConnected: false,
|
||||||
daemonConnectionString: "http://localhost:5279",
|
daemonConnectionString: "http://localhost:5279",
|
||||||
pendingPublishTimeout: 20 * 60 * 1000,
|
pendingPublishTimeout: 20 * 60 * 1000,
|
||||||
defaultClientSettings: {
|
|
||||||
showNsfw: false,
|
|
||||||
showUnavailable: true,
|
|
||||||
debug: false,
|
|
||||||
useCustomLighthouseServers: false,
|
|
||||||
customLighthouseServers: [],
|
|
||||||
language: "en",
|
|
||||||
theme: "light",
|
|
||||||
themes: [],
|
|
||||||
instantPurchaseMax: null,
|
|
||||||
instantPurchaseEnabled: false,
|
|
||||||
instantPurchaseMax: { currency: "LBC", amount: 0.1 },
|
|
||||||
},
|
|
||||||
};
|
};
|
||||||
|
|
||||||
function apiCall(method, params, resolve, reject) {
|
function apiCall(method, params, resolve, reject) {
|
||||||
|
@ -227,17 +200,6 @@ lbry.publishDeprecated = function(
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
||||||
lbry.getClientSetting = function(setting) {
|
|
||||||
var localStorageVal = localStorage.getItem("setting_" + setting);
|
|
||||||
return localStorageVal === null
|
|
||||||
? lbry.defaultClientSettings[setting]
|
|
||||||
: JSON.parse(localStorageVal);
|
|
||||||
};
|
|
||||||
|
|
||||||
lbry.setClientSetting = function(setting, value) {
|
|
||||||
return localStorage.setItem("setting_" + setting, JSON.stringify(value));
|
|
||||||
};
|
|
||||||
|
|
||||||
lbry.imagePath = function(file) {
|
lbry.imagePath = function(file) {
|
||||||
return "img/" + file;
|
return "img/" + file;
|
||||||
};
|
};
|
||||||
|
|
|
@ -14,9 +14,7 @@ let server = null;
|
||||||
let connectTryNum = 0;
|
let connectTryNum = 0;
|
||||||
|
|
||||||
function getServers() {
|
function getServers() {
|
||||||
return lbry.getClientSetting("useCustomLighthouseServers")
|
return defaultServers;
|
||||||
? lbry.getClientSetting("customLighthouseServers")
|
|
||||||
: defaultServers;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
function call(method, params, callback, errorCallback) {
|
function call(method, params, callback, errorCallback) {
|
||||||
|
|
|
@ -11,23 +11,10 @@ class DeveloperPage extends React.PureComponent {
|
||||||
super(props);
|
super(props);
|
||||||
|
|
||||||
this.state = {
|
this.state = {
|
||||||
useCustomLighthouseServers: lbry.getClientSetting(
|
|
||||||
"useCustomLighthouseServers"
|
|
||||||
),
|
|
||||||
customLighthouseServers: lbry
|
|
||||||
.getClientSetting("customLighthouseServers")
|
|
||||||
.join("\n"),
|
|
||||||
upgradePath: "",
|
upgradePath: "",
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
handleUseCustomLighthouseServersChange(event) {
|
|
||||||
lbry.setClientSetting("useCustomLighthouseServers", event.target.checked);
|
|
||||||
this.setState({
|
|
||||||
useCustomLighthouseServers: event.target.checked,
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
handleUpgradeFileChange(event) {
|
handleUpgradeFileChange(event) {
|
||||||
this.setState({
|
this.setState({
|
||||||
upgradePath: event.target.value,
|
upgradePath: event.target.value,
|
||||||
|
@ -60,40 +47,6 @@ class DeveloperPage extends React.PureComponent {
|
||||||
render() {
|
render() {
|
||||||
return (
|
return (
|
||||||
<main>
|
<main>
|
||||||
<section className="card">
|
|
||||||
<h3>{__("Developer Settings")}</h3>
|
|
||||||
<div className="form-row">
|
|
||||||
<label>
|
|
||||||
<FormField
|
|
||||||
type="checkbox"
|
|
||||||
onChange={event => {
|
|
||||||
this.handleUseCustomLighthouseServersChange();
|
|
||||||
}}
|
|
||||||
checked={this.state.useCustomLighthouseServers}
|
|
||||||
/>
|
|
||||||
{" "}
|
|
||||||
{__("Use custom search servers")}
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
{this.state.useCustomLighthouseServers
|
|
||||||
? <div className="form-row">
|
|
||||||
<label>
|
|
||||||
{__("Custom search servers (one per line)")}
|
|
||||||
<div>
|
|
||||||
<FormField
|
|
||||||
type="textarea"
|
|
||||||
className="developer-page__custom-lighthouse-servers"
|
|
||||||
value={this.state.customLighthouseServers}
|
|
||||||
onChange={event => {
|
|
||||||
this.handleCustomLighthouseServersChange();
|
|
||||||
}}
|
|
||||||
checked={this.state.debugMode}
|
|
||||||
/>
|
|
||||||
</div>
|
|
||||||
</label>
|
|
||||||
</div>
|
|
||||||
: null}
|
|
||||||
</section>
|
|
||||||
<section className="card">
|
<section className="card">
|
||||||
<div className="form-row">
|
<div className="form-row">
|
||||||
<FormField
|
<FormField
|
||||||
|
|
|
@ -1,24 +1,35 @@
|
||||||
import * as types from "constants/action_types";
|
import * as types from "constants/action_types";
|
||||||
import * as settings from "constants/settings";
|
import * as settings from "constants/settings";
|
||||||
import LANGUAGES from "constants/languages";
|
import LANGUAGES from "constants/languages";
|
||||||
import lbry from "lbry";
|
|
||||||
|
function getLocalStorageSetting(setting, fallback) {
|
||||||
|
var localStorageVal = localStorage.getItem("setting_" + setting);
|
||||||
|
return localStorageVal === null ? fallback : JSON.parse(localStorageVal);
|
||||||
|
}
|
||||||
|
|
||||||
const reducers = {};
|
const reducers = {};
|
||||||
const defaultState = {
|
const defaultState = {
|
||||||
clientSettings: {
|
clientSettings: {
|
||||||
instantPurchaseEnabled: lbry.getClientSetting(
|
instantPurchaseEnabled: getLocalStorageSetting(
|
||||||
settings.INSTANT_PURCHASE_ENABLED
|
settings.INSTANT_PURCHASE_ENABLED,
|
||||||
|
false
|
||||||
),
|
),
|
||||||
instantPurchaseMax: lbry.getClientSetting(settings.INSTANT_PURCHASE_MAX),
|
instantPurchaseMax: getLocalStorageSetting(settings.INSTANT_PURCHASE_MAX, {
|
||||||
showNsfw: lbry.getClientSetting(settings.SHOW_NSFW),
|
currency: "LBC",
|
||||||
showUnavailable: lbry.getClientSetting(settings.SHOW_UNAVAILABLE),
|
amount: 0.1,
|
||||||
welcome_acknowledged: lbry.getClientSetting(settings.NEW_USER_ACKNOWLEDGED),
|
}),
|
||||||
credit_intro_acknowledged: lbry.getClientSetting(
|
showNsfw: getLocalStorageSetting(settings.SHOW_NSFW, false),
|
||||||
|
showUnavailable: getLocalStorageSetting(settings.SHOW_UNAVAILABLE, true),
|
||||||
|
welcome_acknowledged: getLocalStorageSetting(
|
||||||
|
settings.NEW_USER_ACKNOWLEDGED,
|
||||||
|
false
|
||||||
|
),
|
||||||
|
credit_intro_acknowledged: getLocalStorageSetting(
|
||||||
settings.CREDIT_INTRO_ACKNOWLEDGED
|
settings.CREDIT_INTRO_ACKNOWLEDGED
|
||||||
),
|
),
|
||||||
language: lbry.getClientSetting(settings.LANGUAGE),
|
language: getLocalStorageSetting(settings.LANGUAGE, "en"),
|
||||||
theme: lbry.getClientSetting(settings.THEME),
|
theme: getLocalStorageSetting(settings.THEME, "light"),
|
||||||
themes: lbry.getClientSetting(settings.THEMES),
|
themes: getLocalStorageSetting(settings.THEMES, []),
|
||||||
},
|
},
|
||||||
languages: {},
|
languages: {},
|
||||||
};
|
};
|
||||||
|
@ -35,6 +46,8 @@ reducers[types.CLIENT_SETTING_CHANGED] = function(state, action) {
|
||||||
|
|
||||||
clientSettings[key] = value;
|
clientSettings[key] = value;
|
||||||
|
|
||||||
|
localStorage.setItem("setting_" + key, JSON.stringify(value));
|
||||||
|
|
||||||
return Object.assign({}, state, {
|
return Object.assign({}, state, {
|
||||||
clientSettings,
|
clientSettings,
|
||||||
});
|
});
|
||||||
|
|
Loading…
Add table
Reference in a new issue