2017-06-08_509bba0/509bba0_unpacked/discord_app/index.web.js
2022-07-26 10:06:20 -07:00

112 lines
No EOL
3.6 KiB
JavaScript
Executable file

/* eslint-disable max-len */
import 'babel-polyfill';
import './lib/superagentPatch';
import OverlayBridge from './lib/overlay/OverlayBridge';
import React from 'react';
import ReactDOM from 'react-dom';
import Flux from './lib/flux';
import {App} from './components/App';
import NativeUtils from './utils/NativeUtils';
import RouterUtils from './utils/RouterUtils';
import {contextMenuCallbackNative, contextMenuCallbackWeb} from './utils/ContextMenuUtils';
import HelpdeskUtils from './utils/HelpdeskUtils';
import WindowActionCreators from './actions/WindowActionCreators';
import UserSettingsModalActionCreators from './actions/UserSettingsModalActionCreators';
import './lib/RPCServer';
import './stores/RTCConnectionStore';
import './stores/GuildAFKTimeoutStore';
import './stores/BitRateStore';
import './stores/StreamingStore';
import './stores/FriendSyncStore';
import './stores/PostConnectionCallbackStore';
import './styles/index.styl';
import './styles/themes/dark.styl';
import './images/favicon.ico';
// Used for rich content when displaying in integrated sites/apps (facebook/twitter)
import './images/img_og_discord_home.png';
import {UserSettingsSections} from './Constants';
import './lib/XSSDefenses';
import {AppContainer} from 'react-hot-loader';
import roots from './roots';
Flux.initialize();
const appMount = document.getElementById('app-mount');
const render = App =>
ReactDOM.render(
<AppContainer>
<App />
</AppContainer>,
appMount
);
if (__OVERLAY__) {
OverlayBridge.interceptDispatcher();
render(roots.OverlayApp);
if (module.hot) {
module.hot.accept('./roots', () => {
render(require('./roots').OverlayApp);
});
}
} else {
// Disable scrolling on this page.
document.addEventListener('scroll', e => e.preventDefault());
// Trigger resize event
window.addEventListener('resize', () => WindowActionCreators.resized());
// Trigger focus/blur events.
// TODO: http://www.html5rocks.com/en/tutorials/pagevisibility/intro/
window.addEventListener('focus', () => WindowActionCreators.focus(true));
window.addEventListener('blur', () => WindowActionCreators.focus(false));
if (NativeUtils.embedded) {
window.onbeforeunload = () => NativeUtils.beforeUnload();
// Support for actions triggered by the discord:// protocol.
NativeUtils.on('PATH', path => RouterUtils.replaceWith(path));
NativeUtils.on('USER_SETTINGS_OPEN', () => UserSettingsModalActionCreators.open(UserSettingsSections.ACCOUNT));
NativeUtils.on('HELP_OPEN', () => window.open(HelpdeskUtils.getCommunityURL()));
NativeUtils.on('PURGE_MEMORY', () => NativeUtils.purgeMemory());
NativeUtils.on('MAIN_WINDOW_BLUR', () => {
NativeUtils.setFocused(false);
WindowActionCreators.focus(false);
});
NativeUtils.on('MAIN_WINDOW_FOCUS', () => {
NativeUtils.setFocused(true);
WindowActionCreators.focus(true);
});
// Display a styled Native Context Menu based on current target
window.addEventListener('contextmenu', contextMenuCallbackNative, false);
} else {
// Disable right clicking except where it matters on the webclient
window.addEventListener('contextmenu', contextMenuCallbackWeb, false);
}
if (window.WebSocket == null) {
render(roots.UnsupportedApp);
if (module.hot) {
module.hot.accept('./roots', () => {
render(require('./roots').UnsupportedApp);
});
}
} else {
render(roots.MainApp);
if (module.hot) {
module.hot.accept('./roots', () => {
render(require('./roots').MainApp);
});
}
}
}
// WEBPACK FOOTER //
// ./discord_app/index.web.js