From 7633009ddb1760bdfc6e2a5f00fe602b9a44fbc5 Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 8 Apr 2020 19:35:16 +0100 Subject: [PATCH] clean up loadConfig Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/index.ts | 77 ++++++++++++++++++++++++++------------------- src/vector/init.tsx | 19 +++-------- 2 files changed, 49 insertions(+), 47 deletions(-) diff --git a/src/vector/index.ts b/src/vector/index.ts index 651b0191..bd5de6bf 100644 --- a/src/vector/index.ts +++ b/src/vector/index.ts @@ -102,49 +102,60 @@ async function start() { /* webpackPreload: true */ "./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 - // verifying a 3pid (but after we've loaded the config) - // or if the user is following a deep link - // (https://github.com/vector-im/riot-web/issues/7378) - const preventRedirect = fragparts.params.client_secret || fragparts.location.length > 0; + // don't try to redirect to the native apps if we're + // verifying a 3pid (but after we've loaded the config) + // or if the user is following a deep link + // (https://github.com/vector-im/riot-web/issues/7378) + const preventRedirect = fragparts.params.client_secret || fragparts.location.length > 0; - if (!preventRedirect) { - const isIos = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; - const isAndroid = /Android/.test(navigator.userAgent); - if (isIos || isAndroid) { - if (document.cookie.indexOf("riot_mobile_redirect_to_guide=false") === -1) { - window.location.href = "mobile_guide/"; - return; + if (!preventRedirect) { + const isIos = /iPad|iPhone|iPod/.test(navigator.userAgent) && !window.MSStream; + const isAndroid = /Android/.test(navigator.userAgent); + if (isIos || isAndroid) { + if (document.cookie.indexOf("riot_mobile_redirect_to_guide=false") === -1) { + window.location.href = "mobile_guide/"; + return; + } } } - } - const loadOlmPromise = loadOlm(); - // set the platform for react sdk - preparePlatform(); - // load config requires the platform to be ready - const loadConfigPromise = loadConfig(); + const loadOlmPromise = loadOlm(); + // set the platform for react sdk + preparePlatform(); + // load config requires the platform to be ready + const loadConfigPromise = loadConfig(); - // await config here - const configError = await loadConfigPromise; - // Load language after loading config.json so that settingsDefaults.language can be applied - const loadLanguagePromise = loadLanguage(); - // as quickly as we possibly can, set a default theme... - const loadThemePromise = loadTheme(); - const loadSkinPromise = loadSkin(); + let configError; + try { + // await config here + await loadConfigPromise; + } catch (err) { + configError = err; + } - // await things starting successfully - await loadOlmPromise; - await settled(loadSkinPromise); - await loadThemePromise; - await loadLanguagePromise; + // Load language after loading config.json so that settingsDefaults.language can be applied + const loadLanguagePromise = loadLanguage(); + // as quickly as we possibly can, set a default theme... + const loadThemePromise = loadTheme(); + 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 // run on the components. await loadApp(fragparts.params, acceptBrowser, configError); } -start(); +start().catch(err => { + if (!acceptBrowser) { + alert("Incompatible browser"); + } +}); diff --git a/src/vector/init.tsx b/src/vector/init.tsx index d325dbae..47927762 100644 --- a/src/vector/init.tsx +++ b/src/vector/init.tsx @@ -47,20 +47,11 @@ export function preparePlatform() { } export async function loadConfig(): Promise { - const platform = PlatformPeg.get(); - - let configJson; - try { - configJson = await platform.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 || {}); - } + // 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(PlatformPeg.get().getConfig() || {}); } export function loadOlm(): Promise {