From fd385f8450485faff820b1c093323dccf1d889af Mon Sep 17 00:00:00 2001 From: Michael Telatynski <7t3chguy@gmail.com> Date: Wed, 25 Mar 2020 14:37:28 +0000 Subject: [PATCH] simplify loadConfig Signed-off-by: Michael Telatynski <7t3chguy@gmail.com> --- src/vector/app.js | 8 ++++---- src/vector/init.ts | 26 ++++++++------------------ 2 files changed, 12 insertions(+), 22 deletions(-) diff --git a/src/vector/app.js b/src/vector/app.js index b7ad872aba..131e1ca41b 100644 --- a/src/vector/app.js +++ b/src/vector/app.js @@ -187,7 +187,7 @@ export async function loadApp() { const platform = PlatformPeg.get(); // Load the config from the platform - const configInfo = await loadConfig(); + const configError = await loadConfig(); // Load language after loading config.json so that settingsDefaults.language can be applied await loadLanguage(); @@ -216,7 +216,7 @@ export async function loadApp() { await setTheme(); // Now that we've loaded the theme (CSS), display the config syntax error if needed. - if (configInfo.configSyntaxError) { + if (configError && configError.err && configError.err instanceof SyntaxError) { const errorMessage = (

@@ -228,7 +228,7 @@ export async function loadApp() {

{_t( "The message from the parser is: %(message)s", - {message: configInfo.configError.err.message || _t("Invalid JSON")}, + {message: configError.err.message || _t("Invalid JSON")}, )}

@@ -248,7 +248,7 @@ export async function loadApp() { const urlWithoutQuery = window.location.protocol + '//' + window.location.host + window.location.pathname; console.log("Vector starting at " + urlWithoutQuery); - if (configInfo.configError) { + if (configError) { window.matrixChat = ReactDOM.render(
Unable to load config file: please refresh the page to try again.
, document.getElementById('matrixchat')); diff --git a/src/vector/init.ts b/src/vector/init.ts index 04db8801c6..96745f53cc 100644 --- a/src/vector/init.ts +++ b/src/vector/init.ts @@ -40,31 +40,21 @@ export function preparePlatform() { } } -export async function loadConfig(): Promise<{configError?: Error, configSyntaxError: boolean}> { +export async function loadConfig(): Promise { const platform = PlatformPeg.get(); let configJson; - let configError; - let configSyntaxError = false; try { configJson = await platform.getConfig(); } catch (e) { - configError = e; - - if (e && e.err && e.err instanceof SyntaxError) { - console.error("SyntaxError loading config:", e); - configSyntaxError = true; - configJson = {}; // to prevent errors between here and loading CSS for the error box - } + 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(configJson); - - return {configError, configSyntaxError}; } export function loadOlm(): Promise {