You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

77 lines
2.4 KiB

  1. import React from 'react';
  2. import { Provider } from 'react-redux';
  3. import PropTypes from 'prop-types';
  4. import configureStore from 'flavours/glitch/store/configureStore';
  5. import { showOnboardingOnce } from 'flavours/glitch/actions/onboarding';
  6. import { BrowserRouter, Route } from 'react-router-dom';
  7. import { ScrollContext } from 'react-router-scroll-4';
  8. import UI from 'flavours/glitch/features/ui';
  9. import { fetchCustomEmojis } from 'flavours/glitch/actions/custom_emojis';
  10. import { hydrateStore } from 'flavours/glitch/actions/store';
  11. import { connectUserStream } from 'flavours/glitch/actions/streaming';
  12. import { IntlProvider, addLocaleData } from 'react-intl';
  13. import { getLocale } from 'locales';
  14. import initialState from 'flavours/glitch/util/initial_state';
  15. import ErrorBoundary from 'flavours/glitch/components/error_boundary';
  16. const { localeData, messages } = getLocale();
  17. addLocaleData(localeData);
  18. export const store = configureStore();
  19. const hydrateAction = hydrateStore(initialState);
  20. store.dispatch(hydrateAction);
  21. // load custom emojis
  22. store.dispatch(fetchCustomEmojis());
  23. export default class Mastodon extends React.PureComponent {
  24. static propTypes = {
  25. locale: PropTypes.string.isRequired,
  26. };
  27. componentDidMount() {
  28. this.disconnect = store.dispatch(connectUserStream());
  29. // Desktop notifications
  30. // Ask after 1 minute
  31. if (typeof window.Notification !== 'undefined' && Notification.permission === 'default') {
  32. window.setTimeout(() => Notification.requestPermission(), 60 * 1000);
  33. }
  34. // Protocol handler
  35. // Ask after 5 minutes
  36. if (typeof navigator.registerProtocolHandler !== 'undefined') {
  37. const handlerUrl = window.location.protocol + '//' + window.location.host + '/intent?uri=%s';
  38. window.setTimeout(() => navigator.registerProtocolHandler('web+mastodon', handlerUrl, 'Mastodon'), 5 * 60 * 1000);
  39. }
  40. store.dispatch(showOnboardingOnce());
  41. }
  42. componentWillUnmount () {
  43. if (this.disconnect) {
  44. this.disconnect();
  45. this.disconnect = null;
  46. }
  47. }
  48. render () {
  49. const { locale } = this.props;
  50. return (
  51. <IntlProvider locale={locale} messages={messages}>
  52. <Provider store={store}>
  53. <ErrorBoundary>
  54. <BrowserRouter basename='/web'>
  55. <ScrollContext>
  56. <Route path='/' component={UI} />
  57. </ScrollContext>
  58. </BrowserRouter>
  59. </ErrorBoundary>
  60. </Provider>
  61. </IntlProvider>
  62. );
  63. }
  64. }