Skip to content

Commit

Permalink
Merge pull request #5630 from turt2live/travis/granular-theme
Browse files Browse the repository at this point in the history
Make sure the SettingsStore is ready to load the theme before loading it
  • Loading branch information
dbkr authored Nov 27, 2017
2 parents c28d9e5 + c825ab0 commit a346cf3
Showing 1 changed file with 25 additions and 20 deletions.
45 changes: 25 additions & 20 deletions src/vector/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -245,8 +246,30 @@ 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;
}

// 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
// verifying a 3pid
// verifying a 3pid (but after we've loaded the config)
const preventRedirect = Boolean(fragparts.params.client_secret);

if (!preventRedirect) {
Expand Down Expand Up @@ -278,28 +301,10 @@ 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;
}

// 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;
Expand Down

0 comments on commit a346cf3

Please sign in to comment.