Merge pull request #1795 from MrTimscampi/themes-fix

Fix themes not loading unless signed in
This commit is contained in:
Joshua M. Boniface 2020-08-11 14:45:02 -04:00 committed by GitHub
commit 98d8566aad
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 33 additions and 10 deletions

View File

@ -3,6 +3,10 @@ import skinManager from 'skinManager';
import connectionManager from 'connectionManager';
import events from 'events';
// Set the default theme when loading
skinManager.setTheme(userSettings.theme());
// Set the user's prefered theme when signing in
events.on(connectionManager, 'localusersignedin', function (e, user) {
skinManager.setTheme(userSettings.theme());
});

View File

@ -1,21 +1,40 @@
let data;
function getConfig() {
async function getConfig() {
if (data) return Promise.resolve(data);
return fetch('config.json?nocache=' + new Date().getUTCMilliseconds()).then(response => {
data = response.json();
try {
const response = await fetch('config.json', {
cache: 'no-cache'
});
if (!response.ok) {
throw new Error('network response was not ok');
}
data = await response.json();
return data;
}).catch(error => {
console.warn('web config file is missing so the template will be used');
} catch (error) {
console.warn('failed to fetch the web config file:', error);
return getDefaultConfig();
});
}
}
function getDefaultConfig() {
return fetch('config.template.json').then(function (response) {
data = response.json();
async function getDefaultConfig() {
try {
const response = await fetch('config.template.json', {
cache: 'no-cache'
});
if (!response.ok) {
throw new Error('network response was not ok');
}
data = await response.json();
return data;
});
} catch (error) {
console.error('failed to fetch the default web config file:', error);
}
}
export function getMultiServer() {