simplify loadConfig
Signed-off-by: Michael Telatynski <7t3chguy@gmail.com>
This commit is contained in:
parent
92d8ee355d
commit
fd385f8450
|
@ -187,7 +187,7 @@ export async function loadApp() {
|
||||||
const platform = PlatformPeg.get();
|
const platform = PlatformPeg.get();
|
||||||
|
|
||||||
// Load the config from the platform
|
// 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
|
// Load language after loading config.json so that settingsDefaults.language can be applied
|
||||||
await loadLanguage();
|
await loadLanguage();
|
||||||
|
@ -216,7 +216,7 @@ export async function loadApp() {
|
||||||
await setTheme();
|
await setTheme();
|
||||||
|
|
||||||
// Now that we've loaded the theme (CSS), display the config syntax error if needed.
|
// 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 = (
|
const errorMessage = (
|
||||||
<div>
|
<div>
|
||||||
<p>
|
<p>
|
||||||
|
@ -228,7 +228,7 @@ export async function loadApp() {
|
||||||
<p>
|
<p>
|
||||||
{_t(
|
{_t(
|
||||||
"The message from the parser is: %(message)s",
|
"The message from the parser is: %(message)s",
|
||||||
{message: configInfo.configError.err.message || _t("Invalid JSON")},
|
{message: configError.err.message || _t("Invalid JSON")},
|
||||||
)}
|
)}
|
||||||
</p>
|
</p>
|
||||||
</div>
|
</div>
|
||||||
|
@ -248,7 +248,7 @@ export async function loadApp() {
|
||||||
|
|
||||||
const urlWithoutQuery = window.location.protocol + '//' + window.location.host + window.location.pathname;
|
const urlWithoutQuery = window.location.protocol + '//' + window.location.host + window.location.pathname;
|
||||||
console.log("Vector starting at " + urlWithoutQuery);
|
console.log("Vector starting at " + urlWithoutQuery);
|
||||||
if (configInfo.configError) {
|
if (configError) {
|
||||||
window.matrixChat = ReactDOM.render(<div className="error">
|
window.matrixChat = ReactDOM.render(<div className="error">
|
||||||
Unable to load config file: please refresh the page to try again.
|
Unable to load config file: please refresh the page to try again.
|
||||||
</div>, document.getElementById('matrixchat'));
|
</div>, document.getElementById('matrixchat'));
|
||||||
|
|
|
@ -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();
|
const platform = PlatformPeg.get();
|
||||||
|
|
||||||
let configJson;
|
let configJson;
|
||||||
let configError;
|
|
||||||
let configSyntaxError = false;
|
|
||||||
try {
|
try {
|
||||||
configJson = await platform.getConfig();
|
configJson = await platform.getConfig();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
configError = e;
|
return e;
|
||||||
|
} finally {
|
||||||
if (e && e.err && e.err instanceof SyntaxError) {
|
// XXX: We call this twice, once here and once in MatrixChat as a prop. We call it here to ensure
|
||||||
console.error("SyntaxError loading config:", e);
|
// granular settings are loaded correctly and to avoid duplicating the override logic for the theme.
|
||||||
configSyntaxError = true;
|
//
|
||||||
configJson = {}; // to prevent errors between here and loading CSS for the error box
|
// 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> {
|
export function loadOlm(): Promise<void> {
|
||||||
|
|
Loading…
Reference in New Issue