Make config own function

This commit is contained in:
Marquis Kurt 2019-04-07 18:31:18 -04:00
parent 7621be4198
commit 2397dd6b56
5 changed files with 18 additions and 7 deletions

View File

@ -4,6 +4,7 @@
"logo": "logo.svg",
"background": "background.png"
},
"developer": "true",
"federated": "true",
"registration": {
"defaultInstance": "mastodon.social"

View File

@ -3,14 +3,13 @@ import ReactDOM from 'react-dom';
import App from './App';
import { HashRouter } from 'react-router-dom';
import * as serviceWorker from './serviceWorker';
import {createUserDefaults} from './utilities/settings';
import {createUserDefaults, getConfig} from './utilities/settings';
import {collectEmojisFromServer} from './utilities/emojis';
import {SnackbarProvider} from 'notistack';
import axios from 'axios';
import { userLoggedIn, refreshUserAccountData } from './utilities/accounts';
axios.get('config.json').then((resp: any) => {
document.title = resp.data.branding.name || "Hyperspace";
getConfig().then((config: any) => {
document.title = config.branding.name || "Hyperspace";
}).catch((err: Error) => {
console.error(err);
})

View File

@ -7,6 +7,7 @@ import {Config} from '../types/Config';
import {SaveClientSession} from '../types/SessionData';
import { createHyperspaceApp } from '../utilities/login';
import {parseUrl} from 'query-string';
import { getConfig } from '../utilities/settings';
interface IWelcomeState {
logoUrl?: string;
@ -39,9 +40,7 @@ class WelcomePage extends Component<any, IWelcomeState> {
authority: false
}
axios.get('config.json').then((resp: any) => {
let result: Config = resp.data;
getConfig().then((result: any) => {
this.setState({
logoUrl: result.branding? result.branding.logo: "logo.png",
backgroundUrl: result.branding? result.branding.background: "background.png",

View File

@ -4,6 +4,7 @@ export type Config = {
logo?: string;
background?: string;
};
developer?: string;
federated?: string;
registration?: {
defaultInstance?: string;

View File

@ -1,5 +1,7 @@
import { defaultTheme, themes } from "../types/HyperspaceTheme";
import { getNotificationRequestPermission } from './notifications';
import axios from 'axios';
import { Config } from "../types/Config";
type SettingsTemplate = {
[key:string]: any;
@ -72,4 +74,13 @@ export function createUserDefaults() {
}
})
getNotificationRequestPermission();
}
export function getConfig() {
return axios.get('config.json').then((resp: any) => {
let config: Config = resp.data;
return config;
}).catch((err: Error) => {
console.error("Couldn't configure Hyperspace with the config file. Reason: " + err.name)
})
}