From 1ab5ff079c5716677b71302d91f5f025766fb352 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 16 Nov 2017 20:50:29 -0700 Subject: [PATCH 1/4] Set the SdkConfig values immediately after loading the config This is to ensure that when we make a call to get the theme we'll have the SdkConfig available. Signed-off-by: Travis Ralston --- src/vector/index.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/vector/index.js b/src/vector/index.js index 2b27d4e4ca..83e71f6844 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -79,6 +79,7 @@ import Platform from './platform'; import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg'; import SettingsStore, {SettingLevel} from "matrix-react-sdk/lib/settings/SettingsStore"; import Tinter from 'matrix-react-sdk/lib/Tinter'; +import SdkConfig from "matrix-react-sdk/lib/SdkConfig"; var lastLocationHashSet = null; @@ -295,6 +296,7 @@ async function loadApp() { } catch (e) { configError = e; } + SdkConfig.put(configJson); // as quickly as we possibly can, set a default theme... const styleElements = Object.create(null); From 67ca1515d8b08022b1804f6888322ea964f54616 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 16 Nov 2017 20:50:55 -0700 Subject: [PATCH 2/4] Pull the theme through the default chain This is so the `config` level is respected. Signed-off-by: Travis Ralston --- src/vector/index.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/vector/index.js b/src/vector/index.js index 83e71f6844..2517d10ec3 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -301,7 +301,7 @@ async function loadApp() { // as quickly as we possibly can, set a default theme... const styleElements = Object.create(null); let a; - const theme = SettingsStore.getValueAt(SettingLevel.DEFAULT, "theme"); + const theme = SettingsStore.getValue("theme"); for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) { const href = a.getAttribute("href"); if (!href) continue; From eb40de4670ca96eb087744186132d3f90ba58ec4 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Thu, 16 Nov 2017 21:00:30 -0700 Subject: [PATCH 3/4] Make sure we load the config before trying to redirect to a mobile page Signed-off-by: Travis Ralston --- src/vector/index.js | 40 ++++++++++++++++++++-------------------- 1 file changed, 20 insertions(+), 20 deletions(-) diff --git a/src/vector/index.js b/src/vector/index.js index 2517d10ec3..0138e1e734 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -246,8 +246,27 @@ async function loadApp() { // set the platform for react sdk (our Platform object automatically picks the right one) PlatformPeg.set(new Platform()); + // Load the config file. First try to load up a domain-specific config of the + // form "config.$domain.json" and if that fails, fall back to config.json. + let configJson; + let configError; + try { + try { + configJson = await getConfig(`config.${document.domain}.json`); + // 404s succeed with an empty json config, so check that there are keys + if (Object.keys(configJson).length === 0) { + throw new Error(); // throw to enter the catch + } + } catch (e) { + configJson = await getConfig("config.json"); + } + } catch (e) { + configError = e; + } + SdkConfig.put(configJson); + // don't try to redirect to the native apps if we're - // verifying a 3pid + // verifying a 3pid (but after we've loaded the config) const preventRedirect = Boolean(fragparts.params.client_secret); if (!preventRedirect) { @@ -279,25 +298,6 @@ async function loadApp() { } } - // Load the config file. First try to load up a domain-specific config of the - // form "config.$domain.json" and if that fails, fall back to config.json. - let configJson; - let configError; - try { - try { - configJson = await getConfig(`config.${document.domain}.json`); - // 404s succeed with an empty json config, so check that there are keys - if (Object.keys(configJson).length === 0) { - throw new Error(); // throw to enter the catch - } - } catch (e) { - configJson = await getConfig("config.json"); - } - } catch (e) { - configError = e; - } - SdkConfig.put(configJson); - // as quickly as we possibly can, set a default theme... const styleElements = Object.create(null); let a; From c825ab0fa3ddf19a51507387839ed1ac9f6fbe24 Mon Sep 17 00:00:00 2001 From: Travis Ralston Date: Mon, 27 Nov 2017 11:03:58 -0700 Subject: [PATCH 4/4] Add comment about why we call SdkConfig twice Signed-off-by: Travis Ralston --- src/vector/index.js | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/vector/index.js b/src/vector/index.js index 0138e1e734..eaa1f40bae 100644 --- a/src/vector/index.js +++ b/src/vector/index.js @@ -263,6 +263,9 @@ async function loadApp() { } catch (e) { configError = e; } + + // XXX: We call this twice, once here and once in MatrixChat as a prop. We call it here to ensure + // granular settings are loaded correctly and to avoid duplicating the override logic for the theme. SdkConfig.put(configJson); // don't try to redirect to the native apps if we're