Skip to content

Commit a346cf3

Browse files
authored
Merge pull request element-hq#5630 from turt2live/travis/granular-theme
Make sure the SettingsStore is ready to load the theme before loading it
2 parents c28d9e5 + c825ab0 commit a346cf3

File tree

1 file changed

+25
-20
lines changed

1 file changed

+25
-20
lines changed

src/vector/index.js

Lines changed: 25 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ import Platform from './platform';
7979
import MatrixClientPeg from 'matrix-react-sdk/lib/MatrixClientPeg';
8080
import SettingsStore, {SettingLevel} from "matrix-react-sdk/lib/settings/SettingsStore";
8181
import Tinter from 'matrix-react-sdk/lib/Tinter';
82+
import SdkConfig from "matrix-react-sdk/lib/SdkConfig";
8283

8384
var lastLocationHashSet = null;
8485

@@ -245,8 +246,30 @@ async function loadApp() {
245246
// set the platform for react sdk (our Platform object automatically picks the right one)
246247
PlatformPeg.set(new Platform());
247248

249+
// Load the config file. First try to load up a domain-specific config of the
250+
// form "config.$domain.json" and if that fails, fall back to config.json.
251+
let configJson;
252+
let configError;
253+
try {
254+
try {
255+
configJson = await getConfig(`config.${document.domain}.json`);
256+
// 404s succeed with an empty json config, so check that there are keys
257+
if (Object.keys(configJson).length === 0) {
258+
throw new Error(); // throw to enter the catch
259+
}
260+
} catch (e) {
261+
configJson = await getConfig("config.json");
262+
}
263+
} catch (e) {
264+
configError = e;
265+
}
266+
267+
// XXX: We call this twice, once here and once in MatrixChat as a prop. We call it here to ensure
268+
// granular settings are loaded correctly and to avoid duplicating the override logic for the theme.
269+
SdkConfig.put(configJson);
270+
248271
// don't try to redirect to the native apps if we're
249-
// verifying a 3pid
272+
// verifying a 3pid (but after we've loaded the config)
250273
const preventRedirect = Boolean(fragparts.params.client_secret);
251274

252275
if (!preventRedirect) {
@@ -278,28 +301,10 @@ async function loadApp() {
278301
}
279302
}
280303

281-
// Load the config file. First try to load up a domain-specific config of the
282-
// form "config.$domain.json" and if that fails, fall back to config.json.
283-
let configJson;
284-
let configError;
285-
try {
286-
try {
287-
configJson = await getConfig(`config.${document.domain}.json`);
288-
// 404s succeed with an empty json config, so check that there are keys
289-
if (Object.keys(configJson).length === 0) {
290-
throw new Error(); // throw to enter the catch
291-
}
292-
} catch (e) {
293-
configJson = await getConfig("config.json");
294-
}
295-
} catch (e) {
296-
configError = e;
297-
}
298-
299304
// as quickly as we possibly can, set a default theme...
300305
const styleElements = Object.create(null);
301306
let a;
302-
const theme = SettingsStore.getValueAt(SettingLevel.DEFAULT, "theme");
307+
const theme = SettingsStore.getValue("theme");
303308
for (let i = 0; (a = document.getElementsByTagName("link")[i]); i++) {
304309
const href = a.getAttribute("href");
305310
if (!href) continue;

0 commit comments

Comments
 (0)