finally killed client settings in lbry.js

This commit is contained in:
Jeremy Kauffman 2017-09-22 19:23:51 -04:00
parent 145e4c8b97
commit 767630a985
6 changed files with 29 additions and 104 deletions

View file

@ -3,6 +3,7 @@ import * as settings from "constants/settings";
import lbry from "lbry";
import lbryio from "lbryio";
import lbryuri from "lbryuri";
import { makeSelectClientSetting } from "selectors/settings";
import { selectBalance } from "selectors/wallet";
import {
makeSelectFileInfoForUri,
@ -360,13 +361,13 @@ export function doPurchaseUri(uri) {
if (
cost == 0 ||
!lbry.getClientSetting(settings.INSTANT_PURCHASE_ENABLED)
!makeSelectClientSetting(settings.INSTANT_PURCHASE_ENABLED)(state)
) {
attemptPlay(cost);
} else {
const instantPurchaseMax = lbry.getClientSetting(
const instantPurchaseMax = makeSelectClientSetting(
settings.INSTANT_PURCHASE_MAX
);
)(state);
if (instantPurchaseMax.currency == "LBC") {
attemptPlay(cost, instantPurchaseMax.amount);
} else {

View file

@ -41,8 +41,6 @@ export function doSetDaemonSetting(key, value) {
}
export function doSetClientSetting(key, value) {
lbry.setClientSetting(key, value);
return {
type: types.CLIENT_SETTING_CHANGED,
data: {

View file

@ -1,11 +1,6 @@
import lighthouse from "./lighthouse.js";
import jsonrpc from "./jsonrpc.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) {
const itemRaw = localStorage.getItem(key);
return itemRaw === null ? fallback : JSON.parse(itemRaw);
@ -15,15 +10,6 @@ function setLocal(key, 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 menu = remote.require("./menu/main-menu");
@ -31,19 +17,6 @@ let lbry = {
isConnected: false,
daemonConnectionString: "http://localhost:5279",
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) {
@ -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) {
return "img/" + file;
};

View file

@ -14,9 +14,7 @@ let server = null;
let connectTryNum = 0;
function getServers() {
return lbry.getClientSetting("useCustomLighthouseServers")
? lbry.getClientSetting("customLighthouseServers")
: defaultServers;
return defaultServers;
}
function call(method, params, callback, errorCallback) {

View file

@ -11,23 +11,10 @@ class DeveloperPage extends React.PureComponent {
super(props);
this.state = {
useCustomLighthouseServers: lbry.getClientSetting(
"useCustomLighthouseServers"
),
customLighthouseServers: lbry
.getClientSetting("customLighthouseServers")
.join("\n"),
upgradePath: "",
};
}
handleUseCustomLighthouseServersChange(event) {
lbry.setClientSetting("useCustomLighthouseServers", event.target.checked);
this.setState({
useCustomLighthouseServers: event.target.checked,
});
}
handleUpgradeFileChange(event) {
this.setState({
upgradePath: event.target.value,
@ -60,40 +47,6 @@ class DeveloperPage extends React.PureComponent {
render() {
return (
<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">
<div className="form-row">
<FormField

View file

@ -1,24 +1,35 @@
import * as types from "constants/action_types";
import * as settings from "constants/settings";
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 defaultState = {
clientSettings: {
instantPurchaseEnabled: lbry.getClientSetting(
settings.INSTANT_PURCHASE_ENABLED
instantPurchaseEnabled: getLocalStorageSetting(
settings.INSTANT_PURCHASE_ENABLED,
false
),
instantPurchaseMax: lbry.getClientSetting(settings.INSTANT_PURCHASE_MAX),
showNsfw: lbry.getClientSetting(settings.SHOW_NSFW),
showUnavailable: lbry.getClientSetting(settings.SHOW_UNAVAILABLE),
welcome_acknowledged: lbry.getClientSetting(settings.NEW_USER_ACKNOWLEDGED),
credit_intro_acknowledged: lbry.getClientSetting(
instantPurchaseMax: getLocalStorageSetting(settings.INSTANT_PURCHASE_MAX, {
currency: "LBC",
amount: 0.1,
}),
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
),
language: lbry.getClientSetting(settings.LANGUAGE),
theme: lbry.getClientSetting(settings.THEME),
themes: lbry.getClientSetting(settings.THEMES),
language: getLocalStorageSetting(settings.LANGUAGE, "en"),
theme: getLocalStorageSetting(settings.THEME, "light"),
themes: getLocalStorageSetting(settings.THEMES, []),
},
languages: {},
};
@ -35,6 +46,8 @@ reducers[types.CLIENT_SETTING_CHANGED] = function(state, action) {
clientSettings[key] = value;
localStorage.setItem("setting_" + key, JSON.stringify(value));
return Object.assign({}, state, {
clientSettings,
});