2022-10-22 14:32:33 +00:00
|
|
|
import React, { Suspense, useState, useEffect } from 'react';
|
2022-10-20 18:06:16 +00:00
|
|
|
import ReactDOM from 'react-dom/client';
|
|
|
|
import Main from './basic/Main';
|
2022-10-22 14:32:33 +00:00
|
|
|
import { CssBaseline } from '@mui/material';
|
|
|
|
import { ThemeProvider, createTheme, Theme } from '@mui/material/styles';
|
2022-10-20 18:06:16 +00:00
|
|
|
import UnsafeAlert from './components/UnsafeAlert';
|
|
|
|
import TorConnection from './components/TorConnection';
|
|
|
|
|
|
|
|
import { I18nextProvider } from 'react-i18next';
|
|
|
|
import i18n from './i18n/Web';
|
|
|
|
|
|
|
|
import { systemClient } from './services/System';
|
2022-10-22 14:32:33 +00:00
|
|
|
import { Settings, defaultSettings } from './models';
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2022-10-22 14:32:33 +00:00
|
|
|
const defaultTheme: Theme = createTheme({
|
2022-10-20 18:06:16 +00:00
|
|
|
palette: {
|
2022-10-22 14:32:33 +00:00
|
|
|
mode: defaultSettings.mode,
|
2022-10-20 18:06:16 +00:00
|
|
|
background: {
|
2022-10-22 14:32:33 +00:00
|
|
|
default: defaultSettings.mode === 'dark' ? '#070707' : '#fff',
|
2022-10-20 18:06:16 +00:00
|
|
|
},
|
|
|
|
},
|
2022-10-22 14:32:33 +00:00
|
|
|
typography: { fontSize: defaultSettings.fontSize },
|
2022-10-20 18:06:16 +00:00
|
|
|
});
|
|
|
|
|
|
|
|
const App = (): JSX.Element => {
|
2022-10-22 14:32:33 +00:00
|
|
|
const [theme, setTheme] = useState<Theme>(defaultTheme);
|
|
|
|
const [settings, setSettings] = useState<Settings>(defaultSettings);
|
2022-10-20 18:06:16 +00:00
|
|
|
|
2022-10-22 14:32:33 +00:00
|
|
|
const updateTheme = function () {
|
|
|
|
setTheme(
|
|
|
|
createTheme({
|
|
|
|
palette: {
|
|
|
|
mode: settings.mode,
|
|
|
|
background: {
|
|
|
|
default: settings.mode === 'dark' ? '#070707' : '#fff',
|
2022-10-20 18:06:16 +00:00
|
|
|
},
|
2022-10-22 14:32:33 +00:00
|
|
|
},
|
|
|
|
typography: { fontSize: settings.fontSize },
|
|
|
|
}),
|
|
|
|
);
|
2022-10-20 18:06:16 +00:00
|
|
|
};
|
|
|
|
|
2022-10-22 14:32:33 +00:00
|
|
|
useEffect(() => {
|
|
|
|
updateTheme();
|
2022-10-30 19:13:01 +00:00
|
|
|
}, [settings.fontSize, settings.mode]);
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
i18n.changeLanguage(settings.language);
|
|
|
|
}, []);
|
2022-10-22 14:32:33 +00:00
|
|
|
|
2022-10-20 18:06:16 +00:00
|
|
|
return (
|
|
|
|
<Suspense fallback='loading language'>
|
|
|
|
<I18nextProvider i18n={i18n}>
|
|
|
|
<ThemeProvider theme={theme}>
|
|
|
|
<CssBaseline />
|
|
|
|
<TorConnection />
|
|
|
|
<UnsafeAlert className='unsafeAlert' />
|
2022-10-22 14:32:33 +00:00
|
|
|
<Main settings={settings} setSettings={setSettings} />
|
2022-10-20 18:06:16 +00:00
|
|
|
</ThemeProvider>
|
|
|
|
</I18nextProvider>
|
|
|
|
</Suspense>
|
|
|
|
);
|
|
|
|
};
|
|
|
|
|
|
|
|
const loadApp = () => {
|
|
|
|
if (systemClient.loading) {
|
|
|
|
setTimeout(loadApp, 200);
|
|
|
|
} else {
|
|
|
|
const root = ReactDOM.createRoot(document.getElementById('app') ?? new HTMLElement());
|
|
|
|
root.render(<App />);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
loadApp();
|