From ab56633eed2b74d4441a2d381815893e07189774 Mon Sep 17 00:00:00 2001 From: jessop Date: Fri, 31 Jul 2020 14:24:01 -0400 Subject: [PATCH] prevent specific settings sync in config --- .env.defaults | 5 +++++ config.js | 1 + ui/redux/reducers/settings.js | 24 +++++++++++++++--------- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/.env.defaults b/.env.defaults index c4e523924..71004f69e 100644 --- a/.env.defaults +++ b/.env.defaults @@ -29,6 +29,11 @@ SITE_CANONICAL_URL=https://lbry.tv # LOCALE DEFAULT_LANGUAGE=en +# Custom Settings +# Additional settings for below are found in ui/constants/settings and are for +# preventing user settings from applying to custom sites without overwriting them. +# UNSYNCED_SETTINGS='theme dark_mode_times automatic_dark_mode_enabled' + # Custom Content # If the following is true, copy custom/homepage.example.js to custom/homepage.js and modify CUSTOM_HOMEPAGE=false diff --git a/config.js b/config.js index 1a0e81a0f..517b7af08 100644 --- a/config.js +++ b/config.js @@ -22,6 +22,7 @@ const config = { SITE_CANONICAL_URL: process.env.SITE_CANONICAL_URL, DEFAULT_LANGUAGE: process.env.DEFAULT_LANGUAGE, AUTO_FOLLOW_CHANNELS: process.env.AUTO_FOLLOW_CHANNELS, + UNSYNCED_SETTINGS: process.env.UNSYNCED_SETTINGS, SIMPLE_SITE: process.env.SIMPLE_SITE === 'true', SHOW_ADS: process.env.SHOW_ADS === 'true', PINNED_URI_1: process.env.PINNED_URI_1, diff --git a/ui/redux/reducers/settings.js b/ui/redux/reducers/settings.js index 14978514f..c9754e193 100644 --- a/ui/redux/reducers/settings.js +++ b/ui/redux/reducers/settings.js @@ -3,7 +3,12 @@ import moment from 'moment'; import SUPPORTED_LANGUAGES from 'constants/supported_languages'; import { ACTIONS as LBRY_REDUX_ACTIONS, SETTINGS, SHARED_PREFERENCES } from 'lbry-redux'; import { getSubsetFromKeysArray } from 'util/sync-settings'; +import { UNSYNCED_SETTINGS } from 'config'; const { CLIENT_SYNC_KEYS } = SHARED_PREFERENCES; +const settingsToIgnore = (UNSYNCED_SETTINGS && UNSYNCED_SETTINGS.trim().split(' ')) || []; +const clientSyncKeys = settingsToIgnore.length + ? CLIENT_SYNC_KEYS.filter(k => !settingsToIgnore.includes(k)) + : CLIENT_SYNC_KEYS; const reducers = {}; let settingLanguage = []; @@ -72,14 +77,6 @@ reducers[ACTIONS.REHYDRATE] = (state, action) => { return Object.assign({}, state, { clientSettings }); }; -reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = state => { - const { clientSettings } = state; - const sharedPreferences = Object.assign({}, state.sharedPreferences); - const selectedClientSettings = getSubsetFromKeysArray(clientSettings, CLIENT_SYNC_KEYS); - const newSharedPreferences = { ...sharedPreferences, ...selectedClientSettings }; - return Object.assign({}, state, { sharedPreferences: newSharedPreferences }); -}; - reducers[ACTIONS.FINDING_FFMPEG_STARTED] = state => Object.assign({}, state, { findingFFmpeg: true, @@ -157,11 +154,20 @@ reducers[ACTIONS.CLIENT_SETTING_CHANGED] = (state, action) => { }); }; +reducers[ACTIONS.SYNC_CLIENT_SETTINGS] = state => { + const { clientSettings } = state; + const sharedPreferences = Object.assign({}, state.sharedPreferences); + const selectedClientSettings = getSubsetFromKeysArray(clientSettings, clientSyncKeys); + const newSharedPreferences = { ...sharedPreferences, ...selectedClientSettings }; + return Object.assign({}, state, { sharedPreferences: newSharedPreferences }); +}; + reducers[LBRY_REDUX_ACTIONS.USER_STATE_POPULATE] = (state, action) => { const { clientSettings: currentClientSettings } = state; const { settings: sharedPreferences } = action.data; + if (currentClientSettings[SETTINGS.ENABLE_SYNC]) { - const selectedSettings = getSubsetFromKeysArray(sharedPreferences, CLIENT_SYNC_KEYS); + const selectedSettings = getSubsetFromKeysArray(sharedPreferences, clientSyncKeys); const mergedClientSettings = { ...currentClientSettings, ...selectedSettings }; return Object.assign({}, state, { sharedPreferences, clientSettings: mergedClientSettings }); }