clean up loadConfig

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-04-08 19:35:16 +01:00
parent e267086a17
commit 7633009ddb
2 changed files with 49 additions and 47 deletions

View File

@ -102,49 +102,60 @@ async function start() {
/* webpackPreload: true */ /* webpackPreload: true */
"./init"); "./init");
await settled(rageshakePromise); // give rageshake a chance to load/fail try {
await settled(rageshakePromise); // give rageshake a chance to load/fail
const fragparts = parseQsFromFragment(window.location); const fragparts = parseQsFromFragment(window.location);
// don't try to redirect to the native apps if we're // don't try to redirect to the native apps if we're
// verifying a 3pid (but after we've loaded the config) // verifying a 3pid (but after we've loaded the config)
// or if the user is following a deep link // or if the user is following a deep link
// (https://github.com/vector-im/riot-web/issues/7378) // (https://github.com/vector-im/riot-web/issues/7378)
const preventRedirect = fragparts.params.client_secret || fragparts.location.length > 0; const preventRedirect = fragparts.params.client_secret || fragparts.location.length > 0;
if (!preventRedirect) { if (!preventRedirect) {
const isIos = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; const isIos = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream;
const isAndroid = /Android/.test(navigator.userAgent); const isAndroid = /Android/.test(navigator.userAgent);
if (isIos || isAndroid) { if (isIos || isAndroid) {
if (document.cookie.indexOf("riot_mobile_redirect_to_guide=false") === -1) { if (document.cookie.indexOf("riot_mobile_redirect_to_guide=false") === -1) {
window.location.href = "mobile_guide/"; window.location.href = "mobile_guide/";
return; return;
}
} }
} }
}
const loadOlmPromise = loadOlm(); const loadOlmPromise = loadOlm();
// set the platform for react sdk // set the platform for react sdk
preparePlatform(); preparePlatform();
// load config requires the platform to be ready // load config requires the platform to be ready
const loadConfigPromise = loadConfig(); const loadConfigPromise = loadConfig();
// await config here let configError;
const configError = await loadConfigPromise; try {
// Load language after loading config.json so that settingsDefaults.language can be applied // await config here
const loadLanguagePromise = loadLanguage(); await loadConfigPromise;
// as quickly as we possibly can, set a default theme... } catch (err) {
const loadThemePromise = loadTheme(); configError = err;
const loadSkinPromise = loadSkin(); }
// await things starting successfully // Load language after loading config.json so that settingsDefaults.language can be applied
await loadOlmPromise; const loadLanguagePromise = loadLanguage();
await settled(loadSkinPromise); // as quickly as we possibly can, set a default theme...
await loadThemePromise; const loadThemePromise = loadTheme();
await loadLanguagePromise; const loadSkinPromise = loadSkin();
// await things starting successfully
await loadOlmPromise;
await settled(loadSkinPromise);
await loadThemePromise;
await loadLanguagePromise;
// Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to // Finally, load the app. All of the other react-sdk imports are in this file which causes the skinner to
// run on the components. // run on the components.
await loadApp(fragparts.params, acceptBrowser, configError); await loadApp(fragparts.params, acceptBrowser, configError);
} }
start(); start().catch(err => {
if (!acceptBrowser) {
alert("Incompatible browser");
}
});

View File

@ -47,20 +47,11 @@ export function preparePlatform() {
} }
export async function loadConfig(): Promise<Error | void> { export async function loadConfig(): Promise<Error | void> {
const platform = PlatformPeg.get(); // 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.
let configJson; //
try { // Note: this isn't called twice for some wrappers, like the Jitsi wrapper.
configJson = await platform.getConfig(); SdkConfig.put(PlatformPeg.get().getConfig() || {});
} catch (e) {
return e;
} finally {
// 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.
//
// Note: this isn't called twice for some wrappers, like the Jitsi wrapper.
SdkConfig.put(configJson || {});
}
} }
export function loadOlm(): Promise<void> { export function loadOlm(): Promise<void> {