logo

mastofe

My custom branche(s) on git.pleroma.social/pleroma/mastofe git clone https://hacktivis.me/git/mastofe.git

mastodon.js (2276B)


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