diff --git a/app/src/App.tsx b/app/src/App.tsx index 7205cc8..50feb4c 100644 --- a/app/src/App.tsx +++ b/app/src/App.tsx @@ -12,6 +12,7 @@ import TitleBar from './components/TitleBar' import Tree from './components/Tree/Tree' import UpdateNotifier from './UpdateNotifier' import { connect } from 'react-redux' +import ErrorBoundary from './ErrorBoundary' interface State { selectedNode?: q.TreeNode, @@ -82,25 +83,28 @@ class App extends React.Component { public render() { const { settingsVisible } = this.props const { content, contentShift, centerContent } = this.getStyles() + return (
- -
- -
-
- { - this.setState({ selectedNode: node }) - }} /> + + +
+ +
+
+ { + this.setState({ selectedNode: node }) + }} /> +
+
+ +
-
- -
-
-
- - this.setState({ connectionId })}/> +
+ + this.setState({ connectionId })}/> +
) } diff --git a/app/src/ErrorBoundary.tsx b/app/src/ErrorBoundary.tsx new file mode 100644 index 0000000..8c61357 --- /dev/null +++ b/app/src/ErrorBoundary.tsx @@ -0,0 +1,103 @@ +import * as React from 'react' +import * as q from '../../backend/src/Model' +import { + Button, + Modal, + Paper, + Toolbar, + Typography, +} from '@material-ui/core' + +import Warning from '@material-ui/icons/Warning' +import SentimentDissatisfied from '@material-ui/icons/SentimentDissatisfied' + +import { Theme, withStyles } from '@material-ui/core/styles' + +interface State { + error?: Error +} + +interface Props { + classes: any +} + +class ErrorBoundary extends React.Component { + constructor(props: Props) { + super(props) + this.state = {} + } + + public componentDidCatch(error: Error, errorInfo: any) { + console.log('did catch', error) + } + + public static getDerivedStateFromError(error: Error) { + return { error } + } + + private restart = () => { + window.location = window.location + } + + private clearStorage = () => { + localStorage.clear() + window.location = window.location + } + + public render() { + if (!this.state.error) { + return this.props.children + } + + const { classes } = this.props + return ( + + + + Oooooops! + + I hoped that you would never see this window, but MQTT-Explorer had an unexpected error. + +
+            
+              {this.state.error.stack}
+            
+          
+ + Please report this issue with a short description of what happened to + https://github.com/thomasnordquist/MQTT-Explorer/issues + +
+
+
+
+
+
+ ) + } +} + +const styles = (theme: Theme) => ({ + root: { + minWidth: 550, + maxWidth: 650, + backgroundColor: theme.palette.background.default, + margin: '14vh auto auto auto', + padding: `${2 * theme.spacing.unit}px`, + outline: 'none', + }, + title: { + color: theme.palette.text.primary, + margin: '0', + textAlign: 'center' as 'center', + }, + textColor: { + color: theme.palette.text.primary, + }, + buttonPositioning: { + textAlign: 'center' as 'center', + marginTop: `${theme.spacing.unit * 2}px`, + }, +}) + +export default withStyles(styles)(ErrorBoundary) diff --git a/app/src/tracking.ts b/app/src/tracking.ts index 0f65104..60cb50b 100644 --- a/app/src/tracking.ts +++ b/app/src/tracking.ts @@ -1,3 +1,4 @@ +import { rendererEvents, trackError, trackUserInteraction } from '../../events' let userId = window.localStorage.getItem('userId') const sha1 = require('sha1')