simplify loadConfig

Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
Michael Telatynski 2020-03-25 14:37:28 +00:00
parent 92d8ee355d
commit fd385f8450
2 changed files with 12 additions and 22 deletions

View file

@ -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 = (
<div>
<p>
@ -228,7 +228,7 @@ export async function loadApp() {
<p>
{_t(
"The message from the parser is: %(message)s",
{message: configInfo.configError.err.message || _t("Invalid JSON")},
{message: configError.err.message || _t("Invalid JSON")},
)}
</p>
</div>
@ -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(<div className="error">
Unable to load config file: please refresh the page to try again.
</div>, document.getElementById('matrixchat'));

View file

@ -40,31 +40,21 @@ export function preparePlatform() {
}
}
export async function loadConfig(): Promise<{configError?: Error, configSyntaxError: boolean}> {
export async function loadConfig(): Promise<Error | void> {
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<void> {