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,6 +102,7 @@ async function start() {
/* webpackPreload: true */ /* webpackPreload: true */
"./init"); "./init");
try {
await settled(rageshakePromise); // give rageshake a chance to load/fail await settled(rageshakePromise); // give rageshake a chance to load/fail
const fragparts = parseQsFromFragment(window.location); const fragparts = parseQsFromFragment(window.location);
@ -129,8 +130,14 @@ async function start() {
// load config requires the platform to be ready // load config requires the platform to be ready
const loadConfigPromise = loadConfig(); const loadConfigPromise = loadConfig();
let configError;
try {
// await config here // await config here
const configError = await loadConfigPromise; await loadConfigPromise;
} catch (err) {
configError = err;
}
// Load language after loading config.json so that settingsDefaults.language can be applied // Load language after loading config.json so that settingsDefaults.language can be applied
const loadLanguagePromise = loadLanguage(); const loadLanguagePromise = loadLanguage();
// as quickly as we possibly can, set a default theme... // as quickly as we possibly can, set a default theme...
@ -147,4 +154,8 @@ async function start() {
// 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();
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 // 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. // 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. // Note: this isn't called twice for some wrappers, like the Jitsi wrapper.
SdkConfig.put(configJson || {}); SdkConfig.put(PlatformPeg.get().getConfig() || {});
}
} }
export function loadOlm(): Promise<void> { export function loadOlm(): Promise<void> {