SymphonyElectron/src/renderer/preload-component.ts

73 lines
2.3 KiB
TypeScript
Raw Normal View History

2019-01-07 05:53:44 -06:00
import { ipcRenderer } from 'electron';
2018-10-29 13:52:58 -05:00
import * as React from 'react';
import * as ReactDOM from 'react-dom';
2019-01-07 05:53:44 -06:00
import { i18n } from '../common/i18n-preload';
import AboutBox from './components/about-app';
2019-01-07 05:53:44 -06:00
import BasicAuth from './components/basic-auth';
import LoadingScreen from './components/loading-screen';
import MoreInfo from './components/more-info';
import ScreenPicker from './components/screen-picker';
import ScreenSharingIndicator from './components/screen-sharing-indicator';
const enum components {
aboutApp = 'about-app',
loadingScreen = 'loading-screen',
moreInfo = 'more-info',
screenPicker = 'screen-picker',
screenSharingIndicator = 'screen-sharing-indicator',
2019-01-07 05:53:44 -06:00
basicAuth = 'basic-auth',
}
const loadStyle = (style) => {
const styles = document.createElement('link');
styles.rel = 'stylesheet';
styles.type = 'text/css';
styles.href = `./styles/${style}.css`;
document.getElementsByTagName('head')[0].appendChild(styles);
};
2018-10-29 13:52:58 -05:00
/**
* Loads the appropriate component
*/
const load = () => {
2018-10-29 13:52:58 -05:00
const query = new URL(window.location.href).searchParams;
const componentName = query.get('componentName');
2018-10-29 13:52:58 -05:00
let component;
switch (componentName) {
case components.aboutApp:
loadStyle(components.aboutApp);
2018-10-29 13:52:58 -05:00
component = AboutBox;
break;
case components.loadingScreen:
loadStyle(components.loadingScreen);
component = LoadingScreen;
break;
case components.moreInfo:
loadStyle(components.moreInfo);
2018-12-03 11:46:47 -06:00
component = MoreInfo;
break;
case components.screenPicker:
loadStyle(components.screenPicker);
component = ScreenPicker;
break;
case components.screenSharingIndicator:
loadStyle(components.screenSharingIndicator);
component = ScreenSharingIndicator;
break;
2019-01-07 05:53:44 -06:00
case components.basicAuth:
loadStyle(components.basicAuth);
component = BasicAuth;
break;
2018-10-29 13:52:58 -05:00
}
2018-11-15 03:15:37 -06:00
const element = React.createElement(component);
ReactDOM.render(element, document.getElementById('Root'));
};
2019-01-07 05:53:44 -06:00
document.addEventListener('DOMContentLoaded', load);
ipcRenderer.on('set-locale-resource', (_event, data) => {
const { locale, resource } = data;
i18n.setResource(locale, resource);
});